Advertisement IC Markets

What I make my EA write to the log, and how it changed how I debug

Share, develop, and backtest custom MQL4/MQL5 Expert Advisors, Python data-scraping scripts, trading bots, and automated market alert systems.
Post Reply
Fairman
Posts: 6822
Joined: Tue Jul 21, 2026 7:11 am
Location: Abuja

What I make my EA write to the log, and how it changed how I debug

Post by Fairman »

What I make my EA write to the log, and how it changed how I debug

early on my EA logged almost nothing, and when something went wrong I was guessing. Now I log in a structured way, and it's changed how fast I can find problems.

For every signal, it writes the time, the symbol, the values that went into the decision and whether it traded or skipped. For skipped trades, it writes the reason, like spread too high, news filter, outside session, or max trades reached. For orders it logs the requested price, the fill price, the spread at the time and the response from the server.

When I look at a bad trade, I can see exactly what the EA saw and why it acted. The skipped reasons have been useful too, because if one filter is blocking most signals it's clear in the log.

I keep it readable by using a consistent line format. I can export the log and paste it into a spreadsheet to count things like the average slippage per session. It takes a bit of effort to write but pays off the first time something strange happens.
It’s Fairman :geek:
Recommended broker for automated trading & scalping IC Markets
Fairman
Posts: 6822
Joined: Tue Jul 21, 2026 7:11 am
Location: Abuja

Re: What I make my EA write to the log, and how it changed how I debug

Post by Fairman »

An example of the line format I use, roughly: date and time, symbol, event type, then a few key values separated by semicolons. Event types are things like signal, skip, order, fill, modify and close. Keeping it to a fixed order means I can split the file into columns in a spreadsheet without any cleanup. I also add the magic number at the start of each line, so if more than one EA writes to the same log I can filter them apart easily.
It’s Fairman :geek:
Fairman
Posts: 6822
Joined: Tue Jul 21, 2026 7:11 am
Location: Abuja

Re: What I make my EA write to the log, and how it changed how I debug

Post by Fairman »

One thing I learned is not to log every tick. My first attempt wrote a line on every price change and the files grew huge and were impossible to read. Now the EA only logs when something happens: a new bar with a signal check, an order, a change to a trade, or a skip with a reason. That keeps the log small enough to scroll through and still captures everything I need when something odd shows up. Less noise in the file means I actually read it.
It’s Fairman :geek:
Shadow Trader
Posts: 5438
Joined: Wed Sep 09, 2026 5:19 pm

Re: What I make my EA write to the log, and how it changed how I debug

Post by Shadow Trader »

Two fields that earn their place are the EA version and the input settings, written once when it starts. Without them, a month of log lines can mix two parameter sets after a quiet update, and the averages blend two different systems.

Timing is the other one. Writing the server time of the signal and the time of the fill on the order line lets you measure the delay, and if London open orders show 1,400 milliseconds between the two while quiet hours show 150, that gap explains a good part of the slippage column.

Short fixed codes for skip reasons help the spreadsheet side as well. A code like SPRD or NEWS sorts and counts cleanly, while free text tends to drift into several spellings that end up as separate rows in a pivot table.

One edge case is buffering when writing to a file. If the terminal or the VPS restarts, lines still sitting in the buffer are lost, and they are usually the lines around the problem, so flushing after each order event is worth the small cost.

Do you start a new file each day or keep one running file? Daily files make it easy to match a bad session to its log, though a month of review then starts with joining thirty files.
Shadow Trader
Posts: 5438
Joined: Wed Sep 09, 2026 5:19 pm

Re: What I make my EA write to the log, and how it changed how I debug

Post by Shadow Trader »

Logging the path of each trade, not just its ends, is the addition that tends to pay off fastest. On the close line, the EA can write the maximum favourable and maximum adverse excursion in pips, plus the reason it closed.

Those two excursion numbers answer questions the fills cannot. Say a run of 50 trades with a 6 pip stop shows 14 losers that were at least 6 pips in profit before turning, then the exit logic is leaking more than the entries.

The adverse side is just as telling. If most winners never went more than 2 pips against the entry, a 6 pip stop may be wider than the setup needs, though that deserves a proper test before anything changes.

Tracking excursion means updating a high and low for each open ticket on every tick, but writing them only once at the close. The file stays small while still capturing the whole path.

A running sequence number at the start of each line is a cheap extra. If line 4,812 is followed by 4,815, something was lost, and it points straight at the restart or crash that caused it.
FXS Prop Desk
Posts: 1589
Joined: Wed Oct 07, 2026 9:52 am

Re: What I make my EA write to the log, and how it changed how I debug

Post by FXS Prop Desk »

Structured logging changes everything in debugging. Logging the reason for skipped trades is especially valuable, because most problems with EAs are not wrong trades but missing ones.

One more addition: log the spread and the account equity at each signal. When something goes wrong, those two values often explain it. A wide spread or a low equity can block a trade or change the lot size, and without the log it is hard to see why the EA behaved differently than expected.
FXS Official Team | The Idea Lab & Strategy
gwhitlock64
Posts: 50
Joined: Tue Oct 20, 2026 11:01 pm

Re: What I make my EA write to the log, and how it changed how I debug

Post by gwhitlock64 »

FXS Prop Desk wrote:One more addition: log the spread and the account equity at each signal.
FXS Prop Desk, how often has equity actually been the culprit for you, mate, rather than spread?
Shadow Trader
Posts: 5438
Joined: Wed Sep 09, 2026 5:19 pm

Re: What I make my EA write to the log, and how it changed how I debug

Post by Shadow Trader »

AI assistants can write code for trading platforms, and many people use them to build first drafts of expert advisors. The results are mixed, and the failure modes are specific.

What AI does well: boilerplate, syntax, explaining unfamiliar functions, converting an idea described in plain language into working code, and helping to debug error messages.

Where it stumbles: platform-specific quirks like digit handling and order functions, subtle logic errors that compile fine and behave badly, assumptions about execution that don't match real brokers, and overconfident claims that a strategy "will be profitable". It can also produce code that looks right but hides lookahead bias in indicator calculations.

The sensible approach treats AI output as a draft from a junior colleague. Review every line. Test on demo with logging. Check order handling against the broker's rules. Compare results with a manual calculation.

And no code, however well written, creates an edge. That part still has to come from research.

How has AI helped or misled while building trading tools?
FXS Prop Desk
Posts: 1589
Joined: Wed Oct 07, 2026 9:52 am

Re: What I make my EA write to the log, and how it changed how I debug

Post by FXS Prop Desk »

gwhitlock64 wrote: how often has equity actually been the culprit for you, mate, rather than spread?
Spread is the usual culprit, no question. Equity earns its line for a different reason: it explains the odd ones. An EA that sizes off equity or free margin will open a smaller lot after a drawdown, or skip the signal entirely if another position is using the margin, and without the equity figure next to the signal that looks like a bug. So it rarely explains a bad trade, but it often answers "why 0.03 instead of 0.10" or "why didn't it take that one".
FXS Official Team | The Idea Lab & Strategy
gwhitlock64
Posts: 50
Joined: Tue Oct 20, 2026 11:01 pm

Re: What I make my EA write to the log, and how it changed how I debug

Post by gwhitlock64 »

FXS Prop Desk wrote:Spread is the usual culprit, no question. Equity earns its line for a different reason: it explains the odd ones.
That makes sense, ta - margin getting eaten by another open position is a proper sneaky one to spot without the log, you'd just think the EA had gone wrong. Had similar with mine, lot size dropped to near nothing after a rough week and I was scratching my head for ages before I thought to check equity against the signal line.
Post Reply