I’ve coded a section preventing my system from opening a new position in the same direction as the old position just after a close of the old position. (I use a time exit so the entry signal can still be valid at close). It works on the backtest but I just wanted to double check if this is correct or if there is another way to do the same thing?
if barindex > (longbarexit + stayawaytimeL) then
longstayaway = 0
endif
if barindex > (shortbarexit + stayawaytimeS) then
shortstayaway = 0
endif
//////////////////////////////////////////////////////////////////
//// Conditions to exit long positions
//////////////////////////////////////////////////////////////////
le1 = barindex = tradeindex + Ltradetime
if longonmarket and le1 then
sell at market
longbarexit = barindex
longstayaway = 1
endif
//////////////////////////////////////////////////////////////////
//// Conditions to exit lshort positions
//////////////////////////////////////////////////////////////////
se1 = barindex = tradeindex + Stradetime
if shortonmarket and se1 then
exitshort at market
shortbarexit = barindex
shortstayaway = 1
endif
thanks for sharing the code. what about testing this on the demo account?
I have tested it on the demo and it works 🙂 I just wanted to see if there was somebody who had different way to accomplish the same thing.