Developers

MetaTrader error codes for MT4 and MT5

107 codes from MT5 trade results, MQL4 and MQL5 runtime errors and the MT5 Python package. Each page says what the code means, the usual causes, how to fix it, whether a retry is safe and whether the order may have gone through.

The most dangerous answers are the unclear ones, such as MT5 10031 or MT4 128. The order may have executed even though the call failed. Check positions, orders and history before you send it again. See idempotency for how Tickwire handles them.

MT5 trade return codes

The retcode in the result of OrderSend() in MQL5, or of order_send() in Python. 10008, 10009 and 10010 are success codes; the rest say why a request didn't go through.

CodeMeaningRetry?Executed?
10004 Requote TRADE_RETCODE_REQUOTE Yes No
10006 Request rejected TRADE_RETCODE_REJECT After a fix No
10007 Request canceled by trader TRADE_RETCODE_CANCEL Yes No
10008 Order placed TRADE_RETCODE_PLACED No Yes
10009 Request completed TRADE_RETCODE_DONE No Yes
10010 Only part of the request was completed TRADE_RETCODE_DONE_PARTIAL Check first Partly
10011 Request processing error TRADE_RETCODE_ERROR Check first Maybe
10012 Request canceled by timeout TRADE_RETCODE_TIMEOUT Check first Maybe
10013 Invalid request TRADE_RETCODE_INVALID After a fix No
10014 Invalid volume TRADE_RETCODE_INVALID_VOLUME After a fix No
10015 Invalid price TRADE_RETCODE_INVALID_PRICE After a fix No
10016 Invalid stops TRADE_RETCODE_INVALID_STOPS After a fix No
10017 Trade is disabled TRADE_RETCODE_TRADE_DISABLED No No
10018 Market is closed TRADE_RETCODE_MARKET_CLOSED Yes, after a wait No
10019 Not enough money TRADE_RETCODE_NO_MONEY After a fix No
10020 Prices changed TRADE_RETCODE_PRICE_CHANGED Yes No
10021 No quotes to process the request TRADE_RETCODE_PRICE_OFF Yes, after a wait No
10022 Invalid expiration TRADE_RETCODE_INVALID_EXPIRATION After a fix No
10023 Order state changed TRADE_RETCODE_ORDER_CHANGED Check first Maybe
10024 Too frequent requests TRADE_RETCODE_TOO_MANY_REQUESTS Yes, after a wait No
10025 No changes in request TRADE_RETCODE_NO_CHANGES No Not a trade
10026 Autotrading disabled by server TRADE_RETCODE_SERVER_DISABLES_AT No No
10027 Autotrading disabled by client terminal TRADE_RETCODE_CLIENT_DISABLES_AT After a fix No
10028 Request locked for processing TRADE_RETCODE_LOCKED Check first Maybe
10029 Order or position frozen TRADE_RETCODE_FROZEN Yes, after a wait No
10030 Invalid order filling type TRADE_RETCODE_INVALID_FILL After a fix No
10031 No connection with the trade server TRADE_RETCODE_CONNECTION Check first Maybe
10032 Operation allowed only for real accounts TRADE_RETCODE_ONLY_REAL No No
10033 Pending orders limit reached TRADE_RETCODE_LIMIT_ORDERS After a fix No
10034 Volume limit for the symbol reached TRADE_RETCODE_LIMIT_VOLUME After a fix No
10035 Incorrect or prohibited order type TRADE_RETCODE_INVALID_ORDER After a fix No
10036 Position already closed TRADE_RETCODE_POSITION_CLOSED No Not a trade
10038 Close volume exceeds the position TRADE_RETCODE_INVALID_CLOSE_VOLUME After a fix No
10039 A close order already exists TRADE_RETCODE_CLOSE_ORDER_EXIST Check first Maybe
10040 Open positions limit reached TRADE_RETCODE_LIMIT_POSITIONS After a fix No
10041 Pending order activation rejected, order canceled TRADE_RETCODE_REJECT_CANCEL After a fix No
10042 Only long positions are allowed TRADE_RETCODE_LONG_ONLY No No
10043 Only short positions are allowed TRADE_RETCODE_SHORT_ONLY No No
10044 Only position closing is allowed TRADE_RETCODE_CLOSE_ONLY No No
10045 Closing allowed only by FIFO rule TRADE_RETCODE_FIFO_CLOSE After a fix No
10046 Hedging prohibited TRADE_RETCODE_HEDGE_PROHIBITED After a fix No

MT5 runtime errors

What GetLastError() returns in MQL5 after a function fails. These are the ones trading code meets most often.

CodeMeaningRetry?Executed?
4014 Function is not allowed for call ERR_FUNCTION_NOT_ALLOWED After a fix Not a trade
4301 Unknown symbol ERR_MARKET_UNKNOWN_SYMBOL After a fix No
4302 Symbol is not selected in Market Watch ERR_MARKET_NOT_SELECTED After a fix No
4401 Requested history not found ERR_HISTORY_NOT_FOUND Yes, after a wait Not a trade
4751 Wrong trade property identifier ERR_TRADE_WRONG_PROPERTY After a fix Not a trade
4752 Automated trading is not allowed for the program ERR_TRADE_DISABLED After a fix No
4753 Position not found ERR_TRADE_POSITION_NOT_FOUND No No
4754 Order not found ERR_TRADE_ORDER_NOT_FOUND No Maybe
4755 Deal not found ERR_TRADE_DEAL_NOT_FOUND After a fix Not a trade
4756 Trade request sending failed ERR_TRADE_SEND_FAILED Check first Maybe
4758 Failed to calculate profit or margin ERR_TRADE_CALC_FAILED Yes, after a wait Not a trade

