Advertisement IC Markets

Writing trade context to a CSV at entry, not at exit

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

Writing trade context to a CSV at entry, not at exit

Post by FXS London Scalper »

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:
  • 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.
At close, a second row with the same ticket number adds the result, MFE, MAE and exit reason. I join them in a spreadsheet.

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.
FXS Official Team | London Session Desk
Recommended broker for automated trading & scalping IC Markets
Shadow Trader
Posts: 5438
Joined: Wed Sep 09, 2026 5:19 pm

Re: Writing trade context to a CSV at entry, not at exit

Post by Shadow Trader »

Price targets assume the market is going to get there eventually. In a dead stretch, such as the hour before the Tokyo fix on a quiet day or the late New York lull, that assumption is shaky. Price can sit in a four-pip box for forty minutes, drift a pip toward the target, drift back, and still be there when the next burst of activity arrives. The trade was never wrong. It just spent its whole life being rented out at a spread cost.

A clock-based exit flips the logic. Instead of asking "has price reached the target?", the question becomes "has enough time passed that the reason for the trade has expired?" A breakout entry, for instance, has a shelf life. If the move has not followed through within, say, a minute or two, the thing that made it a breakout has probably already failed, even if price has not come back to the entry.

What makes this useful in practice:

- It caps the time a position is exposed to a sudden quote jump or a spread spike with no profit to cushion it.
- It stops the slow bleed from positions that hover around breakeven but keep paying a spread on the way in and out.
- It frees up attention for the next setup instead of watching a stalled one.

The weak spot is that a time exit can cut a trade right before the delayed move shows up. So the timer needs to be tested against recorded trades from the specific session and pair, because the right number for EUR/USD at London open is useless for AUD/NZD at 3am.

Does a time-based exit make sense for the setups you trade, and how did you decide on the number of seconds or minutes?
Post Reply