CFDs and forex are complex instruments and come with a high risk of losing money rapidly due to leverage. Risk disclosure

MQL4 and MQL5: the programming languages of MetaTrader

This guide explains what MQL4 and MQL5 are, what you can build with them, how to start learning, and why code from unknown sources needs care.

Extrade Pakistan editorial team ·

On this page
  1. What is MQL4 and what is MQL5
  2. Types of MQL programs
  3. How MQL4 and MQL5 differ
  4. What a beginner can automate
  5. A learning path for MQL5 programming
  6. Risks of copying code
  7. Frequent questions

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.

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.

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:

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

  1. Learn the terminal. Know orders, positions, stop loss and contract specifications before you code them. The Trading glossary covers the terms.
  2. 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.
  3. Study the bundled examples. The terminal ships with sample indicators and EAs. Open them in MetaEditor and change small parts.
  4. Write an indicator, then a script, then an EA. Each step adds one new idea: drawing data, sending a trade, reacting to events.
  5. Test in the Strategy tester. Check results across different periods and with realistic spreads.
  6. 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.
  7. 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:

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.

Related pages