Skip to content
All library documents

Incremental Indicator Calculation with Ring Buffers and History Sync

Article MQL5 articles

Summary

The article addresses the cost of recalculating custom indicators over full price history after synchronization events. It proposes a class that tracks calculated data separately, preserves a bounded history in a ring buffer, and reports whether data was initialized, synchronized, changed only at the latest bar, or left unchanged. The approach can support custom indicators in an EA as well as indicator implementations such as ZigZag and ATR.

History synchronization can be skipped for indicators less sensitive to revised prices, performed on each new bar, or checked on every synchronization call. A configurable recent time window is compared first, with broader history checked if a difference appears; selected price fields can also be limited. The design avoids repeated array copying, but requires maintaining and reconciling a local price-history copy. The article notes limits: calculations operate on a configured number of recent bars and are bound to the initialized symbol and period. Its strategy-tester comparison says the class does not significantly reduce performance relative to an ordinary custom indicator, so the main value is controlled incremental calculation rather than a demonstrated speed gain.

Key ideas

  • A separate state tracker can avoid recalculating an entire indicator history when only recent bars have changed.
  • A ring buffer uses fixed allocated memory and wraparound indexing to retain a bounded history.
  • History synchronization can be skipped, checked at each new bar, or performed on every call depending on accuracy needs.
  • The method requires a local price-history copy and logic to detect and correct differences with terminal history.
  • The configured class is tied to a symbol and timeframe and calculates only a specified recent history depth.

Tags

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