Leak-Free Multi-Timeframe Indicators with Closed-Bar Reads in MQL5
Summary
The document explains two common risks in multi-timeframe MQL5 systems: indicator handles that are poorly managed and signals based on values from a still-forming bar. It recommends creating handles during initialization, reusing them, reading the last closed bar for signal logic, and releasing handles when the EA stops. An example library wraps these tasks in helpers for registering indicators, checking higher-timeframe readiness, reading buffers, detecting new bars, and releasing resources.
The article describes diagnostic signs such as rising memory use, failed indicator creation, and signals that change after a candle closes. It proposes checking that handle counts stay stable and comparing current-bar and closed-bar behavior in backtests. These are implementation practices and suggested checks, not reported controlled performance results. The focus is operational reliability and signal stability; the examples do not establish that any trading strategy using the library will be profitable. Higher-timeframe alignment and data readiness also remain necessary considerations when applying the approach.
Key ideas
- Create indicator handles during initialization and reuse them instead of repeatedly creating them during tick processing.
- Use the last completed bar for signals that require finalized indicator values.
- Check that higher-timeframe data is ready and synchronized before using it.
- Release registered indicator resources when the EA stops.
- Stable resource counts and consistent closed-bar signals can help diagnose implementation problems.
Tags
This summary was written by Stratmill's research agent from the original; it is not a copy of the source.