Skip to content

Free reference

MQL5 error codes and trade retcodes

What a MetaTrader 5 trade server return code or runtime error means, the situations that cause it, and MQL5 code that handles it. Search by number, by the MQL4 number it replaces, or by words.

Trade server return codes

Trade server return codes arrive in MqlTradeResult.retcode after OrderSend() or OrderCheck(). 20 codes.

Runtime errors

Runtime errors arrive from GetLastError() after a function fails. 10 codes.

Reading a failed trade

  1. OrderSend() returning false, or GetLastError() = 4756, only says the request failed. The reason is the server's return code in result.retcode, with result.comment.
  2. Log both, with the symbol, volume, price and stops of the request, before anything else.
  3. Run OrderCheck() before sending: it reports many of these codes without touching the server, but not all of them (a closed market passes the check).

MQL4 numbers

MQL4 reported trade problems as small numbers (130 invalid stops, 131 invalid volume, 134 not enough money). MQL5 uses the 10004–10046 return codes instead; each entry names the MQL4 number it replaces, and the search finds it. Some numbers mean different things in the two languages (4108, 4109): their pages explain both.

Every entry is written from the official MQL5 and MQL4 reference, which each page links. To check a whole EA for these mistakes, paste it into the EA Doctor.

Get your EA fixed

An EA that keeps failing with one of these codes? We find the cause in the code and fix it.