Skip to content
All library documents

Porting MQL5 Wizard Expert Advisors to MetaTrader 4

Article MQL5 articles

Summary

This article describes how to make Expert Advisors generated by the MetaTrader 5 Wizard usable in MetaTrader 4. Its approach is to adapt missing MQL5 Standard Library trade classes and emulate the relevant MQL5 trading interface on top of the older terminal’s API. The porting plan proceeds from enumerations and structures to constants and trade functions, using compiler errors to guide incremental changes and keeping modifications to existing library files limited where possible.

A central challenge is reconciling the platforms’ different trade models. The article maps an MT4 market order to MT5-style entry and exit orders, deals, and a position, and explains how hedging behavior affects that mapping. It provides an implementation framework and notes that the emulation cannot reproduce terminal capabilities absent from MT4’s underlying system. The library version described is specific to an older build, so future updates may require merging changes again. The implementation is labeled beta and is not presented as a fully tested system for live trading.

Key ideas

  • The MT4 Wizard lacks trade classes needed to generate complete Expert Advisors like the MT5 Wizard.
  • Porting requires adapting MQL5 types, structures, constants, and trading functions to the MT4 API.
  • MT4 orders need to be represented as MT5-style orders, deals, and positions in the emulated interface.
  • Differences in terminal capabilities limit the fidelity of the emulation.
  • Library updates and the beta status mean the port requires maintenance and thorough testing.

Tags

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