Writing trade context to a CSV at entry, not at exit
Posted: Wed Oct 28, 2026 9:11 am
For a long time my EAs only logged trades at close: entry price, exit price, result. When I wanted to analyse why trades worked, I didn't have the data that mattered.
Now each EA writes a row to a CSV at the moment of entry, with:
This let me find that trades taken when ATR on M5 was in the bottom third had a much lower win rate. I wouldn't have seen that from the close-only log.
The file grows quickly, so I start a new one each month. Writing is cheap in MQL5 with FileOpen in append mode, and I flush after each row so nothing is lost if the terminal crashes.
What context fields do you log? I'm thinking of adding the spread of a correlated pair.
Now each EA writes a row to a CSV at the moment of entry, with:
- Time, symbol, direction, entry price, stop, target.
- Spread at entry and ATR on M5 and H1.
- Distance to the Asian high and low, and to the previous day's high and low.
- Session flag and minutes since the London open.
This let me find that trades taken when ATR on M5 was in the bottom third had a much lower win rate. I wouldn't have seen that from the close-only log.
The file grows quickly, so I start a new one each month. Writing is cheap in MQL5 with FileOpen in append mode, and I flush after each row so nothing is lost if the terminal crashes.
What context fields do you log? I'm thinking of adding the spread of a correlated pair.