Missing candles in a backtest: download the data again or stop the test

Missing candles in a backtest are easy to overlook: the file has plenty of rows, the chart renders, and trades appear. Yet an indicator may treat records two hours apart as adjacent observations. An open position may jump across a period in which the price is unknown.
First establish why the gap exists. Downloading the data again helps when the historical dataset is incomplete. If there genuinely were no trades during the interval, the decision depends on the source's rules and the strategy model. You cannot fill every empty hour with the previous price.
How to find missing candles in a backtest
Record the exchange, market, symbol, timeframe, and period boundaries. Then put timestamps on a single time scale, such as UTC. Check whether the field marks the candle's opening or closing time, and do not confuse seconds with milliseconds.
The dataset below is entirely synthetic: the prices and volumes are invented, and the dates serve only to explain the example. It is not an exchange export. Each timestamp marks the opening of an hourly candle; volume is expressed in arbitrary units of the base asset.
| Opening time, UTC | Open | High | Low | Close | Volume |
|---|---|---|---|---|---|
| 01.10.2026 10:00 | 100 | 103 | 99 | 102 | 10 |
| 01.10.2026 11:00 | 102 | 104 | 101 | 103 | 12 |
| 01.10.2026 11:00 | 102 | 104 | 101 | 103 | 12 |
| 01.10.2026 13:00 | 103 | 106 | 102 | 105 | 9 |
The interval from 10:00 to 14:00, excluding the right boundary, contains four expected hourly slots. The table also has four rows, but only three unique timestamps: 11:00 is repeated and 12:00 is missing. The gap between 11:00 and 13:00 is 7,200 seconds rather than 3,600. A matching row count does not prove that the historical data is complete.
An identical duplicate can be removed, provided you retain the original and a record of the change. If two rows with the same timestamp have different OHLCV values, first establish where the versions came from: choosing the “last row” without justification may change a signal.
Also check that High is not below Open or Close, Low is not above either, and Volume is nonnegative. These conditions catch some errors, but do not establish that the prices are accurate.
No trading and a download error can look alike
Coinbase Exchange's historical candle documentation explicitly says that data is not published for intervals with no ticks. It also specifies a limit of 300 candles per request. An empty interval and a truncated download therefore need different explanations.
Check request boundaries and the source's responses, and download the disputed interval again along with adjacent candles. Compare the same market and instrument: a similar pair on another exchange cannot restore your historical data. A missing candle does not, by itself, prove that no trading occurred. If the source does not let you distinguish the causes, retain an “unknown cause” status.
Check the final candle separately. An interval still in progress when the data is downloaded cannot be treated as complete. For example, an hourly candle opening at 13:00 is still forming if downloaded at 13:30 UTC. Exclude it from calculations of close-based signals and request it again after the hour ends. Check time fields and interval rules against the particular API's documentation, such as Binance Klines.
How to choose a gap-handling policy
| What you have established | Decision before the test |
|---|---|
| The source returned the candle on a repeat request | Add it to a copy of the dataset, record the source, and repeat the duplicate and timestamp-step checks |
| An interval without trades is confirmed | Define in advance how the strategy handles time and indicator calculations during that interval |
| The data is unavailable, but separate sections can be tested | Isolate independent continuous segments and explicitly limit conclusions to those segments |
| The cause is unknown, or a position spans the gap | Stop this run until the data is restored or a separate model of the uncertainty has been agreed |
A candle with OHLC values equal to the previous Close and zero volume is an artificial record. Some models may allow it as a predefined representation of an interval without trades. But it does not restore trades, the spread, or the possibility of execution. It must not be inserted silently and presented as an exchange candle.
Indicator warm-up and positions at the boundary
After a gap, simply continuing the calculation from the next row is not enough. For an SMA of three consecutive hourly closes in our example, the restarted series needs the closing prices of the 13:00, 14:00, and 15:00 candles. The last of these becomes known at 16:00 UTC. Until then, a complete new three-hour calculation is unavailable. Recursive indicators, including EMA, require a separately specified initial state and warm-up length.
An open position is even more complicated. If it existed before the missing hour, the unknown price could have affected an exit, a stop, or the size of the next trade. You cannot delete the hour and declare that the position safely survived the gap. A test of independent segments starts without a carried-over position and with a fresh warm-up; it no longer describes continuous trading over the entire period.
Excluding bad data also changes the sample. If gaps coincided with sharp moves, the remaining calm sections will produce a biased estimate (selection bias). Set the exclusion rule before looking at profits, and retain all excluded intervals and their reasons in the report.
Before backtesting a crypto strategy in XTester, record the historical data source, the gaps found, the chosen policy, and the point at which signals resume. This method does not assume that the application will automatically detect and repair every gap. For subsequent data splitting, use the separate guide to walk-forward and out-of-sample testing.
Checking historical data makes research more transparent, but does not prove that a strategy is profitable or safe. This material is not investment advice; real trading can result in a loss of funds.
This material is for information only and is not investment advice. Backtest results do not guarantee future returns.


