MQL4 vs MQL5 Differences and Technical Insights

In this article we will go through the main differences between MQL4 vs MQL5 and some of the technical details.

MetaTrader MQL4 vs MQL5... Differences and Preference

MQL4 vs MQL5… Differences

MQL stands for MetaQuotes Language and it is the primary language use to develop tools in Metatrader.

MQL4 and MQL5 are different versions of the programming languages developed for creating trading algorithms, indicators, and scripts on the MetaTrader platforms.

While they share a common lineage, significant differences exist between them, impacting development practices and capabilities.

Quick Comparison Table

FeatureMQL4MQL5
Release Year20052010
Execution ModelOrderSend-basedPosition-based
Event HandlingLimitedAdvanced
Object-Oriented ProgrammingBasic SupportFull Support
Order ManagementSeparate OrdersNetting/Hedging
BacktestingSingle-ThreadedMulti-Threaded
File Extensions.mq4, .ex4.mq5, .ex5
Libraries & IncludesSupportedEnhanced Support
Indicators Limit8 BuffersUnlimited
Predefined Functionsinit(), start(), deinit()OnInit(), OnTick(), OnDeinit()
Predefined VariablesAsk, Bid, Bars_LastError, _Period, _Symbol
Array IndexingRight to Left (0 is current bar)Left to Right (0 is first bar)
extern Keyword BehaviorMutable Input ParameterSame as in C/C++
iCustom FunctionReturns Buffer ValueReturns Handle

A Brief History of MQL4 and MQL5

MQL4 was introduced in 2005 alongside MetaTrader 4 (MT4), becoming a staple for forex traders due to its simplicity and effectiveness in developing trading tools.

MQL5, launched in 2010 with MetaTrader 5 (MT5), aimed to provide a more robust and versatile programming environment, accommodating advanced trading strategies and a broader range of financial instruments.

Execution Model

MQL4 operates on an OrderSend-based model, where each trade is managed individually. This approach suits straightforward trading strategies but can become cumbersome when handling complex systems.

In contrast, MQL5 utilizes a Position-based model, consolidating multiple trades of the same instrument into a single position. This model aligns with advanced trading methodologies and diverse market requirements.

Event Handling

MQL4 offers basic event handling through functions like init(), start(), and deinit().

MQL5 replaces these with more specialized functions:

  • OnInit(): Executed during initialization.
  • OnTick(): Handles incoming ticks.
  • OnDeinit(): Executed during deinitialization.

This enhancement provides greater control and responsiveness in automated systems.

Object-Oriented Programming (OOP)

While MQL4 supports OOP to a limited extent, allowing for simple classes and objects, MQL5 offers comprehensive OOP features, including inheritance, polymorphism, and encapsulation.

This advancement facilitates the development of scalable and maintainable code.

Order Management

In MQL4, each order is treated separately, which can complicate the management of multiple trades.

MQL5 introduces both Netting and Hedging systems, offering flexibility in trade management and aligning with global market standards.

Backtesting Performance

MQL4 backtesting is single-threaded, limiting the speed and efficiency of strategy testing.

MQL5, however, offers multi-threaded backtesting, significantly enhancing performance and accuracy when testing over historical data.

File Extensions

MQL4 uses .mq4 for source files and .ex4 for compiled files.

MQL5 uses .mq5 and .ex5, reflecting its enhanced capabilities.

Libraries and Includes

Both languages support libraries and include files, but MQL5 provides a more structured and efficient approach for code reuse and modular development.

Indicator Plotting Styles

MQL4 can use a maximum of 8 indicator buffers in its programs.

MQL5 does not have a limit in the number of indicators that can used as source.

Predefined Functions

In MQL4, the predefined functions are init(), start(), and deinit().

MQL5 replaces these with OnInit(), OnTick(), and OnDeinit(), respectively, aligning with its advanced event-handling system.

Predefined Variables

MQL4 includes predefined variables such as Ask, Bid, and Bars.

In MQL5, these are replaced with _LastError, _Period, _Symbol, and others, offering a more comprehensive set of system variables.

Array Indexing

In MQL4, the index [0] refers to the current bar on the extreme right position.

In MQL5, the index [0] refers to the first bar on the extreme left position, indicating a shift in array indexing methodology. There are easy functions to adjust this, but nonetheless it is something to know.

extern Keyword Behavior

In MQL4, the extern keyword defines a variable as a mutable input parameter.

In MQL5, extern functions similarly to its usage in C/C++, aligning with standard programming practices.

iCustom Function

In MQL4, the iCustom function returns a buffer value directly, allowing immediate access to indicator data.

MQL5, however, returns a handle to the custom indicator, requiring additional steps to retrieve the actual data.

Migrating from MQL4 to MQL5

MQL5 is very similar to MQL4 in some aspects and syntax, however it is not 100% compatible.

This means that you cannot just copy paste MQL4 into MQL5 and compile it, it will likely won’t work.

Some syntax will need adjusting, some functions too.

Moving from MQL4 to MQL5 is a process that needs attention and time.

You can experiment with some simple code, but complex programs will be more challenging.

What-is-Metatrader-MT5-2

I Chose MQL5 vs MQL4

While I used MQL4 for a very long time to develop my indicators and EAs, I have now switched to MQL5.

MQL5 may be a little more complex in some aspects, but it is more powerful, efficient and fast.

You will find some tools for MT4 on this website, but all new tools will be developed in MQL5 only, for MT5.

MT5 is a better platform in my opinion and that’s why I will continue investing effort in it.

Metaeditor-Folders-1

Conclusion

The transition from MQL4 to MQL5 brings numerous enhancements in performance, flexibility, and coding efficiency.

While MQL4 remains popular for its simplicity and familiarity, MQL5’s advanced features make it the superior choice for developing complex and efficient trading systems.

Understanding these differences helps traders and developers choose the right language for their needs.

In my case, I have chosen to continue all further developments in MQL5 for MT5, as I think it’s a better platform in the long term.

For questions or support please Contact Us.

Metatrader MT4 vs MT5… Differences and Choice

MQL5 Data Types

Leave a Comment