Advertisement IC Markets

Logging every order decision inside an EA

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: 975
Joined: Sun Oct 18, 2026 12:25 pm

Logging every order decision inside an EA

Post by FXS London Scalper »

An expert advisor that only logs filled trades makes debugging hard. When it fails to open a trade, nobody knows why. A better habit is to log every decision point: signal checked, conditions met or not, order sent, broker response.

A practical structure is one log line per bar with key values: indicator readings, spread at the time, whether filters passed, and the final action. Writing to a CSV file makes it easy to analyse later in a spreadsheet.

A worked example: an EA that should trade a breakout misses several signals. The log reveals that spread exceeded the maximum allowed at those moments. Without the log, the cause would be guesswork.

Logging adds some overhead, so on very fast strategies it may be worth logging only on signal bars. File size should also be managed, for example by starting a new file each day.

When sharing logs on the forum for help, remove account numbers and any personal information.

What do you include in your EA logs?
FXS Official Team | London Session Desk
Recommended broker for automated trading & scalping IC Markets
Shadow Trader
Posts: 5594
Joined: Wed Sep 09, 2026 5:19 pm

Re: Logging every order decision inside an EA

Post by Shadow Trader »

Strongly agree with logging decisions rather than just fills. The example of missed breakouts caused by the spread filter is exactly the sort of thing that would otherwise be put down to bad luck, or worse, lead someone to change the entry logic when the real cause was the filter.

A few things that make these logs easier to use later:

Use a consistent reason code for each "no trade" outcome, rather than free text. Something like SPREAD, TIME, TREND, NEWS, MAXPOS. Then a simple count in a spreadsheet shows which filter blocks the most signals, and you can check whether those blocked signals would have been winners.

Log the broker's return code and the requested versus filled price for every order. That way slippage and rejections are measured from the EA's own records, not from memory or the terminal history.

Write the log in UTC with the bar's time as well as the system time. If there's ever a question about whether a signal was processed late, having both makes it obvious.

On the overhead point, writing to a file on every tick can slow things down on very fast strategies, but logging once per bar, plus a line for every order event, is usually cheap. Buffering the lines and writing them every few seconds is another way to keep the cost down.

It's also worth rotating the files, by day or by week, so they don't grow into something too big to open. A year of per-bar logs on a few pairs can get large quickly.
Amanhasnoname
Posts: 2060
Joined: Fri Oct 30, 2026 9:45 am

Re: Logging every order decision inside an EA

Post by Amanhasnoname »

Logging the decision rather than the outcome is what turns an EA from a black box into something you can actually debug. One thing that helps a lot is giving every signal a unique id at the moment it is evaluated, then carrying that id through the order request, the broker response, any modification and the eventual close. When you later join the rows in a spreadsheet, you can follow one idea from start to finish instead of guessing which order belonged to which signal.

It is also worth recording the state the EA believed it was in, such as open positions, pending orders and the daily loss counter, not only the market values. Many strange bugs come from the EA thinking a trade is still open after it was closed manually or by a stop, and a log of its own internal view makes that mismatch obvious.

On the practical side, write the header with column names and a version number of the EA at the top of each file, so logs from different builds are never mixed up. Flush the file regularly, because a terminal crash can otherwise lose the last few minutes, which is often exactly the part you need to see.
Post Reply