Navigation: Backtest Engine Details >

The Current Bar in Formula Evaluation

 

 

 

 

When writing a formula that refers to bar data elements such as "High" or "Close", it is important understand what "the current bar" is.

In Data and Scan formulas, the current bar is simply the date for which the formula is being evaluated.

In Strategy Element formulas, the current bar is the most recently completed bar relative to the logical time at which the formula is evaluated.

The best way to understand this is to imagine that you're manually trading your strategy by calculating all of your formulas after the close each day. Say today is a Monday. Even though you are preparing to enter or exit positions in Tuesday's market, the "current bar" is still Monday's bar. This fact makes it impossible to accidentally "look ahead" in a backtest to data that you could not yet see in real trading.

An exception to this rule occurs when a strategy uses EntryTime: ThisClose (with no entry limit or stop) or ExitTime: ThisClose. In these scenarios, RealTest lets you to assume that, by using realtime quotes, you would be able to evaluate your formulas in your live trading platform within a minute or two of the close. In this case and only this case, the current bar is the entry day or exit day bar.

Here is a table of all possible ENTRY scenarios:

EntryTime

EntrySetup Current Bar

ThisClose

entry bar

NextOpen (market default)

bar before entry bar

Intraday (limit/stop default)

bar before entry bar

NextClose

bar before entry bar

All other entry-related formulas use the same current bar as EntrySetup does.

Here is a table of all possible EXIT RULE scenarios:

ExitTime

ExitRule Current Bar

ThisClose

exit bar

NextOpen (default)

bar before exit bar

NextClose

bar before exit bar

Here is a table of all possible EXIT LIMIT and EXIT STOP scenarios:

ExitLimitTime or ExitStopTime

Formula Current Bar

ThisClose

exit bar

NextOpen

bar before exit bar

Intraday (default)

bar before exit bar

NextClose

bar before exit bar

Please take careful note of the following asymmetry between Entry and Exit logic:

the Current Bar for each entry-related formula calculation is determined by EntryTime 

the Current Bar for each exit-related formula calculation has its own time specification (ExitTime, ExitLimitTime and ExitStopTime)

The reason for this asymmetry is that there is effectively only one entry order placed for each EntrySetup, whereas there can be up to three exit orders placed (with an implied bracket), depending on the presence or absence of each of the three exit-related formulas.

If you intend to use a Time Stop in any of your strategies, and/or if you plan to refer to BarsHeld in any of your exit formulas, please also read these topics with all of the above in mind.

 

 

 

 

Copyright © 2020-2022 Systematic Solutions, LLC