The following material is kept here for reference and/or curiosity, but it is no longer necessary to understand and follow these guidelines.
Functions and indicators that can support onepass calculation are now automatically calculated this way even when they're embedded within a larger formula expression.
A regular Data Section item formula is calculated by looping through all the dates of the symbol and evaluating the formula for each date. If the formula includes an indicator or rolling bar function with a long lookback length, this can take some time to accomplish, since it has to "roll back" that many bars from each bar of each symbol.
For most types of formulas, this can't be avoided, and fortunately RealTest already performs these calculations as quickly as possible, using multiple threads.
For certain commonlyused functions and indicators, it is possible to dramatically speed up their calculation if they are structured and declared a certain way.
The difference in speed between the standard calculation method and "onepass" is roughly a factor of one third of the lookback length. For example, a 100day moving average can be calculated approximately 33 times faster when the onepass optimization can be applied.
When you think about a backtest universe with 10,000 stocks going back 20 years (5000 daily bars per stock), you can start to imagine how much faster longlookback indicators can be calculated if you structure your scripts to take advantage of onepass mode.
All of the functions and indicators listed below will be automatically calculated in one pass if and only if the following conditions are all true:
•the indicator is the only element of the data item formula (not part of a larger expression)
•the length argument is a constant (literal number) or a parameter reference
For example, below are two ways to calculate simple uptrend / downtrend variables:
In the first Data section above, RealTest can not use onepass calculation for either formula, because they each contain two functions and an operator.
In the second Data section, the moving averages are each given their own data items, which allows them to be calculated using onepass.
Note the comments that compare the calculation speed (your results may vary depending on your hardware).
The following functions and indicators support onepass calculation if they are specified as described above:
•ADX
•MDI
•PDI
•ATR
•RSI
•RSIF
•RRSI
•KBBOT
•KBTOP
•MACD
•MACDS
•MACDH
•SUM
•AVG / MA
•XAVG / EMA
•Highest / HHV
•Lowest / LLV
•SinceHigh
•SinceLow
It is worth your while to carefully structure your Data Section so that longlookback indicators can take advantage of onepass calculation!
To do this most effectively, look through all of your data and strategy formulas to find any of the above indicators, give each unique one its own data item, and change all the places where it is used to references to that data item.
The bensdorp_book.rts example script gives an excellent illustration of this technique. Imagine (or test, if you're curious) how much more slowly that set of seven strategies would run without the onepass calculations!
