MQL5
MQL5 is the programming language used to create custom Expert Advisors (EAs), indicators, and scripts for the MetaTrader 5 trading platform. Developed by MetaQuotes, it enables traders to automate strategies, conduct technical analysis, and build bespoke tools directly within the MT5 environment. As a compiled, object‑oriented language, MQL5 offers access to market data, order management, and advanced charting functions, making it a core component for algorithmic trading on the platform.
How It Works
MQL5 code is written in the MetaEditor IDE that ships with MetaTrader 5. The language follows a syntax similar to C++, supporting classes, inheritance, and polymorphism. When a script is compiled, MetaExpert produces an executable file (.ex5) that the platform loads into memory. Key event handlers such as OnInit, OnDeinit, and OnTick define the EA’s lifecycle: initialization, cleanup, and reaction to each new tick. Built‑in functions provide access to price history, account information, and order execution, while the Standard Library offers ready‑made modules for risk management, trailing stops, and news filtering. The compiled nature ensures fast execution, essential for high‑frequency strategies.
Why It Matters for Traders
Using MQL5 allows traders to implement algorithmic trading systems that operate without emotional interference, execute trades consistently, and monitor multiple instruments simultaneously. Custom indicators can reveal unique market perspectives unavailable through default tools. Strategy backtesting in the platform’s Strategy Tester lets traders evaluate performance on historical data before risking capital. Moreover, the ability to sell or lease EAs and indicators on the MetaTrader Market creates an additional revenue stream for skilled developers.
Example
Consider a simple moving‑average crossover EA. The programmer defines two input parameters: fastPeriod = 10 and slowPeriod = 30. In OnTick, the EA calculates the 10‑period and 30‑period simple moving averages of the closing price. When the fast MA crosses above the slow MA and no position exists, the EA sends a market buy order for 0.1 lot. Conversely, a cross below triggers a close of the long position. The EA also includes a stop‑loss of 50 pips and a take‑profit of 100 pips, managed via the OrderSend function. After compiling, the trader attaches the EA to a EURUSD chart, enables live trading, and observes the system opening and closing trades according to the rule set.
Key Takeaways
- MQL5 is a compiled, object‑oriented language for building EAs, indicators, and scripts on MetaTrader 5.
- It provides direct access to market data, order execution, and advanced charting tools within the MT5 environment.
- Traders use MQL5 to automate strategies, backtest ideas, and remove emotional bias from trading decisions.