Platform API
MetaTrader 4 API (MQL4)
MetaQuotes' FX terminal; automation is MQL4 code running inside the terminal.
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.
Access, authentication and streaming
API types listed in the record: MQL4, WebRequest (HTTP from MQL4).
- How you get access
Install the MT4 terminal from a broker and write Expert Advisors or scripts in MQL4.
Install terminal (MT4 help)checked
- Who can use it
Real accounts can only be opened by brokerage companies that offer MT4.
- Demo
Yes: demo accounts can be opened from within the terminal.
- Authentication
No API keys: code runs inside a terminal already logged in to a trading account.
MQL4 Referencechecked
- Streaming
In-terminal events only (new tick, timer, depth changes); no external streaming API.
MQL4 Referencechecked
- 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
- Rate limits, as worded
Not published
MQL4 Referencechecked
MetaTrader 4 functions
28 documented functions. They are functions of a programming language, not HTTP endpoints: none has a method or a path, and the code runs against the terminal on your own computer. Grouped by what they do, each with its summary
MQL4
- AccountBalance()
- AccountEquity()
- AccountFreeMargin()
- AccountFreeMarginCheck()
- AccountInfoDouble()
- CopyRates()
- iClose()
- MarketInfo()
- OrderClose()
- OrderCloseBy()
- OrderDelete()
- OrderLots()
- OrderMagicNumber()
- OrderModify()
- OrderOpenPrice()
- OrderProfit()
- OrderSelect()
- OrderSend()
- OrdersHistoryTotal()
- OrderStopLoss()
- OrdersTotal()
- OrderSymbol()
- OrderTakeProfit()
- OrderTicket()
- OrderType()
- RefreshRates()
- SymbolInfoDouble()
- SymbolInfoTick()
MetaTrader 4 API error codes
161 decoded error codes. All MetaTrader 4 (MQL4) errors
0No error was returned.1No error was returned, but the result is unknown.2"Common error" is MetaQuotes' whole description of this code.3"Invalid trade parameters" is MetaQuotes' whole description of this code.4"Trade server is busy" is MetaQuotes' whole description of this code.5"Old version of the client terminal" is MetaQuotes' whole description of this code.6"No connection with trade server" is MetaQuotes' whole description of this code.7"Not enough rights" is MetaQuotes' whole description of this code.8"Too frequent requests" is MetaQuotes' whole description of this code.9"Malfunctional trade operation" is MetaQuotes' whole description of this code.64"Account disabled" is MetaQuotes' whole description of this code.65"Invalid account" is MetaQuotes' whole description of this code.128"Trade timeout" is MetaQuotes' whole description of this code.129"Invalid price" is MetaQuotes' whole description of this code.130"Invalid stops" is MetaQuotes' whole description of this code.131"Invalid trade volume" is MetaQuotes' whole description of this code.132"Market is closed" is MetaQuotes' whole description of this code.133"Trade is disabled" is MetaQuotes' whole description of this code.134"Not enough money" is MetaQuotes' whole description of this code.135"Price changed" is MetaQuotes' whole description of this code.136"Off quotes" is MetaQuotes' whole description of this code.137"Broker is busy" is MetaQuotes' whole description of this code.138"Requote" is MetaQuotes' whole description of this code.139"Order is locked" is MetaQuotes' whole description of this code.140 ERR_Only buy orders are allowed.LONG_ POSITIONS_ ONLY_ ALLOWED 141"Too many requests" is MetaQuotes' whole description of this code.145The modification was denied because the order is too close to the market.146"Trade context is busy" is MetaQuotes' whole description of this code.147Expirations are denied by the broker.148The number of open and pending orders has reached the limit set by the broker.149The code tried to open an order opposite to an existing one while hedging is disabled.150The code tried to close an order in a way that breaks the FIFO rule.4000No error was returned.4001"Wrong function pointer" is MetaQuotes' whole description of this code.4002"Array index is out of range" is MetaQuotes' whole description of this code.4003"No memory for function call stack" is MetaQuotes' whole description of this code.4004"Recursive stack overflow" is MetaQuotes' whole description of this code.4005 ERR_"Not enough stack for parameter" is MetaQuotes' whole description of this code.NOT_ ENOUGH_ STACK_ FOR_ PARAM 4006 ERR_"No memory for parameter string" is MetaQuotes' whole description of this code.NO_ MEMORY_ FOR_ PARAM_ STRING 4007 ERR_"No memory for temp string" is MetaQuotes' whole description of this code.NO_ MEMORY_ FOR_ TEMP_ STRING 4008"Not initialized string" is MetaQuotes' whole description of this code.4009 ERR_"Not initialized string in array" is MetaQuotes' whole description of this code.NOT_ INITIALIZED_ ARRAYSTRING 4010 ERR_"No memory for array string" is MetaQuotes' whole description of this code.NO_ MEMORY_ FOR_ ARRAYSTRING 4011"Too long string" is MetaQuotes' whole description of this code.4012 ERR_"Remainder from zero divide" is MetaQuotes' whole description of this code.REMAINDER_ FROM_ ZERO_ DIVIDE 4013"Zero divide" is MetaQuotes' whole description of this code.4014"Unknown command" is MetaQuotes' whole description of this code.4015"Wrong jump" is MetaQuotes' description, and it marks this as an error that is never generated.4016"Not initialized array" is MetaQuotes' whole description of this code.4017"DLL calls are not allowed" is MetaQuotes' whole description of this code.4018"Cannot load library" is MetaQuotes' whole description of this code.4019"Cannot call function" is MetaQuotes' whole description of this code.4020 ERR_"Expert function calls are not allowed" is MetaQuotes' whole description of this code.EXTERNAL_ CALLS_ NOT_ ALLOWED 4021 ERR_There is not enough memory for the temporary string returned from a function.NO_ MEMORY_ FOR_ RETURNED_ STR 4022"System is busy" is MetaQuotes' description, and it marks this as an error that is never generated.4023"DLL-function call critical error" is MetaQuotes' whole description of this code.4024"Internal error" is MetaQuotes' whole description of this code.4025"Out of memory" is MetaQuotes' whole description of this code.4026"Invalid pointer" is MetaQuotes' whole description of this code.4027 ERR_"Too many formatters in the format function" is MetaQuotes' whole description of this code.FORMAT_ TOO_ MANY_ FORMATTERS 4028 ERR_"Parameters count exceeds formatters count" is MetaQuotes' whole description of this code.FORMAT_ TOO_ MANY_ PARAMETERS 4029"Invalid array" is MetaQuotes' whole description of this code.4030"No reply from chart" is MetaQuotes' whole description of this code.4050 ERR_"Invalid function parameters count" is MetaQuotes' whole description of this code.INVALID_ FUNCTION_ PARAMSCNT 4051 ERR_"Invalid function parameter value" is MetaQuotes' whole description of this code.INVALID_ FUNCTION_ PARAMVALUE 4052"String function internal error" is MetaQuotes' whole description of this code.4053"Some array error" is MetaQuotes' whole description of this code.4054 ERR_"Incorrect series array using" is MetaQuotes' whole description of this code.INCORRECT_ SERIESARRAY_ USING 4055"Custom indicator error" is MetaQuotes' whole description of this code.4056"Arrays are incompatible" is MetaQuotes' whole description of this code.4057 ERR_"Global variables processing error" is MetaQuotes' whole description of this code.GLOBAL_ VARIABLES_ PROCESSING 4058 ERR_"Global variable not found" is MetaQuotes' whole description of this code.GLOBAL_ VARIABLE_ NOT_ FOUND 4059 ERR_"Function is not allowed in testing mode" is MetaQuotes' whole description of this code.FUNC_ NOT_ ALLOWED_ IN_ TESTING 4060"Function is not allowed for call" is MetaQuotes' whole description of this code.4061"Send mail error" is MetaQuotes' whole description of this code.4062 ERR_"String parameter expected" is MetaQuotes' whole description of this code.STRING_ PARAMETER_ EXPECTED 4063 ERR_"Integer parameter expected" is MetaQuotes' whole description of this code.INTEGER_ PARAMETER_ EXPECTED 4064 ERR_"Double parameter expected" is MetaQuotes' whole description of this code.DOUBLE_ PARAMETER_ EXPECTED 4065 ERR_"Array as parameter expected" is MetaQuotes' whole description of this code.ARRAY_ AS_ PARAMETER_ EXPECTED 4066"Requested history data is in updating state" is MetaQuotes' whole description of this code.4067"Internal trade error" is MetaQuotes' whole description of this code.4068"Resource not found" is MetaQuotes' whole description of this code.4069"Resource not supported" is MetaQuotes' whole description of this code.4070"Duplicate resource" is MetaQuotes' whole description of this code.4071"Custom indicator cannot initialize" is MetaQuotes' whole description of this code.4072"Cannot load custom indicator" is MetaQuotes' whole description of this code.4073"No history data" is MetaQuotes' whole description of this code.4074"No memory for history data" is MetaQuotes' whole description of this code.4075"Not enough memory for indicator calculation" is MetaQuotes' whole description of this code.4099"End of file" is MetaQuotes' whole description of this code.4100"Some file error" is MetaQuotes' whole description of this code.4101"Wrong file name" is MetaQuotes' whole description of this code.4102"Too many opened files" is MetaQuotes' whole description of this code.4103"Cannot open file" is MetaQuotes' whole description of this code.4104"Incompatible access to a file" is MetaQuotes' whole description of this code.4105"No order selected" is MetaQuotes' whole description of this code.4106"Unknown symbol" is MetaQuotes' whole description of this code.4107"Invalid price" is MetaQuotes' whole description of this code.4108"Invalid ticket" is MetaQuotes' whole description of this code.4109Trade is not allowed.4110Long positions are not allowed.4111Short positions are not allowed.4112 ERR_"Automated trading by Expert Advisors/Scripts disabled by trade server" is MetaQuotes' whole description of this code.TRADE_ EXPERT_ DISABLED_ BY_ SERVER 4200"Object already exists" is MetaQuotes' whole description of this code.4201"Unknown object property" is MetaQuotes' whole description of this code.4202"Object does not exist" is MetaQuotes' whole description of this code.4203"Unknown object type" is MetaQuotes' whole description of this code.4204"No object name" is MetaQuotes' whole description of this code.4205"Object coordinates error" is MetaQuotes' whole description of this code.4206"No specified subwindow" is MetaQuotes' whole description of this code.4207"Graphical object error" is MetaQuotes' whole description of this code.4210"Unknown chart property" is MetaQuotes' whole description of this code.4211"Chart not found" is MetaQuotes' whole description of this code.4212"Chart subwindow not found" is MetaQuotes' whole description of this code.4213"Chart indicator not found" is MetaQuotes' whole description of this code.4220"Symbol select error" is MetaQuotes' whole description of this code.4250"Notification error" is MetaQuotes' whole description of this code.4251"Notification parameter error" is MetaQuotes' whole description of this code.4252"Notifications disabled" is MetaQuotes' whole description of this code.4253 ERR_"Notification send too frequent" is MetaQuotes' whole description of this code.NOTIFICATION_ TOO_ FREQUENT 4260"FTP server is not specified" is MetaQuotes' whole description of this code.4261"FTP login is not specified" is MetaQuotes' whole description of this code.4262"FTP connection failed" is MetaQuotes' whole description of this code.4263"FTP connection closed" is MetaQuotes' whole description of this code.4264"FTP path not found on server" is MetaQuotes' whole description of this code.4265The file to send to the FTP server was not found in the Files directory under MQL4.4266"Common error during FTP data transmission" is MetaQuotes' whole description of this code.5001"Too many opened files" is MetaQuotes' whole description of this code.5002"Wrong file name" is MetaQuotes' whole description of this code.5003"Too long file name" is MetaQuotes' whole description of this code.5004"Cannot open file" is MetaQuotes' whole description of this code.5005 ERR_"Text file buffer allocation error" is MetaQuotes' whole description of this code.FILE_ BUFFER_ ALLOCATION_ ERROR 5006"Cannot delete file" is MetaQuotes' whole description of this code.5007"Invalid file handle (file closed or was not opened)" is MetaQuotes' whole description of this code.5008"Wrong file handle (handle index is out of handle table)" is MetaQuotes' whole description of this code.5009"File must be opened with FILE_WRITE flag" is MetaQuotes' whole description of this code.5010"File must be opened with FILE_READ flag" is MetaQuotes' whole description of this code.5011"File must be opened with FILE_BIN flag" is MetaQuotes' whole description of this code.5012"File must be opened with FILE_TXT flag" is MetaQuotes' whole description of this code.5013"File must be opened with FILE_TXT or FILE_CSV flag" is MetaQuotes' whole description of this code.5014"File must be opened with FILE_CSV flag" is MetaQuotes' whole description of this code.5015"File read error" is MetaQuotes' whole description of this code.5016"File write error" is MetaQuotes' whole description of this code.5017"String size must be specified for binary file" is MetaQuotes' whole description of this code.5018"Incompatible file (for string arrays-TXT, for others-BIN)" is MetaQuotes' whole description of this code.5019"File is directory not file" is MetaQuotes' whole description of this code.5020"File does not exist" is MetaQuotes' whole description of this code.5021"File cannot be rewritten" is MetaQuotes' whole description of this code.5022"Wrong directory name" is MetaQuotes' whole description of this code.5023"Directory does not exist" is MetaQuotes' whole description of this code.5024"Specified file is not directory" is MetaQuotes' whole description of this code.5025 ERR_"Cannot delete directory" is MetaQuotes' whole description of this code.FILE_ CANNOT_ DELETE_ DIRECTORY 5026 ERR_"Cannot clean directory" is MetaQuotes' whole description of this code.FILE_ CANNOT_ CLEAN_ DIRECTORY 5027"Array resize error" is MetaQuotes' whole description of this code.5028"String resize error" is MetaQuotes' whole description of this code.5029"Structure contains strings or dynamic arrays" is MetaQuotes' whole description of this code.5200 ERR_"Invalid URL" is MetaQuotes' whole description of this code.WEBREQUEST_ INVALID_ ADDRESS 5201 ERR_"Failed to connect to specified URL" is MetaQuotes' whole description of this code.WEBREQUEST_ CONNECT_ FAILED 5202"Timeout exceeded" is MetaQuotes' whole description of this code.5203 ERR_"HTTP request failed" is MetaQuotes' whole description of this code.WEBREQUEST_ REQUEST_ FAILED 65536This is not an error in itself: it is the first code available for errors that a program defines for itself.
MetaTrader 4 API: questions and answers
Each answer is read from the record on this page, not written separately. Where the record is unverified, the answer says so.
How do I get access to the MetaTrader 4 API?
Install the MT4 terminal from a broker and write Expert Advisors or scripts in MQL4.
Install terminal (MT4 help)checked
Who can use the MetaTrader 4 API?
Real accounts can only be opened by brokerage companies that offer MT4.
MetaTrader 4 API demo: is there a demo or sandbox?
Yes: demo accounts can be opened from within the terminal.
How does MetaTrader 4 API authentication work?
No API keys: code runs inside a terminal already logged in to a trading account.
MQL4 Referencechecked
Does the MetaTrader 4 API support streaming?
In-terminal events only (new tick, timer, depth changes); no external streaming API.
MQL4 Referencechecked
How much history does the MetaTrader 4 API return?
Bars limited to the terminal's max bars in chart. Closed orders limited to what the Account History tab has loaded.
MQL4 docs: CopyRateschecked
Which brokers offer MetaTrader 4?
Brokers on this register recorded as offering MetaTrader 4, with a source: Axi, Capital.com, CMC Markets, FOREX.com, FXCM, IG, OANDA, Pepperstone, Swissquote, ThinkMarkets and Tickmill. Recorded as offering it but unverified: FxPro.
Trading platforms, Axi UKchecked Capital.com UK MT4checked CMC Markets UK MetaTrader 4checked FOREX.com UK trading platformschecked FXCM UK MetaTrader 4checked IG UK MetaTrader 4checked OANDA UK MetaTrader 4checked Pepperstone UK trading platformschecked Swissquote UK, forex and CFD platformschecked ThinkMarkets support: Spread betting accountchecked Tickmill UKchecked
MetaTrader 4 API questions, each answered in a sentence or two.
Everything this site records for MetaTrader 4 (MQL4), as one JSON file. Each section of the file states its own licence. About the files. This page as Markdown.
MetaTrader 4 API guides and reference
MetaTrader 4 API compared
The same fields from two records, side by side. No winner is picked.
What changed recently for the MetaTrader 4 API
Documentation
The MQL4 reference carries a 2000 to 2025 copyright while mql5.com carries 2000 to 2026. No deprecation notice appears on either, so MQL4 stays recorded as legacy and not as deprecated. A copyright year is not a revision date and is not presented as one here.
MQL4 referencechecked
Ecosystem
MetaTrader 4 build 1470 improved interface translations, fixed errors and improved platform stability.
MetaTrader 4 release notes, build 1470date last opened not recorded
Ecosystem
MetaTrader 4 build 1460 delivered security improvements, bug fixes and stability improvements.
MetaTrader 4 release notes, build 1460date last opened not recorded
The newest entries are shown. Every dated change, all brokers and platforms. Follow MetaTrader 4 changes by RSS
Open source repositories for MetaTrader 4
Read from GitHub's own records and ordered by stars as read. A listing is not a recommendation.
Brokers that offer MetaTrader 4 (MQL4)
| Broker | Entity | Note | Source |
|---|---|---|---|
| Axi | Axi Financial Services (UK) Limited | Listed on Axi's UK site and platforms page, with Expert Advisors presented for automated trading. | Trading platforms, Axi UKchecked |
| Capital.com | Capital Com (UK) Limited | MT4 offered; Expert Advisors allowed ('Expert advisors execute according to rules set in advance'), with a disclaimer that Capital.com is not responsible for EA performance. | Capital.com UK MT4checked |
| CMC Markets | CMC Markets UK plc | Offered for spread betting and CFDs. The MT4 page says Expert Advisors can be used to automate trading. | CMC Markets UK MetaTrader 4checked |
| FOREX.com / StoneX Trading (City Index) | StoneX Financial Ltd (FOREX.com UK), FCA Register not read by us | MT4 on desktop, web and mobile. Expert Advisors allowed ('Expert Advisors (EAs) are programs that can be used to automate trading'); only one EA per chart; EA hosting/VPS for qualifying clients. | FOREX.com UK trading platformschecked |
| FOREX.com / StoneX Trading (City Index) | StoneX Financial Ltd trading as StoneX Trading (formerly City Index UK) | City Index UK pages now redirect to stonex.com/en-gb. MT4 offered with Expert Advisors from FX Blue (nine EAs). | StoneX Trading MetaTrader 4checked |
| FXCM | Stratos Markets Limited | MT4 on desktop, web and mobile. Expert Advisors allowed: 'Get MT4 EAs (Expert Advisors) and Virtual Private Server (VPS) with your MT4 account'. | FXCM UK MetaTrader 4checked |
| FxPro | FxPro group (UK entity not confirmed on page) | Listed on platform comparison with EA trading; page does not say which entity offers it. | UnverifiedFxPro platform comparisonchecked |
| IG | IG Markets Ltd (CFDs), IG Index Ltd (spread betting) | Offered for spread betting and CFD accounts. Expert Advisors allowed: page says you can build strategies to execute automatically using your algorithms or MT4's own, called Expert Advisors. | IG UK MetaTrader 4checked |
| OANDA | OANDA Europe Limited | MT4 offered. Expert Advisors allowed: 'The MetaTrader 4 platform supports Expert Advisors (EAs)'. | OANDA UK MetaTrader 4checked |
| Pepperstone | Pepperstone Limited | MetaTrader 4 is listed on the broker's UK platforms page for UK clients. | Pepperstone UK trading platformschecked |
| Swissquote | Swissquote Ltd (UK) | Listed on the UK private client forex and CFD platforms page, with Expert Advisors ticked in the comparison table. | Swissquote UK, forex and CFD platformschecked |
| ThinkMarkets | TF Global Markets (UK) Limited | Support article: spread betting is available on ThinkTrader, MT4 and MT5 for UK residents. | ThinkMarkets support: Spread betting accountchecked |
| Tickmill | Tickmill UK Ltd | MT4 on Windows, macOS, mobile and WebTrader. | Tickmill UKchecked |
How to cite this
MetaTrader 4 API (MQL4). Broker API Hub, https://openbrokerapi.com/platforms/metatrader-4, newest check .
Where you rely on a single figure, cite the source and the checked date printed beside it as well.