Skip to content
All library documents

Porting Simple MQL4 Indicators to MQL5 with a Compatibility Library

Article MQL5 articles

Summary

The article outlines a staged method for adapting simple MQL4 price indicators, using MACD as its example. It first changes the legacy calculation routine to accept bar counts, prior-calculation state, output buffers, and inputs as arguments. The code is then placed in an MQL5 custom-indicator template and connected through a compatibility library that supplies MQL4-style functions and state.

The debugging guidance focuses on replacing legacy references with MQL5 equivalents and setting indicator buffers to series order after binding. The article explains that the compatibility layer creates and recalculates data needed by the older calculation model, which can introduce delays; its postscript notes that a newly created indicator handle may not have calculated data immediately. The method targets straightforward price calculations. Indicators with graphical elements or more involved calculations may need substantial changes, and the author says a full MQL5 rewrite better fits MQL5's data-access model.

Key ideas

  • The MQL4 calculation routine can be adapted to receive bar counts, buffer references, and input parameters explicitly.
  • An MQL5 custom-indicator template can call the adapted routine through a compatibility library.
  • Legacy function names and bar-count variables need to be mapped to MQL5 equivalents during debugging.
  • Bound indicator buffers may need series indexing restored explicitly.
  • Compatibility-based transfer can delay recalculation, while complex indicators may require a native MQL5 rewrite.

Tags

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