MQL4
Definition
MQL4 is the programming language used to develop expert advisors, indicators, and scripts on MT4. Simpler than MQL5 — procedural syntax, less type-strict, smaller standard library. Legacy commercial EAs are typically MQL4; new commercial EAs ship both MQL4 and MQL5 versions.
In-depth: MQL4
MQL4 occupies the entry-level tier of MetaTrader programming languages. The language was designed for retail traders who learned programming primarily to automate their trading rather than as software engineers, which shaped many of its design decisions.
Key MQL4 language features:
• **Procedural syntax**: traditional functions-and-statements model rather than object-oriented; simpler for non-programmers to learn • **Loose typing**: variables can be assigned values of compatible types without strict type enforcement; reduces boilerplate but increases bug risk • **Built-in trading functions**: OrderSend, OrderClose, OrderSelect, etc., providing direct access to broker operations • **Built-in technical indicators**: iMA, iRSI, iMACD, iBands, etc., for accessing standard indicators without reimplementing them • **Event-driven execution**: OnInit, OnTick, OnTimer, OnDeinit lifecycle functions for EA logic structuring • **Custom indicator support**: programmers can write custom indicators in MQL4 that EAs then consume via iCustom function calls
MQL4 limitations vs MQL5:
• **No object-oriented programming**: complex EA architectures requiring class hierarchies must be expressed procedurally, increasing code complexity • **No multi-threading**: single-threaded execution model limits parallel computation in complex strategies • **Limited standard library**: smaller built-in function library compared to MQL5 • **No native machine learning support**: ML-augmented strategies must call out to external systems or implement primitives manually
For EA buyers, MQL4 source-code visibility (when available) is valuable for auditability. Vendors who provide MQL4 source allow buyers to inspect strategy logic before purchase; vendors who provide only .ex4 compiled binaries require buyer trust in the vendor's claims about the underlying logic. Most premium vendors compile to .ex4 to protect intellectual property; budget vendors sometimes ship source.
Further reading: MQL4
MQL4 (MetaQuotes Language 4) is the C-like scripting language used to write Expert Advisors (EAs), custom indicators, and scripts for the MetaTrader 4 trading platform. It defines event handlers such as OnInit, OnTick and OnDeinit, and exposes trading functions like OrderSend and OrderModify, allowing programmatic order placement and position management. Developers compile MQL4 source files into .ex4 executables with MetaEditor. Example: an EA can check a 14-period RSI in OnTick and call OrderSend to open a 0.1-lot buy if RSI < 30. MQL4 supports libraries, include files, and built-in technical indicators, but does not guarantee profitability; performance depends on strategy logic, market conditions, broker execution, and proper testing.
MQL4 appears wherever traders automate strategies on MetaTrader 4: retail forex, CFD trading, signal services, and many broker-provided platforms. It is central to building EAs that run live on client terminals or VPS instances, and to creating custom indicators used on charts. Traders use MQL4 scripts during strategy development, to connect technical analysis rules to order functions, or to create automated risk-management routines. Example contexts include algorithmic scalping, grid systems, and indicator-based breakout alerts. MQL4 code is also uploaded to the MT4 Marketplace and shared in source or compiled form. Because MT4 remains widely supported by brokers, MQL4 skills are frequently used for legacy-system maintenance and rapid EA prototyping.
Traders use MQL4 to encode trading rules into Expert Advisors that monitor market data and act automatically. Typical workflow: write indicators to generate signals, program an EA with OnTick logic that evaluates signals and risk parameters, backtest using MT4’s Strategy Tester, optimize input parameters, then forward-test on a demo or small live account. For example, an EA might open positions with OrderSend, place stop-loss and take-profit levels via OrderModify, and handle trade management on each OnTick event. Advanced users modularize code into libraries for position sizing, trailing stops, and news filters. Always test across historical data and use proper risk controls; MQL4 tools enable automation but cannot assure future profits.