Adapting MQL5 Standard Library Classes for Cross-Platform Expert Advisors
Summary
The article explains how to reuse selected MQL5 Standard Library components in expert advisors that must compile under both MQL4 and MQL5. Its approach is to copy the relevant MQL5 headers, place them in an organized MQL4 library folder, and add shared include headers that select the original or adapted class according to the compiler. This avoids rewriting whole components while keeping platform-specific files separate.
Using CSymbolInfo as an example, it identifies unsupported symbol-property calls and enumerations that need to be removed, altered, or declared for MQL4 compatibility. It also describes adapted account and trade classes, plus managers for handling multiple object instances. The article is an implementation guide rather than a trading method: it provides code examples and class structure but no performance evidence. Its approach can leave the MQL4 version less complete than the original, and copied library code may require further changes as MQL5 components evolve.
Key ideas
- Shared include headers can route each platform to its original or adapted library classes.
- Copying and modifying MQL5 headers can reduce the amount of MQL4 code that must be rewritten.
- CSymbolInfo requires compatibility changes where MQL5 properties or enumerations are unavailable in MQL4.
- Managers can coordinate multiple symbol, account, and trade objects in an expert advisor.
Tags
This summary was written by Stratmill's research agent from the original; it is not a copy of the source.