Skip to content
All library documents

Adapting an MQL5 Trading Library for MQL4 Compatibility

Article MQL5 articles

Summary

This article describes the first stage of adapting a MetaTrader trading library written for MQL5 so it can compile and operate in MQL4. The starting point is to compile the library under MQL4 and work through the errors, many of which arise because MQL4 lacks MQL5 constants, enumerations, or functions. The proposed approach adds a compatibility include file, conditionally included for MQL4, and defines missing types and values there.

The walkthrough uses deal types and position types as examples, then continues iteratively through compilation and implementation issues. It also describes checks of account-history displays for balance operations, closed positions, and removed pending orders, noting that the available history depends on the terminal’s selected history range. The article focuses on software compatibility and data handling rather than trading rules or performance. Its examples are tied to the library version and platform behavior discussed, and the excerpt is incomplete, so it does not provide a full compatibility specification.

Key ideas

  • Compiling the MQL5 library under MQL4 reveals missing constants, enumerations, and functions.
  • A conditional compatibility header can define MQL5 types needed by MQL4 builds.
  • Repeated compile-and-fix cycles provide a practical way to identify compatibility gaps.
  • Account-history displays in MQL4 depend on the history range selected in the terminal.
  • The described work prepares the library for later support of positions and pending orders.

Tags

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