Order-send error handling in MQL5: the cases I handle explicitly
Posted: Thu Oct 29, 2026 9:30 am
After a few incidents with an EA silently failing to place orders, I rewrote the error handling. Here are the return codes I treat individually and what the EA does for each.
Also: every request and result goes to a log file with a timestamp, not just the journal.
What error cases have caught you out? Anyone handling the timeout scenario differently?
- TRADE_RETCODE_REQUOTE / PRICE_OFF: refresh prices, retry up to 2 times with a short pause. If still failing, skip the signal.
- TRADE_RETCODE_INVALID_STOPS: recalculate stops respecting the stops level, retry once. Log the original and corrected values.
- TRADE_RETCODE_INVALID_VOLUME: normalise to volume step, check min/max, retry once.
- TRADE_RETCODE_NO_MONEY: no retry. Alert immediately; that means something is wrong with sizing.
- TRADE_RETCODE_MARKET_CLOSED: stop trading for that symbol until the next session.
- TRADE_RETCODE_TIMEOUT / connection errors: don't retry blindly. Check open positions first so you don't open a duplicate.
- Anything else: log the full request and result, no retry, alert.
Also: every request and result goes to a log file with a timestamp, not just the journal.
What error cases have caught you out? Anyone handling the timeout scenario differently?