Navigation: Realtest Script Language > Syntax Element Details >

ExitRule

 

 

 

 

Category

Strategy Elements

Description

Specifies one or more conditions that would trigger a position exit

Input

Any formula specifying a true/false condition (non-zero means true)

Notes

The ExitRule for a strategy is evaluated for every position every day. If it ever returns true (non-zero), the position is exited either that day at the close or the next day at the open, depending on the ExitTime setting.

When exit time is NextOpen (the default) or NextClose, ExitRule is evaluated using the day prior to exit day as the most recent bar in the formula. For ThisClose exits, the exit day is the most recent bar.

This formula is typically used to specify a conditional exits such as C > C[1], or time-based exits such as BarsHeld=10.

A strategy can include any combination of an ExitRule, ExitLimit (target) and/or ExitStop (stop-loss). Whichever one is determined to have occurred first will be the one used in the test. The type of exit that occurred for each trade is displayed in the Reason column of the Trade List.

Optionally, for ExitRule formulas with multiple "or" conditions, the formula can return a string which both serves as the "true" signal of the condition and provides the Reason name for the exit in the trade list.

This example shows how to structure a multi-reason ExitRule formula using the Select function, and how each reason string is shown in the Trades Window:

Note that when used this way, the Select statement must be the entire ExitRule formula.

For example, to only check a pair of exit rules only at the end of each month, you must use this:

          Select(EndOfMonth and condition1, "reason1", EndOMonth and condition2, "reason2")

rather than this:

          ExitRule: EndOfMonth and Select(condition1, "reason1", condition2, "reason2")

For more information on how the backtest engine works, see Backtest Engine Details.

 

 

 

Copyright © 2020-2022 Systematic Solutions, LLC