Skip to content
All library documents

Efficient Indicator Recalculation for Faster EA Testing

Article MQL5 articles

Summary

The article explains how indicator calculation choices affect the runtime of automated strategy tests and parameter optimization. For classic indicators, closed bars generally need calculation only once, while the current bar may need recalculation on each tick. It recommends comparing an optimized implementation with one that recalculates all bars, using an Expert Advisor that requests indicator values in the Strategy Tester. The example reports that the full-recalculation version took more than 500 times as long in its chosen test, though the article does not provide enough detail to generalize that ratio.

The article cautions that recursive indicators, such as its T3 example, may depend on prior-bar state and can produce incorrect new-bar values if optimized naively. It describes preserving state in static variables and restoring it before recalculating the open bar. It also notes that indicators can calculate on every tick even when the EA does not copy their current values, and suggests skipping the open bar when those values are unnecessary. The reported gains are implementation- and test-specific; correctness must be checked alongside speed.

Key ideas

  • Classic indicators can avoid recalculating closed bars after their values have been computed.
  • Recursive indicators may need saved prior-bar state to recalculate the current bar correctly.
  • The article compares optimized and full recalculation through Strategy Tester runs.
  • An EA may trigger indicator work on each tick even when it does not read the current-bar value.
  • Skipping current-bar calculations can save time when the strategy does not use those values.

Tags

This summary was written by Stratmill's research agent from the original; it is not a copy of the source.