Backtesting means replaying a strategy against historical price data to see how it would have performed — before risking real money. Here's how to do it properly.
The basic loop
- Define the strategy in rules — exact entry, exit, stop-loss, position size. Vague strategies can't be backtested.
- Get clean historical data — OHLCV (open/high/low/close/volume) candles per timeframe, plus funding rates for perpetual strategies. Free sources: Binance/Bybit public API, or paid datasets like CoinAPI for deeper history.
- Run the simulation — walk through candles, applying your rules bar by bar, tracking equity, drawdown, fees, and slippage.
- Measure performance — not just total return. Key metrics: CAGR, max drawdown, Sharpe ratio (risk-adjusted return), win rate, profit factor (gross profit ÷ gross loss), and number of trades (few trades = results are statistically meaningless).
- Validate out-of-sample — split data into a training period and a hold-out period you never tuned on. If it only works on the training data, it's overfit.
Tools you'd use
- Python (the standard):
backtesting.py library, vectorbt, zipline, or backtrader. Full control over logic.
- TradingView — built-in Strategy Tester, good for quick indicator-based tests, no coding required.
- Freqtrade — open-source crypto bot with a built-in backtesting engine; useful if you also plan to automate.
- Exchange-native — some platforms offer paper trading, which is a useful forward test (live data, fake money) once a backtest looks good.
The crypto-specific traps (where most backtests lie)
- Slippage & fees: crypto is volatile and thin-liquidity-friendly; a backtest ignoring these overstates returns badly. Always model both.
- Lookahead bias: using info at bar N+1 to make a decision at bar N. Classic bug.
- Survivorship bias: testing only coins that survived — altcoins that died get dropped, inflating results.
- Regime change: a strategy that crushes 2020-21 bull volatility can bleed in a flat or bear market. Test across multiple regimes, not just the nice one.
- Overfitting: curve-fitting to past data means it won't generalize. Fewer parameters, more out-of-sample validation.
The honest bottom line: a good backtest proves a strategy worked in the past, not that it will work tomorrow — and every successful strategy eventually degrades as it gets crowded. Treat any promising result with suspicion until it survives out-of-sample testing and forward paper-trading.
This isn't financial advice — and if you'd like, I can point you to live data on a specific coin (price, volume, volatility) that might be relevant to what you want to test. Just name it.