On an hourly chart there are no candles between midnight and three in the morning. That does not show up as a gap; the two candles are drawn side by side, so the eye never registers the three missing hours. The indicator does not register them either, and a twenty-period average quietly measures a twenty-three hour window.
Three causes of a gap
Different things, handled differently.
A maintenance window. The exchange goes into planned maintenance, nothing trades for that period, and because the window is usually announced in advance it repeats at a regular hour. It is the one predictable kind of gap.
No trades. In an illiquid asset nothing changes hands during that period. The market is open, the book is there, no trade happens. Here the gap is the information rather than an error.
Data provider loss. The connection dropped, the collector crashed, the history downloaded incomplete. This third group is the dangerous one, because nothing distinguishes it directly from the other two.
The misleading way to fill
Most tools close gaps with a “fill with previous close” option. The chart then looks tidy and the data is continuous.
The problem: those filled candles have zero volume, a flat price, no volatility. A volatility indicator reads that region as extremely calm, your strategy opens a position in exactly that spot, and by the time the first real candle after maintenance arrives you find the price has already moved.
Filling is a choice. Choose it and you accept, along with it, how your indicators will see that period.
What it does to a backtest
Where the history has gaps, the test treats that period as never having happened at all, and the result comes out distorted in two separate directions.
First, price jumps that occurred across maintenance windows and outages never enter the test at all. The maximum drawdown you see is shallower than the truth for that reason.
Second, every indicator based on a period count shifts: on a gapped series a twenty-candle average is no longer an average of twenty hours, and the only way to learn how many hours it does cover is to read the timestamps.
What to do
Count the gaps, do not hide them. When loading data, compare the expected period count against the actual one, and if the difference crosses the threshold you set in advance, keep that period out of the test entirely.
List the maintenance hours. The maintenance windows of the exchanges you trade are known. Keep them in a list and stop counting gaps in those hours as data loss.
Read a gap as a signal when live. If the bot did not receive the candle it expected, the strategy calculation should be postponed, because an indicator computed on incomplete data produces a more dangerous result than one never computed. It answers wrongly without saying so.
A one-line check
After every data load, compare the span between the first and last timestamp against the number of candles. If the two disagree, the series has gaps.
The check takes one second, and it removes the cause that corrupts backtest results most quietly.



