MQL4 vs MQL5: Differences That Matter When You Buy or Edit Source Code

MQL4 and MQL5 are the two programming languages used to build Expert Advisors and indicators for MetaTrader. They look similar, but they are not interchangeable. An .mq4 file will not compile in MetaTrader 5, and an .mq5 will not compile in MetaTrader 4. If you buy or edit source code, knowing the difference saves you a lot of confusion.

The short answer

  • MQL4 is for MetaTrader 4. Source files end in .mq4, compiled files in .ex4.
  • MQL5 is for MetaTrader 5. Source files end in .mq5, compiled files in .ex5.

Your broker and your platform decide which one you need. If you trade on MT4, you need MQL4 code. If you trade on MT5, you need MQL5 code.

Why they are not compatible

MQL5 was a ground up rewrite. It uses a more modern, object oriented structure, a different event model, and a different way of handling orders and positions. MQL4 works with a simple order pool, while MQL5 separates orders, deals, and positions into distinct concepts. Because of this, you cannot just rename an .mq4 to .mq5 and expect it to work. The order handling code has to be rewritten.

Key technical differences

Order and position handling

In MQL4 you send an order with OrderSend and loop through orders with OrderSelect. In MQL5 you use the CTrade class or the OrderSend request structure, and positions are managed separately from pending orders. This is the single biggest source of incompatibility.

Indicators

MQL4 reads indicator values directly with functions like iMA. MQL5 creates an indicator handle first, then copies values into a buffer. More steps, but more flexible.

Language features

MQL5 supports full object oriented programming, structures, and templates in a cleaner way. MQL4 gained some of these later, but MQL5 was built for them from the start.

Which should you choose?

If you are starting fresh, MT5 and MQL5 are the modern choice. MT5 supports more asset classes, has a faster strategy tester with multi threading, and is where MetaQuotes focuses development. That said, plenty of solid strategies still run on MT4, and many brokers offer both.

When you shop for source code, always check the platform first. Every listing in our free source code library and our premium catalog is labeled MT4 or MT5 so you never buy the wrong one.

Can you convert MQL4 to MQL5?

Yes, but it is real work, not a find and replace. The order logic, indicator calls, and event handlers all need to be rewritten. If you are comfortable editing code, it is doable. If not, it is usually easier to find an EA already written for your platform. Our guide on editing EA source code is a good place to start.

Shopping Cart