MetaTrader 4 vs MetaTrader 5 API
The same fields from the MetaTrader 4 (MQL4) record and the MetaTrader 5 (Python package and MQL5) record, side by side. No winner is picked: which one suits you depends on what you are building.
Risk warning: CFDs and spread bets are complex instruments and come with a high risk of losing money rapidly due to leverage. You can lose money on these products, and each provider publishes its own loss figure under FCA rules. You should consider whether you understand how they work and whether you can afford to take the high risk of losing your money. Automated and API trading can amplify losses through bugs, connectivity failures and runaway orders.
What the two records show
Differences you can see in the records themselves. These are counts of what this site holds, not a verdict on either API.
- MetaTrader 4 (MQL4) is a platform API, offered through the brokers that carry the platform. MetaTrader 5 (Python package and MQL5) is a platform API, offered through the brokers that carry the platform.
- This site has not yet documented individual endpoints for MetaTrader 4 (MQL4) or for MetaTrader 5 (Python package and MQL5).
- This site has decoded 161 error codes for MetaTrader 4 (MQL4) and 311 error codes for MetaTrader 5 (Python package and MQL5).
- The limits register holds no limit records for MetaTrader 4 (MQL4) and no limit records for MetaTrader 5 (Python package and MQL5). Each limit record carries its own scope.
- The MetaTrader 4 (MQL4) record holds a demo claim, verified at its source. The MetaTrader 5 (Python package and MQL5) record holds a demo claim, verified at its source. The wording of each is in the Demo row below.
- A quickstart is built here for MetaTrader 5 (Python package and MQL5) only.
MetaTrader 4 (MQL4) and MetaTrader 5 (Python package and MQL5), field by field
| Field | MetaTrader 4 (MQL4) | MetaTrader 5 (Python package and MQL5) |
|---|---|---|
| Kind | Platform API, offered by many brokers | Platform API, offered by many brokers |
| API family | MQL4, WebRequest (HTTP from MQL4) | Python package (MetaTrader5), MQL5, WebRequest and sockets from MQL5 |
| How you get access | Install the MT4 terminal from a broker and write Expert Advisors or scripts in MQL4.Install terminal (MT4 help)checked | Install the MT5 terminal from your broker, then pip install MetaTrader5 on Windows x86-64 or write MQL5 in MetaEditor. The terminal must be at build 4755 or later.order_sendchecked |
| Who can use it | Real accounts can only be opened by brokerage companies that offer MT4.Opening of accounts (MT4 help)checked | Real accounts come from brokers offering MT5; the API runs through your own local terminal.Opening an account (MT5 help)checked |
| Demo | Yes: demo accounts can be opened from within the terminal.Opening of accounts (MT4 help)checked | Yes: demo accounts can be opened from within the terminal.Opening an account (MT5 help)checked |
| Authentication | No API keys: code runs inside a terminal already logged in to a trading account.MQL4 Referencechecked | No API keys: initialize() connects to the local terminal, optionally with account login, password and server.initializechecked |
| Streaming | In-terminal events only (new tick, timer, depth changes); no external streaming API.MQL4 Referencechecked | No push API in Python: poll ticks and bars; market_book_add subscribes the terminal to depth events. MQL5 EAs get tick events.MetaTrader for Pythonchecked |
| History depth | Bars limited to the terminal's max bars in chart. Closed orders limited to what the Account History tab has loaded.MQL4 docs: CopyRateschecked | Bars limited to the terminal's Max bars in chart setting. Deal history by date range with no stated limit.MQL5 docs: copy_rates_fromchecked |
| Limits | None recorded | None recorded |
| Endpoints documented here | None yet | None yet |
| Error codes decoded here | 161 | 311 |
| Official documentation | docs.mql4.com | mql5.com |
Go deeper on each side
MetaTrader 4 (MQL4)
- MetaTrader 4 API page, the full record
- No MetaTrader 4 API quickstart is built here yet
- MetaTrader 4 API limits, in the table above: none recorded
- MetaTrader 4 API error codes, each with its fix
MetaTrader 5 (Python package and MQL5)
- MetaTrader 5 API page, the full record
- MetaTrader 5 API quickstart, credentials to a first call
- MetaTrader 5 API limits, in the table above: none recorded
- MetaTrader 5 API error codes, each with its fix
- Claude with MetaTrader 5: a safe, read-first setup
- MetaTrader 5 for Python: which platforms does it run on?
- MT5 trade history to a spreadsheet with Python
All comparisons. New to this? Getting started with API trading.