Blog

How to Convert an MT4 EA to MT5 (and Why Converters Fail)

TradeSmithy Team4 min read

Short answer: you cannot run an MT4 Expert Advisor on MT5 — .ex4 files only load in MetaTrader 4. Converting means rewriting the MQL4 source as MQL5: trade handling, indicator access and account logic all change, not just names. With the source you can rewrite or convert it; without the source you must rebuild the strategy from its rules. Either way, backtest the MT5 version from scratch.

Why an MT4 EA does not "just work" on MT5

MetaQuotes built MT5 on a different language. Programs written for one do not compile in the other, and compiled files are not interchangeable. The differences that matter most for an EA:

AreaMQL4MQL5
Opening a tradeOrderSend(...) returns a ticketCTrade.Buy() / OrderSend(request, result)
Open tradesOne mixed list of ordersPositions, orders and deals are separate
IndicatorsiRSI(...) returns a valueiRSI(...) returns a handle; values come from CopyBuffer
PricesBid, Ask variablesSymbolInfoDouble(_Symbol, SYMBOL_BID)
AccountAccountBalance()AccountInfoDouble(ACCOUNT_BALANCE)
ErrorsGetLastError() codesTrade result retcodes plus error codes
Position modelMany trades per symbolNetting (one per symbol) or hedging, by account

The dangerous differences compile cleanly. MT4 numbers some indicator lines from 1 (Alligator, Fractals, Envelopes, Ichimoku, Gator) where MT5 numbers every buffer from 0, and iBands takes its arguments in a different order. A mechanical conversion that misses either trades on the wrong line with no error. The full list is here.

Netting versus hedging

When MT5 launched it only supported netting — one position per symbol, with new trades adding to or reducing it. MT4-style strategies that hold several trades at once only behave the same on an MT5 hedging account, which brokers now widely offer. Check which your account is before judging a converted EA: the same code behaves differently on each.

Your options

You have the .mq4 source

  • Rewrite by hand (or pay a developer to). Most reliable for complex EAs.
  • Use a converter or compatibility library. These map MQL4 calls onto MQL5 equivalents and can get simple EAs compiling. They struggle with order loops, position logic and anything that assumes MT4's single order list.
  • Ask an AI to convert it. Helpful as a first draft; check every trade call and indicator read — the mistakes are the ones above, and they compile.

You only have the .ex4

You cannot convert a compiled file. Rebuild the strategy from its rules: the vendor's documentation, its inputs, and its trade history in a backtest tell you most of what it does. If you bought it, ask the vendor for an MT5 version first.

The rebuild route: platform as a setting

If you rebuild a strategy as a graph, the platform stops being a rewrite. In TradeSmithy, a project targets MT4 or MT5, and switching it changes nothing on the canvas — it re-checks the graph against the new platform and exports the other language, generated by a separate MQL5- or MQL4-specific generator rather than a find-and-replace. Every indicator MT4 ships also exists on MT5, so an MT4 graph moves to MT5 cleanly; the one thing to replace is any custom indicator, whose .ex4 needs its .ex5 equivalent — the builder flags it on the node and refuses to export until it is fixed.

Retest after converting — always

A converted EA is a new EA. Even perfectly translated logic meets different history, a different tester and possibly a different position model. Run it in the MT5 Strategy Tester — step-by-step guide — compare the trade list with the MT4 version over the same dates, and explain every difference before trading it.

Rebuild once, export to both

Start free on TradeSmithy, rebuild the strategy on the canvas, and export it as MQL5 — or MQL4, from the same graph — with one export a month free. On Pro, describe the old EA's rules to the AI assistant and let it build the first draft of the graph. Background: how to create an MT4 EA without coding.

Frequently asked questions

Can MT5 run MT4 Expert Advisors?

No. MT5 only runs .ex5 files compiled from MQL5 source.

Is there a free MT4 to MT5 EA converter?

Converters and compatibility libraries exist and help with simple EAs. Anything with order management usually needs manual work and a full retest.

Can I convert an .ex4 file to MT5?

Not directly. Without the source code, the strategy has to be rebuilt from its rules.

Why does my converted EA behave differently on MT5?

Usually the position model (netting vs hedging), indicator line numbering, or different historical data. Compare trade lists to find which.

Keep reading

← More from the TradeSmithy blog