Good logs make it possible to understand what an EA did and why. Many problems only show up in logs.
What to log:
Signal time and price, plus indicator values.
Order send time and requested price.
Fill time and price, slippage.
Spread at signal and at fill.
Errors and retries.
Exit reason.
Format:
CSV for analysis.
Text logs for debugging.
Unique IDs linking signal, order and fill.
Comparing logs from live trading and backtests shows where execution differs.
Log rotation is worth planning too: daily files with a clear naming scheme, kept for a fixed period, make it easier to find a specific day and prevent logs from filling the disk on a small VPS.
The row I added last and now value most is the signal the EA rejected. If it skipped a valid setup for spread or session time, I log the reason code, otherwise the live versus backtest comparison only shows trades that happened.
For the unique ID I build a string from symbol, magic number and the bar open time of the signal. It survives restarts, which a simple counter did not when my VPS rebooted mid session.
Timestamps need two clocks. I write server time plus a local millisecond count from GetTickCount, because server time alone cannot show the 300 to 400 ms gap I sometimes see between send and fill.
On MT5 the retcode gets its own column instead of hiding in free text. Grouping by it after a month showed most of my retries were price changed responses around the London open, not connection drops.
Rotation is easy to underrate. My daily CSV runs 1 to 2 MB on a busy day, so I keep 90 days, but verbose debug text is capped at 14 days.
Do you write to file on every tick, or buffer and flush once per bar? I moved to buffering after the writes started adding visible latency on a cheap VPS.
Two things I write once per session rather than per trade have saved me the most time. The first is a header line with the EA version and a short hash of every input value, so each trade row can be traced back to the exact settings that produced it.
That caught a mess last spring. After a template reload one terminal window was running the EA with an old lot multiplier, and only the hash column showed two different input sets live on the same account.
The second is a snapshot of the symbol specification at startup: contract size, tick value, stops level and freeze level. My broker changed the stops level on gold one weekend, and the only clue was a sudden run of invalid stops errors on Monday morning.
I also make the strategy tester write exactly the same CSV schema as live. A short script can then line up live and backtest rows by signal ID and print only the trades that differ in fill or exit reason.
Do you log equity and open position count alongside each trade as well? I added both after a margin call left gaps in the record that I could not explain.
When an automated strategy misbehaves, logs are the main source of information. Poor logging leaves the developer guessing, while good logging allows rapid diagnosis.
Useful logs record each decision with timestamps, the data that led to it, and the outcome. Entries should include signal values, prices at the moment of decision, order requests and responses, error codes, and the state of key variables. Spread, latency, and slippage on each fill add valuable context for later analysis.
Log levels distinguish routine information from warnings and errors, making it easier to scan for problems. Rotating files prevent disks from filling, and timestamps in UTC avoid confusion. Periodic review of logs, not only after failures, often reveals subtle issues, such as repeated rejected orders or unexpected delays. Aggregating log data into a database or spreadsheet allows trend analysis. The effort spent on logging pays back whenever something unusual happens, which in live trading is guaranteed to occur sooner or later.