Discussing the article: "Lazy-Loading Indicator Handles in MQL5: A Resource Manager Pattern for Multi-Timeframe EAs"
You don't need all this: the platform supports reference counting and resource cleanup (for indicator handles left unreferenced after deinit) right from the shelf, and behind the scenes.
You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
Check out the new article: Lazy-Loading Indicator Handles in MQL5: A Resource Manager Pattern for Multi-Timeframe EAs.
Multi‑timeframe EAs that initialize every indicator handle in OnInit() pay a fixed startup cost even when most handles are never used. CIndicatorCache applies lazy loading with composite‑key lookup, reference‑counted Acquire/Release, and a deterministic FlushAll() for cleanup. Handles are created on first request and reused across ticks, reducing startup latency, avoiding repeated heap allocation, and preventing terminal resource leaks through centralized ownership.
A multi-timeframe Expert Advisor (EA) trading 10 symbols across four timeframes with five indicators per combination requires 200 indicator handles for full coverage. Conventionally, developers initialize all handles inside OnInit(). Before OnInit() returns, the terminal connects to each price feed, verifies data availability, allocates indicator buffers, and registers the handles. This process introduces initialization latency. This latency increases during terminal cold starts or when synchronizing stale historical data.
Furthermore, many of these handles are rarely used simultaneously. A strategy may only generate active signals on a small fraction of its watched symbols at any given time. The remaining inactive handles consume memory and handle slots without contributing to the current session.
Static initialization also increases code maintenance overhead. If indicator requirements change, developers must manually update the handle instantiations in OnInit(). Omitted or forgotten handles waste runtime resources while remaining undetected by the compiler.
The lazy-loading resource manager pattern resolves these inefficiencies through three core mechanisms:
Author: Ushana Kevin Iorkumbul