Navigation: Backtest Engine Details >

Specifying a Time Stop

 

 

 

The way to specify a Time Stop in RealTest is to reference the BarsHeld element in the ExitRule formula.

For example, a simple five-day time-stop rule would be:

The evaluation of BarsHeld is an exception to the logic described in the topic The Current Bar In Formula Evaluation.

When used in any exit-related formula, BarsHeld will always return the number of bars (nights) across which the position will have been held if the formula triggers an exit.

For example, say you entered a position on a Monday and want to exit on (a) the first "up" day, or (b) the 3rd day after entry day, whichever comes first.

This would be your exit rule:

If Tuesday's close is higher than Monday's close, and your ExitTime is AtOpen (the default), then you will exit the position Wednesday at the open. If, in the same situation, your ExitTime is AtClose, then you will exit exit the position Tuesday at the close. In both cases, Tuesday's bar is used to evaluate the "C > C[1]" clause, because it is the most recently completed bar.

Now let's assume that it was a terrible (long) entry and price closes lower every day that week, so that the time stop clause is invoked. If your ExitTime is AtOpen (the default), then you will exit the position Thursday at the open. Even though Wednesday's bar is used to evaluate the ExitRule formula, BarsHeld is evaluated as if it is Thursday, because of the default ExitTime of AtOpen.

However, if your ExitTime is AtClose, you will not exit until Thursday at the close. In this case, Thursday's bar is used to evaluate your ExitRule, and no exception is made for BarsHeld.

Assuming that you entered a position on a Monday, the following table shows all the possibilities for the next 3 days:

ExitRule

ExitTime

Date/Time of Exit

Trade List Bars Value

BarsHeld=0

AtOpen

never*

n/a

BarsHeld=0

AtClose

Monday at close

0

BarsHeld=1

AtOpen

Tuesday at open

1

BarsHeld=1

AtClose

Tuesday at close

1

BarsHeld=2

AtOpen

Wednesday at open

2

BarsHeld=2

AtClose

Wednesday at close

2

BarsHeld=3

AtOpen

Thursday at open

3

BarsHeld=3

AtClose

Thursday at close

3

* when ExitTime is AtOpen, BarsHeld will never return 0 in an ExitRule formula, so ExitRule: BarsHeld=0 will never cause an exit

 

 

 

Copyright © 2020-2021 Systematic Solutions, LLC