MT5 Python package errors

What mt5.last_error() returns in the MetaTrader5 Python package when a call fails, such as initialize() or login().

CodeMeaningRetry?Executed?
-1 Generic failure RES_E_FAIL Check first Maybe
-2 Invalid parameters RES_E_INVALID_PARAMS After a fix No
-3 Out of memory RES_E_NO_MEMORY After a fix Not a trade
-4 Not found RES_E_NOT_FOUND Yes, after a wait Not a trade
-5 Invalid version RES_E_INVALID_VERSION After a fix Not a trade
-6 Authorization failed RES_E_AUTH_FAILED After a fix Not a trade
-7 Unsupported method RES_E_UNSUPPORTED No Not a trade
-8 Auto-trading disabled RES_E_AUTO_TRADING_DISABLED After a fix No
-10000 IPC internal error RES_E_INTERNAL_FAIL Yes, after a wait Maybe
-10001 IPC send failed RES_E_INTERNAL_FAIL_SEND Check first Maybe
-10002 IPC receive failed RES_E_INTERNAL_FAIL_RECEIVE Check first Maybe
-10003 IPC initialize failed RES_E_INTERNAL_FAIL_INIT After a fix Not a trade
-10004 No IPC connection RES_E_INTERNAL_FAIL_CONNECT After a fix No
-10005 IPC timeout RES_E_INTERNAL_FAIL_TIMEOUT Check first Maybe

MT4 trade server errors

What GetLastError() returns in MQL4 after OrderSend(), OrderModify(), OrderClose() or OrderDelete() fails on the server side.

CodeMeaningRetry?Executed?
1 No error returned, but the result is unknown ERR_NO_RESULT Check first Maybe
2 Common error ERR_COMMON_ERROR Check first Maybe
3 Invalid trade parameters ERR_INVALID_TRADE_PARAMETERS After a fix No
4 Trade server is busy ERR_SERVER_BUSY Yes, after a wait No
5 Old version of the client terminal ERR_OLD_VERSION No No
6 No connection with trade server ERR_NO_CONNECTION Check first Maybe
7 Not enough rights ERR_NOT_ENOUGH_RIGHTS No No
8 Too frequent requests ERR_TOO_FREQUENT_REQUESTS Yes, after a wait No
9 Malfunctional trade operation ERR_MALFUNCTIONAL_TRADE After a fix No
64 Account disabled ERR_ACCOUNT_DISABLED No No
65 Invalid account ERR_INVALID_ACCOUNT No No
128 Trade timeout ERR_TRADE_TIMEOUT Check first Maybe
129 Invalid price ERR_INVALID_PRICE After a fix No
130 Invalid stops ERR_INVALID_STOPS After a fix No
131 Invalid trade volume ERR_INVALID_TRADE_VOLUME After a fix No
132 Market is closed ERR_MARKET_CLOSED Yes, after a wait No
133 Trade is disabled ERR_TRADE_DISABLED No No
134 Not enough money ERR_NOT_ENOUGH_MONEY After a fix No
135 Price changed ERR_PRICE_CHANGED Yes No
136 Off quotes ERR_OFF_QUOTES Yes, after a wait No
137 Broker is busy ERR_BROKER_BUSY Yes, after a wait No
138 Requote ERR_REQUOTE Yes No
139 Order is locked ERR_ORDER_LOCKED Check first Maybe
140 Long positions only allowed ERR_LONG_POSITIONS_ONLY_ALLOWED No No
141 Too many requests ERR_TOO_MANY_REQUESTS Yes, after a wait No
145 Modification denied because order is too close to market ERR_TRADE_MODIFY_DENIED Yes, after a wait No
146 Trade context is busy ERR_TRADE_CONTEXT_BUSY Yes, after a wait No
147 Expirations are denied by broker ERR_TRADE_EXPIRATION_DENIED After a fix No
148 Too many open and pending orders ERR_TRADE_TOO_MANY_ORDERS After a fix No
149 Hedging is prohibited ERR_TRADE_HEDGE_PROHIBITED After a fix No
150 Prohibited by FIFO rules ERR_TRADE_PROHIBITED_BY_FIFO After a fix No

MT4 runtime errors

MQL4 runtime errors raised inside the terminal, before or instead of a server answer.

CodeMeaningRetry?Executed?
4051 Invalid function parameter value ERR_INVALID_FUNCTION_PARAMVALUE After a fix No
4105 No order selected ERR_NO_ORDER_SELECTED After a fix No
4106 Unknown symbol ERR_UNKNOWN_SYMBOL After a fix No
4107 Invalid price parameter for trade function ERR_INVALID_PRICE_PARAM After a fix No
4108 Invalid ticket ERR_INVALID_TICKET After a fix No
4109 Trade is not allowed ERR_TRADE_NOT_ALLOWED After a fix No
4110 Longs are not allowed ERR_LONGS_NOT_ALLOWED After a fix No
4111 Shorts are not allowed ERR_SHORTS_NOT_ALLOWED After a fix No
4112 Automated trading disabled by trade server ERR_TRADE_EXPERT_DISABLED_BY_SERVER No No
4200 Object already exists ERR_OBJECT_ALREADY_EXISTS After a fix Not a trade

Tickwire answers with the same MT5 style codes on both platforms, so one handler covers MT4 and MT5. The full list of Tickwire's own error codes is in the error reference.