EA Doctor rule · Portability
MQL4 functions in an MQL5 file
The file uses MQL4's order functions and variables (OP_BUY, OrderSelect by position, Bid, Ask, Close[]), which MQL5 does not have.
Why it matters
MQL5 replaced MQL4's order model. There is no nine-parameter OrderSend(), no OrderSelect(…, SELECT_BY_POS), no OP_BUY, no Bid and Ask variables, no Close[] or Open[] arrays and no AccountBalance(). Such code does not compile for MetaTrader 5.
In MQL5, positions, orders and deals are separate lists with their own functions. A port is a rewrite of the trading part, not a rename; the MQL5 error library shows how 4108 and 4109 from MQL4 map to MQL5.
When the rule fires
The file uses MQL4 names that MQL5 does not have (OP_BUY and the other OP_ constants, SELECT_BY_POS, MODE_TRADES, OrderSend() with more than four arguments, OrderClose(), OrderLots(), MarketInfo(), RefreshRates(), AccountBalance(), Bid, Ask, Close[] …) without declaring them itself. When most of the file is MQL4, EA Doctor reports this rule only.
When it stays quiet
Files that include an MQL4 compatibility library (for example MT4Orders) or declare those names themselves.
How to fix it
- Replace order functions with MQL5's:
CTrade(orOrderSend()withMqlTradeRequest),PositionsTotal()/PositionGetTicket()for open positions,OrdersTotal()/OrderGetTicket()for pending orders. - Read prices with
SymbolInfoDouble(_Symbol, SYMBOL_BID)/SYMBOL_ASK, bars withiClose()orCopyRates(), account values withAccountInfoDouble().
Code that fires it
void OpenBuy()
{
int ticket = OrderSend(Symbol(), OP_BUY, 0.10, Ask, 3, 0, 0, "", 12345, 0, clrBlue);
if(ticket < 0)
Print("OrderSend failed: ", GetLastError());
}Fixed code
void OpenBuy()
{
const double ask = SymbolInfoDouble(_Symbol, SYMBOL_ASK);
trade.SetExpertMagicNumber(12345);
trade.SetDeviationInPoints(3);
if(!trade.Buy(0.10, _Symbol, ask, 0.0, 0.0))
PrintFormat("Buy failed: retcode %u (%s)", trade.ResultRetcode(), trade.ResultRetcodeDescription());
}The fixed code shows this rule’s fix and compiles in MetaEditor for MetaTrader 5 (with CTrade trade, InpLots and InpMagic declared, as in a typical EA). Other rules may still apply to it as a fragment: check your whole EA.
Related MQL5 errors
- 4108Timer or Invalid TicketERR_CHART_CANNOT_CREATE_TIMER
- 4109Chart Property or Trade Not AllowedERR_CHART_WRONG_PROPERTY
More rules on portability
- MediumHard-coded symbol nameThe code names a symbol such as "EURUSD" or "XAUUSD", which breaks on brokers that use another name or a suffix.
Sources
Get your EA fixed
Check a whole EA for this and 29 other mistakes with EA Doctor, free and in your browser. Or send it to us: we confirm the price in writing, then fix it.