Checking order return codes in MQL5: the minimum
Posted: Sat Oct 31, 2026 12:27 pm
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:
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?
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.
- 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.
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?