Loading…

Order Error Code Explorer

GetLastError() returns a number. Nothing in the terminal turns that number into "what do I do about this," and MetaQuotes' own reference documentation is one page per constant, which is a lot of clicking when a script keeps failing and the only question is whether that means "give up" or "just retry." This is that lookup, done once and kept local. On MQL4, roughly forty of the codes that actually turn up in day-to-day work - the trade server codes in the 0-150 range, plus the runtime faults in the 4000s that beginners generate by indexing an empty array or dividing by a stale MarketInfo() value - are listed with the constant name, what the code means in plain terms, and the fix that applies most of the time. MQL5 moved this whole layer. A broker's accept-or-reject verdict on a trade request no longer comes back through GetLastError() - it arrives as the retcode field of a trade result (MqlTradeResult, or CTrade::ResultRetcode() when using the standard trade class), using the TRADE_RETCODE_* enumeration. GetLastError() on MQL5 mostly only confirms that the terminal-side API call itself fired, not what the broker decided. Porting the MQL4 table's numbers across would therefore silently describe the wrong thing, so the MQL5 submission is a genuine rewrite: a full table of TRADE_RETCODE_* values, covering the same ground - which codes are worth a retry, which mean stop and check something, and what the usual fix is. Both tables deliberately avoid trying to be exhaustive. Padding either one with obscure codes nobody looks up twice would make the codes someone actually needs harder to find, not easier. Notes and limitations - Each table covers the codes chosen for how often they actually appear, not every constant either platform defines. A code not found here may still exist and be documented by MetaQuotes; this script just does not repeat what the official reference already tells you. - "Fix" is the usual cause and remedy, not a guarantee - the same code can occasionally have a different root cause on a specific broker. - Retryable and non-retryable are not labelled as a separate column but are described in the fix text for each code; codes like requotes and busy servers are worth a retry loop, codes like invalid stops are not.

Script · MT4 · v1.0 · Free

About Order Error Code Explorer

Order Error Code Explorer is a script for MetaTrader 4. It can alert you with a pop-up, sound, email or push message. It has 3 settings, such as Lookup code, Write csv report and Csv delimiter. MQL source code included.

Files in the download: OrderErrorCodeExplorer.ex4, OrderErrorCodeExplorer.mq4, OrderErrorCodeExplorer.txt.

Settings

SettingDefaultWhat it does
Lookup code0Show just this code (0 = print the whole table)
Write csv reporttrueAlso write the table to MQL4\Files as CSV
Csv delimiter,Delimiter for the CSV report

How to install

  1. Download the ZIP from your PolyMaria library and unzip it.
  2. In MetaTrader 4 open File → Open Data Folder, then go to MQL4 → Scripts.
  3. Copy the .mq4 file(s) there. Put any .mqh files in MQL4 → Include.
  4. Open the .mq4 file in MetaEditor and press Compile (F7) if MetaTrader does not show it.
  5. Drag the script onto a chart to run it once.

Download the PDF guide

Tags: Alerts · MT4 Script · MQL4 Source Code

MQL4 & MQL5 scripts · PolyMaria