MQL4 - automated forex trading   /  

Documentation

MQL4 Reference  Trading functions  Execution errors

 
Use the opportunities of
MQL5 in MetaTrader 5
Study the new MQL5 language
Study the new MQL5 language.
Reference is already available

Any trading operation (functions of OrderSend(), OrderClose, OrderCloseBy, OrderDelete or OrderModify) can fail, for a number of reasons, and return either negative ticket number or FALSE. One can find out about the reason for fail by calling of the GetLastError() function. Every error must be processed in a special way. The most common recommendations are given below.

Error codes returned from trade server.

ConstantValueDescription
ERR_NO_ERROR0Trade operation succeeded.
ERR_NO_RESULT1OrderModify attempts to replace the values already set with the same values. One or more values must be changed, then modification attempt can be repeated.
ERR_COMMON_ERROR2Common error. All attempts to trade must be stopped until reasons are clarified. Restart of operation system and client terminal will possibly be needed.
ERR_INVALID_TRADE_PARAMETERS3Invalid parameters were passed to the trading function, for example, wrong symbol, unknown trade operation, negative slippage, non-existing ticket number, etc. The program logic must be changed.
ERR_SERVER_BUSY4Trade server is busy. The attempt can be repeated after a rather long period of time (over several minutes).
ERR_OLD_VERSION5Old version of the client terminal. The latest version of the client terminal must be installed.
ERR_NO_CONNECTION6No connection to the trade server. It is necessary to make sure that connection has not been broken (for example, using the IsConnected function) and repeat the attempt after a certain period of time (over 5 seconds).
ERR_TOO_FREQUENT_REQUESTS8Requests are too frequent. The frequency of requesting must be reduced, the program logic must be changed.
ERR_ACCOUNT_DISABLED64The account was disabled. All attempts to trade must be stopped.
ERR_INVALID_ACCOUNT65The account number is invalid. All attempts to trade must be stopped.
ERR_TRADE_TIMEOUT128Timeout for the trade has been reached. Before retry (at least, in 1-minute time), it is necessary to make sure that trading operation has not really succeeded (a new position has not been opened, or the existing order has not been modified or deleted, or the existing position has not been closed)
ERR_INVALID_PRICE129Invalid bid or ask price, perhaps, unnormalized price. After 5-second (or more) delay, it is necessary to refresh data using the RefreshRates function and make a retry. If the error does not disappear, all attempts to trade must be stopped, the program logic must be changed.
ERR_INVALID_STOPS130Stops are too close, or prices are ill-calculated or unnormalized (or in the open price of a pending order). The attempt can be repeated only if the error occurred due to the price obsolescense. After 5-second (or more) delay, it is necessary to refresh data using the RefreshRates function and make a retry. If the error does not disappear, all attempts to trade must be stopped, the program logic must be changed.
ERR_INVALID_TRADE_VOLUME131Invalid trade volume, error in the volume granularity. All attempts to trade must be stopped, and the program logic must be changed.
ERR_MARKET_CLOSED132Market is closed. The attempt can be repeated after a rather long period of time (over several minutes).
ERR_TRADE_DISABLED133Trade is disabled. All attempts to trade must be stopped.
ERR_NOT_ENOUGH_MONEY134Not enough money to make an operation. The trade with the same parameters must not be repeated. After 5-second (or more) delay, the attempt can be repeated with a smaller volume, but it is necessary to make sure that there is enough money to complete the operation.
ERR_PRICE_CHANGED135The price has changed. The data can be refreshed without any delay using the RefreshRates function and make a retry.
ERR_OFF_QUOTES136No quotes. The broker has not supplied with prices or refused, for any reason (for example, no prices at the session start, unconfirmed prices, fast market). After 5-second (or more) delay, it is necessary to refresh data using the RefreshRates function and make a retry.
ERR_REQUOTE138The requested price has become out of date or bid and ask prices have been mixed up. The data can be refreshed without any delay using the RefreshRates function and make a retry. If the error does not disappear, all attempts to trade must be stopped, the program logic must be changed.
ERR_ORDER_LOCKED139The order has been locked and under processing. All attempts to make trading operations must be stopped, and the program logic must be changed.
ERR_LONG_POSITIONS_ONLY_ALLOWED140Only buying operation is allowed. The SELL operation must not be repeated.
ERR_TOO_MANY_REQUESTS141Too many requests. The frequency of requesting must be reduced, the program logic must be changed.
 142The order has been enqueued. It is not an error but an interaction code between the client terminal and the trade server. This code can be got rarely, when the disconnection and the reconnection happen during the execution of a trade operation. This code should be processed in the same way as error 128.
 143The order was accepted by the dealer for execution. It is an interaction code between the client terminal and the trade server. It can appear for the same reason as code 142. This code should be processed in the same way as error 128.
 144The order was discarded by the client during manual confirmation. It is an interaction code between the client terminal and the trade server.
ERR_TRADE_MODIFY_DENIED145Modifying has been denied since the order is too close to market and locked for possible soon execution. The data can be refreshed after more than 15 seconds using the RefreshRates function, and a retry can be made.
ERR_TRADE_CONTEXT_BUSY146The trade thread is busy. Retry only after the IsTradeContextBusy function has returned FALSE.
ERR_TRADE_EXPIRATION_DENIED147The use of pending order expiration date has been denied by the broker. The operation can only be repeated if the expiration parameter has been zeroized.
ERR_TRADE_TOO_MANY_ORDERS148The amount of open and pending orders has reached the limit set by the broker. New open positions and pending orders can be placed only after the existing positions or orders have been closed or deleted.
ERR_TRADE_HEDGE_PROHIBITED149An attempt to open a position opposite to the existing one when hedging is disabled. First the existing opposite position should be closed, all attempts of such trade operations must be stopped, or the program logic must be changed.
ERR_TRADE_PROHIBITED_BY_FIFO150An attempt to close a symbol position contravening the FIFO rule. First earlier existing position(s) should be closed, all attempts of such trade operations must be stopped, or the program logic must be changed.