OHLCV Data for Backtesting: A Beginner’s Guide

Short answer: To backtest a crypto strategy you need clean OHLCV candles in the timeframe your strategy trades, with no gaps and in UTC, with fees and slippage included and signals computed only from information available at each candle close. The most common failure is look-ahead bias, followed by too few trades and overfitting.

If you are building a crypto trading bot or testing a strategy, OHLCV data is where you start. It is the standard historical format used by every major backtesting framework — freqtrade, vectorbt, backtrader, and Nautilus Trader all expect it.

What OHLCV Stands For

  • O — Open: price of the first trade in the period
  • H — High: highest price during the period
  • L — Low: lowest price during the period
  • C — Close: price of the last trade in the period
  • V — Volume: total quantity traded

Which Timeframe Should You Use?

  • 1m / 5m: scalping, market making — noisy, requires large datasets
  • 15m / 1h: most common for retail algo traders — balanced signal/noise
  • 4h / 1d: swing trading, trend following — clean signals, fewer trades

Loading OHLCV Data in Python

import polars as pl

df = pl.read_parquet("BTC_OHLCV_1h.parquet")
print(f"Candles: {len(df):,}")
print(f"Range: {df['candle_time'].min()} to {df['candle_time'].max()}")

The Backtesting Trap: Look-Ahead Bias

Using the close price of a candle to generate a signal that executes at that same close is impossible in live trading. Always shift your signal by one period: .shift(1). An audited OHLCV dataset verifies that every candle boundary is correct — no future information leaks into any candle.

How Many Candles Do You Need?

A one-year Bitcoin OHLCV dataset at 1-minute resolution contains approximately 526,000 one-minute candles. At 1-hour resolution, around 57,000 — enough for statistically meaningful backtesting across multiple market regimes. Testing on less than two years risks overfitting to a single market regime.

Free OHLCV Bundle: BTC, ETH, XRP, SOL, LINK, LTC and ADA, 6 timeframes (1m to 1d) in Parquet, each with an integrity disclosure of its known gaps. → Get the free OHLCV Bundle

Pre-flight checklist before you run a backtest

Check Why it matters
No missing candles Gaps distort indicators and fake returns
UTC timestamps end to end Timezone shifts move signals by hours
Fees and slippage included Edges of a few basis points disappear without them
Signals shifted by one bar Removes the classic look-ahead bias
Out-of-sample or walk-forward split Shows whether the edge survives unseen data
Enough trades A handful of trades is noise, not evidence

A minimal example without look-ahead

import pandas as pd
df = pd.read_csv("btcusdt_1h.csv", parse_dates=["timestamp"], index_col="timestamp")
df["sma_fast"] = df.close.rolling(20).mean()
df["sma_slow"] = df.close.rolling(100).mean()
# act on the NEXT bar: shift(1) removes look-ahead bias
df["signal"] = (df.sma_fast > df.sma_slow).astype(int).shift(1)
df["ret"] = df.close.pct_change() * df["signal"]
fee = 0.0005  # hypothetical 5 bps per side
trades = df["signal"].diff().abs().fillna(0)
df["net"] = df["ret"] - trades * fee
print("net return:", (1 + df["net"].fillna(0)).prod() - 1)

After the backtest: audit it

A good-looking equity curve is not proof. Export your trades and run them through the Backtest CSV Auditor to check for fragile results and data-quality problems. If your rules depend on what happens inside a candle, read tick data vs OHLCV before trusting OHLCV alone.

Free data to start with

The Glitch List publishes a free OHLCV Bundle (7 coins) in six timeframes, each shipped with an integrity declaration that lists its known gaps. Background on the format: what is OHLCV data.

Browse the full dataset catalog

FAQ

What data do I need to backtest a crypto strategy?

Clean OHLCV candles in the timeframe your strategy decides on, with no gaps, in UTC, with realistic fees and slippage applied, and signals computed only from information available at each candle close.

What is look-ahead bias in backtesting?

It happens when a signal uses information that was not yet available at the moment of the trade, for example acting on a candle’s close price at that same candle’s open. Shifting signals by one bar prevents the most common version.

How many candles do I need for a reliable backtest?

Enough to contain many independent trades across different market regimes. A strategy with only a few dozen trades tells you very little, however long the history looks.

How do I know my backtest is not overfit?

Hold out data the strategy never saw, use walk-forward testing, keep the parameter count small and audit the trade list for suspicious win rates and fragile results.

Summary

OHLCV data is the practical starting point for almost every crypto backtesting project. It is compact, widely supported, and sufficient for the majority of strategies. A clean, audited OHLCV dataset with multiple timeframes is exactly what you need to start.

Explore

More from the blog
Free tools  ·  Is your backtest just luck?