I would like to test a number of pattern trading systems. I am not sure how to handle in system tester an exit based on both:
1. a stop loss at the low of the setup bar (or lowest low in setup, as in the example below) and
2. a time in position limit (5 bars in the example).
As an example, take the following entry long condition (I have used the Ref() function for the timing stop rather than the BarsSince() or Simulation.CurrentPositionAge functions which I understand are equivalent):
BUY ORDER:
setup:=C>O AND L>Ref(L,-2) AND Ref(L,-1)<Ref(L,-2) AND Ref(L,-2)<Ref(L,-3)
AND H>Ref(H,-1);
Ref(setup,-1) and H>Ref(H,-1)
order type:
Stop:
Max(O,Ref(H,-1))
SELL ORDER:
setup:=C>O AND L>Ref(L,-2) AND Ref(L,-1)<Ref(L,-2) AND Ref(L,-2)<Ref(L,-3)
AND H>Ref(H,-1);
L<ValueWhen(1,setup,Ref(L,-1)) or Ref(setup,-5)
order type:
Stop:
setup:=C>O AND L>Ref(L,-2) AND Ref(L,-1)<Ref(L,-2) AND Ref(L,-2)<Ref(L,-3)
AND H>Ref(H,-1);
If(L<ValueWhen(1,setup,Ref(L,-1)),Min(O,ValueWhen(1,setup,Ref(L,-1)),
Ref(setup,-5),Open,0))
The doubt is about the Stop order code which incorporates both the stop loss level and the time exit (exit at the open as assumed here).
Is this the correct way to handle this type of exit conditions in System Tester?
Thanks for your opinion and regards.
Maurizio