Backtesting

How to Collect Quality Historical Data for Backtesting

A backtest is only as good as its data. Tick vs bar data, broker-specific prices, spreads, time zones, gaps and bad ticks - and a checklist to validate a dataset before testing.

By AlgoXP4 min readUpdated

Historical price series with a missing data gap and a bad tick highlighted

Every backtest result is a statement about data. If the prices are wrong, missing or different from what you will trade on, the statistics are precise answers to the wrong question. Collecting and checking data is the least exciting part of system development, and the one that most often decides whether a test means anything.

Choose the right resolution

Match the data to how the strategy behaves:

Strategy type Minimum sensible data Why
Daily or swing, decisions on bar close H1 or daily bars Intrabar path rarely matters
Intraday, decisions on bar close, normal stops One-minute bars Lets the engine place stops and targets inside bars reasonably
Tight stops, trailing stops, scalping Tick data with bid and ask Spread and intrabar path decide the result
News or session-open strategies Tick data Spread widening and gaps are the whole story

If you are unsure, test with the finer data at least once. A large difference between tick and bar results is a warning that the strategy depends on details that bars hide.

Use your broker’s prices

For FX and CFDs there is no single “true” price. Each broker streams its own quotes, and the differences matter:

  • Spreads differ, especially around rollover and news.
  • Session and daily-close times differ (for example New York 17:00 close versus midnight GMT), which changes every daily bar and every indicator calculated on it.
  • Symbol specifications - contract size, digits, swap rates, trading hours - differ.

The simplest rule: test on the price feed you will trade on. On cTrader, historical data in backtesting comes from the broker’s own server, so tick and bar tests reflect that broker’s quotes.

Spreads are part of the data

Bar data usually stores only bid prices. To simulate buying at the ask, the engine adds a spread you specify - a fixed value or a random range. That is fine for strategies that trade in calm conditions, and dangerous for ones that trade at the open, at news, or at rollover, where real spreads can be several times wider.

Tick data with bid and ask carries the historical spread automatically. If you can only use bars, test with a spread noticeably above the typical value; a strategy whose edge vanishes at a slightly higher spread has no margin of safety.

Watch for these data problems

Gaps. Missing periods inside normal trading hours. A strategy may hold a position “through” a hole in the data and miss a stop that real markets would have hit.

Bad ticks and spikes. A single wrong print can trigger a stop or a breakout entry that never existed. Look for bars whose range is many times larger than their neighbours.

Time zone shifts. Daylight saving changes and mixed time zones shift sessions by an hour. Session-based strategies (Asian range, London open) are especially sensitive.

Duplicated or out-of-order records. Common after merging files from several sources.

Rolled contracts. For futures-based CFDs (oil, indices), price series can jump when the underlying contract rolls. A breakout bot may read a roll as a real move.

Survivorship. For stock strategies, testing only on companies that still exist today ignores those that were delisted, and inflates results.

A validation checklist

Before the first backtest on a new dataset:

  1. Plot it. Look at the full history on a chart. Obvious spikes and holes are visible immediately.
  2. Count bars per day. For one-minute FX data, a normal weekday has about 1,440 bars; days with far fewer are suspicious.
  3. Check the largest bars. Sort by range and inspect the top 20. Real news events are fine; isolated spikes are not.
  4. Check session times. Confirm when the daily bar starts and that sessions do not drift through the year.
  5. Compare with a second source for a few random days. Small differences are normal; large ones are not.
  6. Record what you used: source, period, time zone, resolution, and any cleaning steps. Without this, results cannot be reproduced later.

How much history?

More data is not automatically better, but too little is a common failure. Aim for:

  • Several market regimes: trending and ranging years, low and high volatility.
  • Enough trades: at least about 100 for the main test, ideally many more for strategies with large outliers.
  • A reserved out-of-sample period - often the most recent 20-30% of the data - that you do not look at while developing rules.

Very old data can be less relevant: market structure, spreads and volatility levels change. Use it to check robustness rather than as the main evidence.

Importing your own data

Some platforms accept external data. cTrader, for example, can backtest on one-minute bars from a CSV file (date, time, open, high, low, close, volume). That is useful for symbols or periods the broker does not provide, but it brings back every question above: where the data came from, which time zone it uses, and whether its prices resemble what you will trade.

Key takeaways

  • Match the data resolution to the strategy; test on tick data when stops are tight or timing matters.
  • Prefer the price feed of the broker you will actually trade with.
  • Spreads, gaps, spikes and time zones change results more than most parameter tweaks.
  • Validate and document every dataset before trusting a backtest built on it.

Related: how backtesting works and common backtesting mistakes.

FAQ

Is free historical data good enough?

It can be for daily or H1 strategies, after you check it for gaps and spikes. For intraday systems with tight stops, use tick data from the broker you will trade with, because spreads and prices differ between brokers.

Why do two brokers give different backtest results?

CFD and FX prices are not identical across brokers: quotes, spreads, session times and the daily close (and therefore daily bars) can differ. A strategy tested on one feed and traded on another is trading slightly different markets.

How do I handle missing data?

Find out why it is missing first. Weekends and holidays are normal; random holes inside trading hours are not. Do not fill gaps with made-up prices for intraday testing. Exclude the period, or get better data.

Sources and further reading

  1. cTrader Help: Backtest a cBot (data sources and CSV format) - help.ctrader.com
  2. Bailey et al.: The Probability of Backtest Overfitting - papers.ssrn.com