Forex tick data in Python
Code to read a CSV, measure spread, build bars, convert time zones and handle large files.
If an EA wins in backtests and loses live, the reason is usually one of these seven. You can check every one of them before you go live.
Updated 2026-12-02
Most often costs were set too low: spread, commission and slippage. Strategies that earn little per trade and trade often suffer most. After that come simulated prices and settings that fit the past too closely.
A live spread keeps changing. It is small in quiet hours and larger at the open, at the close and around big news. A backtest with one small spread for the whole period counts too little cost.
What to do: in MT5, test on real ticks, where each tick has its own bid and ask. MT4 has one spread for the whole test, so test with a small, a medium and a large one. If your account's spread is wider than the data's, use Spread widening when you export.
A live order takes time, and price moves meanwhile. By default a backtest fills at the requested price at once.
What to do: MT5's tester can add a delay. With Random Delay, 90% of orders wait 0 to 8 seconds and 10% wait 9 to 18 seconds. You can also enter a fixed delay.
Low-spread accounts usually charge commission as well, and holding overnight costs swap. A backtest may include neither.
What to do: enter your commission in the MT5 tester's settings. On a custom symbol, check the swap settings too; they are sometimes off. Note that the “profit in pips” mode leaves out commission and swap.
Forex has no single exchange. Every broker's quotes are a little different, and the high of the same minute may differ by a point or two. For a very close stop, that alone can change the result.
What to do: move stops and targets by a point or two and see whether the result holds. If it flips from profit to loss, the strategy is too sensitive.
The server's time decides when an H4 or D1 bar starts. Move it by an hour, and the bars have a different shape and give different signals.
What to do: export in your broker's time zone. See time zones in forex data.
With only 1-minute bars, the tester guesses how price moved inside a minute. When it guesses wrong, the order of stop and target is reversed.
What to do: use real ticks for the final check. See MT5 Every tick vs real ticks.
Try a thousand settings, and one will look great on past data. It may only have memorised the past.
What to do:
| Check | What passes |
|---|---|
| Real ticks | The last test used real ticks, with high history quality |
| Spread | With a spread half as large again, it still doesn't lose |
| Delay | Random delay changes the result only a little |
| Commission | Your account's commission is entered |
| Time zone | Bars match your broker's chart |
| Unused data | It doesn't lose on a period kept out of the optimisation |
| Demo account | Run it on demo for a few weeks and compare with a backtest of the same weeks |
Passing this list doesn't mean the EA will make money. It only removes the usual mistakes.
Guides
Code to read a CSV, measure spread, build bars, convert time zones and handle large files.
Create a custom symbol, import M1 bars and ticks, then test on real ticks.
What .hst and .fxt are, why quality shows n/a, and how to check your data.
Download the client and, the first time you open it, click “Try free for 7 days” in the setup guide: no sign-up and no payment. Choose one symbol and download its last 7 days of data; every export format and one-click import are available. Once you're sure it suits you, choose a single symbol or all markets.