Page 1 of 1

Checking order return codes in MQL5: the minimum

Posted: Sat Oct 31, 2026 12:27 pm
by FXS London Scalper
A surprising number of EAs send orders without checking whether they worked. In MQL5 the information is all there; it just needs to be read.

The minimum:
  • Check the return value of OrderSend. False means the request didn't reach the server or failed a local check.
  • Read the result structure's retcode. TRADE_RETCODE_DONE means filled; anything else needs handling.
  • Log the retcode with a short description, the requested price and, if filled, the fill price.
Common codes worth handling:
  • Requote and price changed: retry once with a fresh price, or skip.
  • Invalid stops: the stop is too close; check stop level and recalculate.
  • Market closed: stop trying until the session reopens.
  • No money: reduce size or stop; never loop.
The worst pattern is a loop that retries forever. Limit retries to one or two, with a short pause, and then log and give up.

A simple test: on demo, deliberately send an order with a stop inside the stop level and check that the EA logs and handles it.

These basics matter more than clever entry logic, because a silent failure can leave the account exposed without anyone noticing.

Which return codes caused you trouble?