What is MQL4 and what is MQL5
MQL stands for MetaQuotes Language. MetaQuotes is the company behind MetaTrader. MQL4 is the language for MetaTrader 4 (MT4), and MQL5 is the language for MetaTrader 5 (MT5). Both let you write programs that run inside the trading terminal.
Code is written in MetaEditor, the editor that comes with the terminal. In the terminal, open the Tools menu and choose MetaQuotes Language Editor. You write the source code, compile it into a file the terminal can run, and attach the result to a chart from the Navigator window.
The syntax of both languages is close to C and C++. If you have written any C-style code before, MQL will look familiar.
Ready to try it on a real or demo account?
Partner link · trading carries a high risk of loss
Types of MQL programs
| Program | What it does |
|---|---|
| Indicator | Calculates values and draws them on a chart. It cannot place trades. |
| Script | Runs once when dropped on a chart, for example to close all orders on a symbol. |
| Expert Advisor (EA) | Runs on every price tick or timer event and can open, modify and close trades automatically. |
| Library and include file | Shared code that other programs reuse. |
| Service (MT5 only) | Runs in the background without being tied to a chart. |
When people ask about the "MT5 expert advisor language", the answer is MQL5. See Expert Advisors for how to run them and Custom indicators for how to install ready-made files.
How MQL4 and MQL5 differ
The two languages share a lot, but code written for one does not run on the other without changes. Each terminal compiles and runs only its own language.
- Trading model. In MQL4, the main trading function is
OrderSend, which returns a ticket, and open trades are called orders. MQL5 separates orders (instructions), deals (executions) and positions (what is open). Trades are sent through a request structure or the standardCTradeclass. MT5 accounts can also use hedging or netting mode, which changes how positions behave. See Hedging vs netting. - Indicator access. In MQL4, a call such as
iMAreturns a value directly. In MQL5,iMAreturns a handle, and you read values withCopyBuffer. - Events. Both use event handlers such as
OnInit,OnDeinitandOnTick. MQL5 adds handlers such asOnTradeandOnTradeTransactionfor finer control. - Language features. MQL5 was object-oriented from the start, with classes and a large standard library. MQL4 gained many of these features later, but older MQL4 code is often written procedurally.
For a wider comparison of the terminals, see MT4 vs MT5.
What a beginner can automate
Start small. These tasks teach the basics without placing your money in the hands of untested logic:
- an indicator that colours candles or marks a level you watch by hand
- an alert when price crosses a moving average (compare with built-in price alerts)
- a script that sets a stop loss and take profit on all open positions
- a script that calculates position size from a fixed risk amount you enter
- a simple EA that only logs signals to the Experts tab without trading
Fully automated trading comes later, after the program has been tested on historical data and on a demo account.
A learning path for MQL5 programming
- Learn the terminal. Know orders, positions, stop loss and contract specifications before you code them. The Trading glossary covers the terms.
- Read the built-in help. In MetaEditor, place the cursor on a function name and open the help to see its parameters and an example.
- Study the bundled examples. The terminal ships with sample indicators and EAs. Open them in MetaEditor and change small parts.
- Write an indicator, then a script, then an EA. Each step adds one new idea: drawing data, sending a trade, reacting to events.
- Test in the Strategy tester. Check results across different periods and with realistic spreads.
- Run on a demo. Use an MT5 demo account to see how the code behaves with live quotes, requotes and errors. If you use a demo with Exness, check the current account conditions in the Exness personal area.
- Handle errors. Check the return value of every trade call and read the Journal and Experts tabs. MetaTrader errors lists common messages.
Menu names and features can change between terminal builds. If a step here does not match your screen, check the help inside your current version.
Risks of copying code
Free and paid EAs and indicators circulate on forums, Telegram and WhatsApp groups. Before you run any of them, keep these risks in mind:
- No source code. A compiled file can't be read. You don't know what it does with your account.
- Hidden logic. Code may open large positions, remove stop losses or use martingale (doubling size after a loss).
- Wrong assumptions. Code written for netting may misbehave on a hedging account, and code tuned for one symbol may fail on another.
- Curve-fitted results. A strong backtest can come from settings tuned to past data that will not repeat.
- Security. Do not enable DLL imports for files from unknown sources, and never share your account password with a code seller.
An EA is a tool, not a source of profit. Automated trading on leveraged CFDs and forex can lose money fast, sometimes faster than manual trading, because the program keeps acting while you are away. Read Risk management before you let any code trade.
Frequent questions
Is MQL5 hard to learn?
It is a full programming language, so expect a learning curve. Simple indicators and scripts are a realistic starting point for a beginner.
Can I run an MQL4 EA in MetaTrader 5?
No. MT5 does not run MT4 programs. The code must be rewritten in MQL5, mainly the trading and indicator parts.
Do I need to install MetaEditor separately?
No. MetaEditor comes with the desktop MetaTrader terminal and opens from the Tools menu.
Can an indicator place trades?
No. Indicators only calculate and draw. Trading needs a script or an Expert Advisor.
Is a profitable backtest enough to trust an EA?
No. A backtest shows how the code behaved on past data only. Test it on a demo and size risk as if the EA could fail.
