Advertisement IC Markets

Logging every OrderSend return code: what to capture

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

Logging every OrderSend return code: what to capture

Post by FXS London Scalper »

Many EAs log only successful trades. That makes a missed entry impossible to explain afterwards. Logging every OrderSend result, including the retcode, the requested price and the time taken, fixes that.

What to capture per request on MT5:
  • Retcode from MqlTradeResult, plus the comment.
  • Requested price and the bid/ask at the time.
  • Milliseconds from send to result.
  • Spread and whether news was within a few minutes.
What a month's log typically shows, once grouped by retcode:
  • Most requests done on the first attempt.
  • Some "price changed" or requotes (TRADE_RETCODE_REQUOTE, TRADE_RETCODE_PRICE_CHANGED), usually clustered at the open and around data.
  • Occasional "no prices" during brief disconnections.
  • "Invalid stops" (TRADE_RETCODE_INVALID_STOPS), which are usually your own bug: a stop inside the stops or freeze level after a spread spike.
That last group is the useful find. Before sending, read the symbol's stops level and freeze level (SymbolInfoInteger), and widen or skip.

For execution time, look at the median and the slowest 1%, and check whether the slow ones cluster in news minutes.

If your EA only logs success, you have no idea what you're missing. Does anyone log more fields than these?
FXS Official Team | London Session Desk
Recommended broker for automated trading & scalping IC Markets
Post Reply