Handling requotes and order errors gracefully in MQL5
Posted: Mon Nov 02, 2026 12:33 pm
Orders can fail for many reasons: requotes, invalid stops, insufficient margin, market closed. An EA that does not handle errors may retry endlessly, skip trades silently, or open duplicates.
A robust approach is to check the return code of every trade request and handle the main categories explicitly. For temporary issues such as requotes or busy servers, a limited number of retries with a short pause is reasonable. For permanent issues such as invalid stops, log the problem and stop retrying.
A worked example of a duplicate bug: an EA sends an order, the connection drops before confirmation, and the EA sends it again on reconnect. Checking open positions by magic number before sending prevents this.
It is also wise to verify stop distances against the broker's minimum stop level before sending, since this varies by broker and can change around news.
Testing error handling on demo by deliberately sending invalid orders helps confirm the logic works.
Which order errors have caused you the most trouble?
A robust approach is to check the return code of every trade request and handle the main categories explicitly. For temporary issues such as requotes or busy servers, a limited number of retries with a short pause is reasonable. For permanent issues such as invalid stops, log the problem and stop retrying.
A worked example of a duplicate bug: an EA sends an order, the connection drops before confirmation, and the EA sends it again on reconnect. Checking open positions by magic number before sending prevents this.
It is also wise to verify stop distances against the broker's minimum stop level before sending, since this varies by broker and can change around news.
Testing error handling on demo by deliberately sending invalid orders helps confirm the logic works.
Which order errors have caused you the most trouble?