My strategy is:
-buy on Friday's one tick above highest high of last ten days, if the 10 day simple moving average is above the 40 day simple moving average.
-if I get filled, I exit my position on Monday;
I want to make only one entry. I made two filters to prevent additional entries:
-X variable which prevents from extra orders( enter only if X == false);
-EntriesPerDirection=1,(EntryHandling=EntryHandling .AllEntries);
but I still get two entries;
Bellow i Attach a code:
protected override void OnBarUpdate()
{
if(Time[0].DayOfWeek==DayOfWeek.Friday && Time[0].Hour>=OpeningOrderHour && X==false)
{
if (SMA(BarsArray[1],SMA1Period)[0] > SMA(BarsArray[1],SMA2Period)[0])
{
Max=MAX(Highs[1],highestHighPeriod)[0];
BuyPrice=Max + TickSize;
if(Open[0]>BuyPrice)
{
pozycja=EnterLong();
Print("Before " + Time[0].ToString() + " " + X.ToString());
SetStopLoss(CalculationMode.Ticks, 100);
X=true;
Print("After " + Time[0].ToString() + " " + X.ToString());
}
}
}
if(Time[0].DayOfWeek!=DayOfWeek.Friday && Time[0].DayOfWeek!=DayOfWeek.Saturday && Time[0].DayOfWeek!=DayOfWeek.Sunday && Time[0].Hour>=closingTradeHour)
{
ExitLong();
}
}
protected override void OnPositionUpdate(IPosition pozycja)
{
if(pozycja.MarketPosition==MarketPosition.Long)
X=true;
if(pozycja.MarketPosition==MarketPosition.Flat)
X=false;
}
I tried Print() method to see what is going on before making entry and right after entry and I still can't figure it out. It's seems like X variable is changing itself from true to false. Example :
Friday at 7:02 X == false(condition to make entry) then strategy is making entry and changing X to true. X is supposed to be true until Monday morning.
Friday at 7:09 is making another entry and X is false again(don't know why it changed to false and don't know why strategy is ignoring EntriesPerDirection=1).
I am attaching results screen shot, with two entries.
I don't know what to do, please help.

Comment