Embedding Indicator Calculations Inside a Trading Expert Advisor
Summary
This article explains how to move indicator calculations from a separate MetaTrader 5 indicator into an expert advisor. The motivation may include packaging the strategy in one program, controlling which calculations run, or keeping implementation details together. Since indicators receive price histories and maintain chart-linked buffers automatically, an EA that performs the same calculations must manage its own buffers, load time-series data, track new bars, and decide how much history to recalculate.
The proposed design wraps these responsibilities in reusable classes: a buffer class for storing and shifting values, a base indicator class for loading history and exposing calculated data, and indicator-specific classes that implement the calculations. The article compares this approach with obtaining values through standard indicator handles and reports experiments involving moving-average calculations, including a more computationally intensive variant. The results suggest embedded calculations can reduce time during testing and optimization, while the benefit may disappear in live operation because MetaTrader 5 uses multiple threads. The evidence is specific to the described experiments and does not establish that relocation is faster for every indicator or EA.
Key ideas
- An EA must manage indicator buffers and price-history access that an indicator normally receives from the terminal.
- A reusable class structure can make embedded indicator values accessible in a way similar to standard buffers.
- The design separates buffer storage, history loading, recalculation, and indicator-specific logic.
- Experiments compare embedded moving-average calculations with standard indicator retrieval methods.
- Testing and optimization may benefit, but live performance gains may be offset by the platform’s multithreaded architecture.
Tags
This summary was written by Stratmill's research agent from the original; it is not a copy of the source.