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: Leak-Free Multi-Timeframe Engine with Closed-Bar Reads in MQL5.
The article presents two systematic pitfalls in MQL5 multi‑timeframe work: indicator handle leaks that exhausted resources and repainting from reading the forming bar (index 0). It introduces MTFEngine.mqh, a unified include that creates and tracks handles in one place and defaults all reads to closed bars (index 1). A D1–H4–H1 example shows how this approach keeps signals technically correct and consistent with charts.
Writing multi-timeframe (MTF) logic in MQL5 is simple in theory: create indicator handles in OnInit(), read values from the last closed bar (shift = 1), and release handles in OnDeinit(). In practice these rules live only “in the developer's head.” A single iMA() call inside OnTick() or a CopyBuffer(…,0,…) typed by habit is enough to introduce two silent but dangerous failures: unreleased indicator instances that gradually exhausted terminal resources, and “phantom” signals that fire on still‑forming bar values and vanish after the bar closes. The symptoms are subtle — growing mt5.exe memory, Journal lines like "IndicatorCreate failed", or a strategy that produces more signals in live trading than it did in a closed‑bar backtest — so many authors miss the cause.
This article presents a structural fix: MTFEngine.mqh. Rather than rely on developer discipline, the engine makes correct behavior the default. All indicator handles are created only during initialization and managed internally; ReadBuffer() defaults to bar_shift = 1 and offers safe array reads for crossover checks; IsReady() checks both buffer contents and HTF bar timestamps to avoid stale HTF reads; and a single ReleaseAll() cleans up every handle. The result is a small, explicit API that prevents the two common failure modes before they can appear.
Author: Ushana Kevin Iorkumbul