Navigation: Backtest Engine Details >

Referring to Past Trades in Strategy Formulas

 

 

 

 

The RealTest Formula Syntax includes a set of elements which can be used to refer to Trade Record Values.

The main purpose of these elements is to facilitate customization of the Trades Window columns by editing the standard Trades.rts script or providing an alternative Trades Section in a different script.

The trade record syntax can also be used in any Strategy Element formula to access certain details of trades which have occurred earlier in the current backtest. This allows you to model strategies which incorporate the concept of looking at past trades in a specific symbol to inform decisions about the next trade.

When used in this way, the context of the trade reference is always the current bar of the current symbol in the current strategy. To refer to trades that closed previously, Multi-Bar Functions and/or Bar Offsets must be used.

If a strategy specifies MaxSameSym > 1 to allow multiple positions in the same stock then T.Points, T.Profit, T.QtyIn and T.QtyOut return the sum for all trades with the same exit date (and symbol and strategy).

The following are a few examples of ways in which you might want to explore using this capability:

Example

Description

CountTrue(T.DateOut > 0, 10) > 0

a prior trade in this symbol was exited within the past 10 bars

Sum(T.Profit, 20) < -0.01 * S.Equity

recent trades in this symbol have lost more than 1% of equity

T.Reason = 2

a prior trade in this symbol just hit its target earlier today

Extern(@tracking, Avg(T.Profit > 0, Barnum) < 0.5)

a tracking strategy that takes all signals shows < 50% past win rate for this symbol

For the above examples, the EntrySkip formula would be a good place to test these conditions.

 

 

 

 

Copyright © 2020-2024 Systematic Solutions, LLC