this is the body of my strategy, does somebody know what I am doing wrong? why did It take a position twice?
#region Variables
private int tradeok = 1;
private double RngFrac = 0.35;
#endregion
protected override void Initialize()
{
CalculateOnBarClose = true;
EntryHandling = EntryHandling.UniqueEntries;
ExitOnClose = false;
}
protected override void OnBarUpdate()
{
//Enter long
if (CrossAbove(...)
&& tradeok == 1)
{
EnterLongLimit(Close[0] - RngFrac * (High[0] - Low[0]));
}
//Enter short
if (CrossBelow(...)
&& tradeok == 1)
{
EnterShortLimit(Close[0] + RngFrac * (High[0] - Low[0]));
}
// Exit short
if (Position.MarketPosition == MarketPosition.Short
&& CrossAbove(...)
&& tradeok == 1)
{
ExitShort();
}
//Exit long
if (Position.MarketPosition == MarketPosition.Long
&& CrossBelow(...)
&& tradeok == 1)
{
ExitLong();
}
if (Position.MarketPosition == MarketPosition.Long
&& Time[0].DayOfWeek == DayOfWeek.Friday
&& ToTime(Time[0]) > ToTime(17, 59, 0))
{
ExitLong();
}
if (Position.MarketPosition == MarketPosition.Short
&& Time[0].DayOfWeek == DayOfWeek.Friday
&& ToTime(Time[0]) > ToTime(17, 59, 0))
{
ExitShort();
}
if (Time[0].DayOfWeek == DayOfWeek.Sunday)
{
tradeok = 0;
}
if (Time[0].DayOfWeek == DayOfWeek.Monday
&& ToTime(Time[0]) < ToTime(6, 0, 0))
{
tradeok = 0;
}
if (Time[0].DayOfWeek == DayOfWeek.Friday
&& ToTime(Time[0]) >= ToTime(15, 59, 0))
{
tradeok = 0;
}
else
{
tradeok = 1;
}
}
//Enter long
if (CrossAbove(...)
&& tradeok == 1)
{
EnterLong();
}
//Enter long
if (CrossAbove(...)
&& tradeok == 1)
{
EnterLongLimit(Close[0] - RngFrac * (High[0] - Low[0]));
}

. The problem I have is that every time the fast SMA crosses above the slow SMA, immediately at the next 60 min bar the strategy exits the short position via market order, and simultaneously it leaves the EnterLongLimit. What I noticed is that the strategy actually leaves 2 EnterLongLimit (one to flatten the position, one to go long) not recognizing that I am already flat.
Often writing a spec looks like overkill, until what at first looked simple, simply seems to not work. If you will first completely describe, in verbose language or pseudocode, that which you want to code, it might be much faster to reach your goal.
Heck, even the title of my thread is that same question!
Comment