How to handle trading errors - mql4

 

I noticed that this is no longer present in the current mql4 documentation so I though I would add the "old" documentation here for future reference . . .

Constant Value Description
ERR_NO_ERROR 0 Trade operation succeeded.
ERR_NO_RESULT 1 OrderModify 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_ERROR 2 Common 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_PARAMETERS 3 Invalid 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_BUSY 4 Trade server is busy. The attempt can be repeated after a rather long period of time (over several minutes).
ERR_OLD_VERSION 5 Old version of the client terminal. The latest version of the client terminal must be installed.
ERR_NO_CONNECTION 6 No 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_REQUESTS 8 Requests are too frequent. The frequency of requesting must be reduced, the program logic must be changed.
ERR_ACCOUNT_DISABLED 64 The account was disabled. All attempts to trade must be stopped.
ERR_INVALID_ACCOUNT 65 The account number is invalid. All attempts to trade must be stopped.
ERR_TRADE_TIMEOUT 128 Timeout 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_PRICE 129 Invalid 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_STOPS 130 Stops 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 obsolescence. 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_VOLUME 131 Invalid trade volume, error in the volume granularity. All attempts to trade must be stopped, and the program logic must be changed.
ERR_MARKET_CLOSED 132 Market is closed. The attempt can be repeated after a rather long period of time (over several minutes).
ERR_TRADE_DISABLED 133 Trade is disabled. All attempts to trade must be stopped.
ERR_NOT_ENOUGH_MONEY 134 Not 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_CHANGED 135 The price has changed. The data can be refreshed without any delay using the RefreshRates function and make a retry.
ERR_OFF_QUOTES 136 No 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_REQUOTE 138 The 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_LOCKED 139 The 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_ALLOWED 140 Only buying operation is allowed. The SELL operation must not be repeated.
ERR_TOO_MANY_REQUESTS 141 Too many requests. The frequency of requesting must be reduced, the program logic must be changed.
142 The 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.
143 The 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.
144 The 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_DENIED 145 Modifying 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_BUSY 146 The trade thread is busy. Retry only after the IsTradeContextBusy function has returned FALSE.
ERR_TRADE_EXPIRATION_DENIED 147 The 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_ORDERS 148 The 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_PROHIBITED 149 An 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_FIFO 150 An 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.
 

Yep, but the critical part, IMO, is missing . . . for example, error 130 . .

Stops 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 RefreshRatesfunction and make a retry. If the error does not disappear, all attempts to trade must be stopped, the program logic must be changed.


I'll go through a little later and fix the broken links.

 
RaptorUK:

Yep, but the critical part, IMO, is missing . . . for example, error 130 . .


I'll go through a little later and fix the broken links.

Yes that's right, a lot less explanations about these errors.
 


Yes, but you would have thought that the documentation re GetLastError() would have a link to the error codes, but the link only details codes of 4000+

Unbelieveably typing "error codes" into the documentation search does not take you to the list of error codes

 
RaptorUK:

Yep, but the critical part, IMO, is missing . . . for example, error 130 . .


I'll go through a little later and fix the broken links.

Fixed.
 
GumRai:


Yes, but you would have thought that the documentation re GetLastError() would have a link to the error codes, but the link only details codes of 4000+

Unbelieveably typing "error codes" into the documentation search does not take you to the list of error codes

Try symply with "errors" : https://www.mql4.com/search#!keyword=errors&module=mql4_module_docs
 
RaptorUK:

I noticed that this is no longer present in the current mql4 documentation so I though I would add the "old" documentation here for future reference . . .

Trade Server Return Codes https://docs.mql4.com/en/constants/errorswarnings/enum_trade_return_codes
 

RaptorUK:

Yep, but the critical part, IMO, is missing . . . for example, error 130 . .

Stops 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 RefreshRatesfunction and make a retry. If the error does not disappear, all attempts to trade must be stopped, the program logic must be changed.

 
Got it, not the code but the text.
 
WHRoeder:
Got it, not the code but the text.
Did you read the topic before posting ?