Navigation: Backtest Engine Details >

The Current Bar in Formula Evaluation

 

 

 

When writing a formula that refers to bar data elements such as "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.

The one exception to this rule is a strategy that uses EntryTime: AtClose, or ExitTime: AtClose. In these scenarios, RealTest lets you to assume that, by using realtime quotes, you will 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

EntryStop or EntryLimit

EntrySetup Current Bar

AtClose

no

entry bar

AtOpen

no

bar before entry bar

n/a

yes

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 scenarios:

ExitTime

ExitRule Current Bar

ExitLimit/ExitStop Current Bar

AtClose

exit bar

bar before exit bar

AtOpen

bar before exit bar

bar before exit bar

These two tables highlight an important asymmetry in entry vs. exit logic in RealTest:

all of the entry formulas work together to specify a single entry tactic, and are always evaluated using a common current bar

ExitRule, ExitLimit and ExitStop are three separate possible exit tactics and are not necessarily evaluated using the same current bar

Consider a strategy which includes the following exit specification:

This instructs RealTest to model the following daily scenario for each open position in this strategy:

place a stop order at a price that is 5% below yesterday's close

if the stop wasn't hit and today's close ends up above yesterday's close then exit at (just before) the close today

This seems intuitive, but notice that "C" in the stop formula refers to yesterday's close while "C" in the rule formula refers to today's close.

If the exit time was AtOpen (or not specified since this is the default) then both "C" instances would refer to yesterday's close and there would be no confusion.

The potential confusion that this topic is meant to circumvent exists only because RealTest optionally supports entering or exiting positions just before the close in its backtest models.

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 the above in mind.

 

 

 

 

Copyright © 2020-2021 Systematic Solutions, LLC