Hi All,
Appreciate your help here, I am baffled with this one instance that one of the strategy I was testing seems to skip the exit. It appears the backtester is not recognising that bar. In my debugger, I am able to see the Entry and Exits accurately.
Code for the strategy is below
cond1 = DayOfWeek()==1;
Cond2 = C<Ref(C,-1);
Cond3 = Ref(C,-1)<Ref(C,-2);
SetTradeDelays (0,0,0,0);
SetOption("Allowsamebarexit",True);
Buy = cond1 AND cond2 AND cond3;
BuyPrice = SellPrice = C;
Sell = BarsSince(Buy)==5 ;
SellPrice = C;
Short = 0;
Cover = 0;
//Debugger
Plot(Buy,"Buy",colorBlack,styleHistogram|styleThick);
Plot(-Sell,"Sell",colorRed,styleHistogram|styleThick);
The strategy is simple, it enters on Monday close (if the condition satisfied) and holds the position for 5 bars which in most case also result on a Monday. i.e., in some case the position may have to enter on the same day as the exit.
The issue I am facing is that some exits/entries are skipped.
As you can see in the screenshot there are trades which stayed open for 11 days. I have tried to resolve it through N-Bar stop as well and I have exact same result. So I am not certain why it is happening.
It could be very obvious which my eyes are not catching at the moment, but I have tried hours trying to resolve this and gone through the forum reading about same bar exits and Exrems but none of them seems to be relevant to my issue.
Appreciate your guidance.