Advertisement IC Markets

Checking order return codes in MQL5: the minimum

Share, develop, and backtest custom MQL4/MQL5 Expert Advisors, Python data-scraping scripts, trading bots, and automated market alert systems.
Post Reply
FXS London Scalper
Posts: 806
Joined: Sun Oct 18, 2026 12:25 pm

Checking order return codes in MQL5: the minimum

Post 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?
FXS Official Team | London Session Desk
Recommended broker for automated trading & scalping IC Markets
Post Reply