MQL4 to MQL5 Compatibility Library - Library for MetaTrader 5 | Forex Indicators Download - MT4/MT5 Resources


This library allows running most scripts and indicators from MetaTrader 4 on MetaTrader 5. Most of the features are already covered, only the trading logic is not added, so for experts, because the trading mechanism needs to be rewritten.
The library already covers most of the functionality except the EA trading mechanism. In addition, for functions that give errors on MT5, there are other functions with the same name but ending in MQL4. Most of them are for conflicting functions that already have the same name in MQL5. The original article only provided the framework library, so this version of the library mainly contains MQL4 functions. See the library source code with search pattern "MQL4" for specific function names.
To-do list: Expert Advisor trading mechanism for order sending and control. Some functions have generic stubs and give appropriate error messages in the log. The return code for these is always -1 .
Place mql4compat.mqh into your Include directory (it is located in your Windows user roaming profile).
In your MQL4 EA/Indicators/Library/Script, please add after #property definition:
#include
Change MQL4 functions:
integer_initialize ( ) to integer_initialize ( ) integer deinit ( ) to blank solution_initialize ( ) constant integer previously calculated, const datetime &time[], const double &open[], const double &high[], const double &low[], const double &close[], constant length &tick_volume[], const long &volume[], const int & spread[]) {
The last line of the return() function should look like this:
return (rate_total);Change conflicting functions between MQL4 and MQL5 due to parameter changes by adding MQL4 to their names:
Integer array initialization in MQL4 ( double & bulk[], double value) Integer array max MQL4 ( double & bulk[], integer count = whole array , integer start = 0 ) Integer array minimum MQL4 ( double & bulk[], integer count = whole array , integer start = 0 ) Integer array sorting MQL4 ( double & bulk[], integer count = whole array , integer start = 0 , integer sort directory = MODE_ASCEND) Double copy buffer MQL4 ( integer processing, integer exponent, integer transfer) Double envelope MQL4 ( string symbol, integer teff, integer ma_period, integer method, integer ma_shift, integer price, double deviation, integer mode, integer shift) Double file reading DoubleMQL4 ( integer processing, integer size = DOUBLE_VALUE) Boolean file search MQL4 ( long processing, integer offset, ENUM_FILE_POSITION origin) Integer indicator count MQL4 ( integer_prev_calculated = 0 ) Boolean object created in MQL4 ( string name, type ENUM_OBJECT , integer window, datetimetime1 , doubleprice1 , datetimetime2 = 0 , doubleprice2 = 0 , datetimetime3 = 0 , doubleprice3 = 0 ) Boolean object deletion MQL4 ( string name) String object description MQL4 ( string name) Integer object search MQL4 ( string name) Boolean object move MQL4( string name, integer view, date time time 1, double price 1) String object name MQL4 ( integer exponent) Integer objects delete all MQL4 ( integer window = empty, integer type = empty) Total number of integer objects MQL4 ( integer type = empty, integer window = - 1 ) Boolean setting index buffer MQL4 ( integer index, double & bulk[]) String string connection MQL4 ( string_str1 , string_str2 , ... string_str64 = ”” ) Integer StringGetCharMQL4( string text, integer position) String string set CharMQL4 ( string text, integer position, integer value) iACMQL4 double ( string symbol, integer tef, integer transfer) iADMQL4 double ( string symbol, integer tef, integer transfer) Double iADXMQL4 ( string symbol, integer tef, integer period, integer price, integer mode, integer transfer) Double iAOMQL4 ( string symbol, integer tef, integer transfer) Double iATRMQL4 ( string symbol, integer tef, integer period, integer transfer) Double iAlligatorMQL4( string symbol, integer tef, integer mandibular phase, integer mandibular shift, integer dental period, integer tooth displacement, integer lip phase, integer lip movement, integer method, integer price, integer mode, integer transfer) double iBWMFIMQL4 ( string symbol, integer teff, integer transfer) double iB andsMQL4( string symbol, integer tef, integer period, double deviation, integer band_shift, integer method, integer mode, integer shift) double iBearsPowerMQL4( string symbol, integer tef, integer period, integer price, integer shift) double i BullsPowerMQL4( String Symbol, Integer Tef, Integer Period, Integer Price, Integer Transfer) Double iCCIMQL4( String Symbol, Integer Tef, Integer Period, Integer Price, Integer Transfer) Double iDeMarkerMQL4( String Symbol, Integer Tef, Integer Transfer) Integer periods, integer transfer) Double iForceMQL4 ( String symbol, integer tef, Integer period, Integer method, Integer price, Integer transfer) Double iFractal MQL4 ( String symbol, Integer tef , Integer mode , Integer transfer) Double iGatorMQL4 ( String symbol, Integer special Husband, integer mandibular period, integer mandibular shift, integer tooth period, integer tooth shift, integer lip period, integer lip movement, integer method, integer price, integer mode, integer transfer) Double Ichimoku MQL4 ( string symbol, integer tefu, integer Akansen, integer kijun_sen, integer sen kou_span_b, integer mode, integer transfer) double iMACDMQL4 ( string symbol, integer tef, integer fast_EMA_period, integer slow EMA period, integer signal period, integer price, integer mode, integer transfer) double iMAMQL4 ( string symbol, integer special iMomentumMQL4( string symbol, integer period, integer ma_shift, integer method, integer price, integer shift) double iMFIMQL4 ( string symbol, integer tref, integer period, integer shift ) ) double iOBVMQL4( string symbol, integer tef, integer price, integer transfer) double iOsMAMQL4( string symbol, integer tef, integer fast_EMA_period, integer slow EMA period, integer signal period, integer price, integer transfer) double iRSIMQL4(">String symbol, integer tef, integer period, integer price, integer transfer) double iRVIMQL4 ( string symbol, integer tef, integer period, integer mode, integer transfer) double iSARMQL4 ( string symbol, integer tef, integer transfer) double iSARMQL4 ( string symbol, integer tef, integer ma ) _period, integer ma_shift, integer method, integer price, integer shift) double iStochasticMQL4 ( string symbol, integer teff, integer K period, integer D period, integer slowdown, integer method, integer field, integer mode, integer shift) double iWPRMQL4 ( string symbol, integer teff , integer period, integer shift)
In the indicator, the OnInit() function and the #property header need to be adjusted manually. Furthermore, the IndicatorCounted() function needs to be changed to a variable of the same name by removing the clause or changing to the MQL5 prev_calculated variable:
#define IndicatorCounted IndicatorCountedMQL4 (prev_calculated) In custom indicators, see how the #property header takes MQL5 and then exchanges the input parameter definition type external to the input . Now also in MQL5 any attempt to change the value of a constant will result in an error. The workaround is to add a temporary variable and copy the input parameter values into it.
In the first line of your base code, please add the MQL4 reserved variable initialization function (if the custom indicator is used for OHLC/time/volume reserved variables, a warning about them will be issued by the OnCalculate() function, which can be safely ignored):
Attachment download
📎 mql4compat.mqh (54.62 KB)
Source: MQL5 #1787
MQL4 to MQL5 Compatibility Library - Important points before using the library for MetaTrader 5
This page has been supplemented with structured instructions, focusing on the purpose of EA source code, MQL4/MQL5 platform compatibility, testing process and risk control. Before downloading or deploying, it is recommended to first determine whether it is consistent with your own variety, cycle and account environment.
Suitable for who to use
- Users who want to quickly screen EA source code and are willing to do simulation disk verification first.
- People who need to compare MT4/MT5 EAs, indicators, scripts or source code projects.
- Traders who wish to record backtests, parameters and risk boundaries before placing a trade.
Testing and risk control suggestions
- First verify the default parameters in the strategy tester or demo account, and then adjust the symbol, period, spread and trading period one by one.
- Scalping, grid, martin, and high-frequency strategies should focus on observing maximum drawdowns, consecutive losses, slippage, and trading frequency.
- It is not recommended to run any document directly on the real disk. At least observe the simulated disk performance for 2-4 weeks first.
FAQ
Can MT4 and MT5 be used interchangeably?
Usually cannot be used directly. EX4/MQ4 corresponds to MT4, EX5/MQ5 corresponds to MT5, and the source code needs to be compiled in the corresponding MetaEditor.
Is this resource guaranteed to be profitable?
cannot. EAs, indicators and scripts can only be used as trading tools, and the results depend on parameters, market environment, spreads, slippage and risk control.
What else can I continue to watch?
Forex EA download , foreign exchange indicator download , EA evaluation , MQL5 CodeBase .
English Search Notes
This page is also optimized for English search intent around MQL4 to MQL5 Compatibility Library - Library for MetaTrader 5. Related search terms include: MQL4 source code, MQL5 source code. Test any Forex EA, Expert Advisor, MT4/MT5 indicator, script or MQL source code with historical data and a demo account before live trading.
💡 Featured Recommendations
✍️ Latest by the author
- •
- •
- •
- •
- •
- •
📌 Popular topics
- •
- •
- •
- •
- •
- •
- •
- •
🔗 You May Be Interested In
- •
- •
- •
- •
- •
- •