What Is Backtesting?
Backtesting is the simulation of a trading strategy using historical market data. You're essentially asking: "If I'd followed these exact rules over the past year, would I have made money or gone broke?"
The premise is straightforward. You define your strategy's logic — when to enter, when to exit, how much to risk, which indicators to follow. Then you run it against actual price history and see what happens. Did your long entry at the 50-day moving average crossover catch the bull run? Or did you get chopped up in sideways action?
This isn't crystal ball gazing. Backtesting won't predict the future. But it will expose whether your strategy has an edge, or if you're gambling with extra steps.
Why Traders Backtest (And Why You Should Too)
Most traders lose money. That's not opinion — it's measurable reality across equities, forex, and crypto markets. One reason? They trade based on vibes, not data.
Backtesting forces discipline. It's the difference between "I think Bitcoin pumps after whale accumulation" and "Here are 47 instances where this pattern appeared, with a 63% win rate and 1.8 risk-reward ratio."
Here's what proper backtesting reveals:
- Expectancy: Your average profit per trade after accounting for wins and losses
- Drawdown: The worst losing streak your strategy would have endured
- Win rate: Percentage of profitable trades (spoiler: you don't need 80% to be profitable)
- Risk-adjusted returns: Whether you're making 40% annually with 5% drawdowns or 45% with 60% drawdowns (the former is vastly superior)
- Market regime dependency: Does your strategy only work in bull markets? You'll find out.
I've seen traders blow accounts because they didn't backtest. They'd catch two winning trades, assume they'd cracked the code, then get obliterated when market conditions shifted.
The Backtesting Process: From Idea to Validation
1. Define Your Strategy Rules
Vague ideas don't backtest. "Buy the dip" isn't a strategy — it's a bumper sticker.
You need concrete, unambiguous rules:
- Entry conditions: "Enter long when price closes above the 20-day EMA and RSI crosses above 50"
- Exit conditions: "Exit when price closes below 20-day EMA OR hits 2% stop loss OR reaches 6% profit target"
- Position sizing: "Risk 1% of capital per trade" (see position sizing for why this matters)
- Filters: "Only trade BTC pairs with >$10M daily volume"
If a computer can't interpret your rules without ambiguity, they're not specific enough.
2. Gather Quality Historical Data
Garbage in, garbage out. Your backtest is only as reliable as your data.
For crypto, you need:
- OHLCV data: Open, high, low, close, volume for your timeframe
- Sufficient history: At least 2-3 years to capture different market regimes
- Clean data: No missing candles, no obvious errors (BTC didn't trade at $0.01 last Tuesday)
- Realistic spreads: Especially for lower-cap altcoins where bid-ask spreads matter
Sources like CoinGecko, Messari, and major exchange APIs provide historical data. For DeFi protocols, on-chain data from sources like Dune Analytics captures the full picture.
3. Account for Realistic Trading Costs
Here's where most backtests lie to you.
Your backtest shows 80% annual returns? Cool. Did you include:
- Exchange fees: Typically 0.1-0.5% per trade for crypto spot markets
- Slippage: The difference between expected and actual execution price (slippage kills strategies)
- Spread costs: Buying the ask and selling the bid chips away at profits
- Network fees: Gas costs for on-chain transactions can destroy small position strategies
- Funding rates: For perpetual futures, holding overnight costs money
A strategy that makes 100 trades per year with 0.2% fees per trade sacrifices 20% of capital just to transaction costs. That 80% return? Now it's 60%. Still good, but not what you thought.
4. Run the Simulation
Modern backtesting tools range from Excel spreadsheets to sophisticated platforms. Python libraries like Backtrader or vectorbt are popular. TradingView's Strategy Tester works for simpler approaches.
The simulation walks through each bar of historical data, checks if entry conditions are met, tracks open positions, applies exit rules, and logs results.
5. Analyze Results Critically
Raw returns mean nothing without context.
Key metrics to examine:
| Metric | What It Tells You | Target Range |
|---|---|---|
| Sharpe Ratio | Risk-adjusted returns | >1.5 is solid, >2 is excellent |
| Maximum Drawdown | Worst peak-to-trough decline | <20% for most strategies |
| Win Rate | % of profitable trades | 40-60% is typical for trend following |
| Profit Factor | Gross profit ÷ gross loss | >1.5 suggests edge |
| Average Trade Duration | How long capital is at risk | Depends on strategy type |
But here's the critical question: Would you have actually followed this strategy during the drawdown?
Backtests show a 23% drawdown as a number. Living through six consecutive losses watching your portfolio bleed feels different. If you'd have abandoned the strategy in real-time, the backtest is irrelevant.
Common Backtesting Pitfalls (And How to Avoid Them)
Overfitting: The Silent Killer
You add another indicator. Win rate jumps from 52% to 67%. You add another filter. Now it's 71%. You keep tweaking until your strategy is "perfect."
Congratulations — you've curve-fit your strategy to historical noise.
Overfitting is optimizing a strategy so specifically to past data that it has zero predictive power going forward. It's like studying last year's exam questions and expecting them to repeat verbatim.
How to spot overfitting:
- Strategy has 10+ parameters all "optimized" to specific values
- Performance is spectacular in backtest but immediately fails in live trading
- Minor parameter changes cause dramatic performance swings
- Strategy works on one asset but fails on similar assets
The antidote: Keep strategies simple. Test on out-of-sample data (data the strategy hasn't "seen" during optimization). If it works on BTC 2020-2023, does it work on ETH 2020-2023? If not, you've overfit.
Look-Ahead Bias
This is using information in your backtest that wouldn't have been available at the time.
Classic example: "Buy when today's close is above yesterday's high." Sounds reasonable. But your code accidentally uses today's high in the calculation — information you wouldn't have had until after the trading opportunity passed.
Or using an indicator that repaints — changes its historical values as new data arrives. That "perfect" signal on the chart never existed in real-time.
Survivorship Bias
Your backtest portfolio of altcoins shows 300% returns. Amazing! Except you only tested coins that still exist today.
The 40 projects that went to zero and exited the market? Not in your backtest. But they would've been in your real portfolio.
This is massive in crypto. Testing a "small-cap momentum strategy" on 2020-2026 data using only coins that survived until 2026 excludes all the rug pulls, failed projects, and exchange delistings that would've destroyed real capital.
Ignoring Market Impact
Your backtest buys $2M of a token with $500K daily volume. In reality, that order would move the market against you significantly. Your backtested entry at $1.00 becomes a real entry at $1.08.
Large positions need different assumptions than small ones. If you're backtesting strategies that would move markets, you need impact models.
Backtesting in DeFi: Different Rules Apply
Traditional backtesting assumes liquid markets with continuous pricing. DeFi introduces unique considerations:
AMM slippage models: Trading against an automated market maker like Uniswap produces nonlinear slippage. Your backtest needs to model the x*y=k curve, not just a spread.
Gas cost volatility: A strategy that trades 50 times daily might be profitable when gas is 20 gwei but unprofitable at 200 gwei. Your backtest needs dynamic cost assumptions.
MEV and sandwich attacks: Protocols like Ethereum have bots that front-run and back-run your trades. Backtests assuming atomic execution without interference are optimistic.
Oracle lag: DeFi protocols often use price oracles with delays. Your backtest's instant execution doesn't match reality where price updates lag by blocks.
Understanding whale wallet movements becomes crucial here — large DeFi traders need to account for how their transactions affect pool depth and subsequent execution.
Forward Testing: The Reality Check
Backtesting is homework. Forward testing (paper trading with live data) is the quiz. Real money is the final exam.
After backtesting, run your strategy in real-time without real capital. Track every signal, log every hypothetical trade. This catches issues backtests miss:
- Execution challenges (fills don't happen at your expected price)
- Emotional discipline (can you actually take the signal when it appears?)
- Data discrepancies (your live feed differs from historical data)
- Regime changes (market conditions that didn't exist in your backtest period)
If your forward test performs dramatically worse than your backtest, something's wrong. Either your backtest was overfit, your execution assumptions were unrealistic, or market conditions changed fundamentally.
The Uncomfortable Truth About Backtesting
Here's what makes backtesting both essential and insufficient: markets evolve.
A strategy that worked beautifully from 2018-2023 might fail in 2026 because market structure changed. Maybe liquidity pools got deeper, reducing arbitrage opportunities. Maybe a dominant trading firm started running the same strategy at scale. Maybe regulatory changes altered market behavior.
Backtesting reveals if a strategy had an edge historically. It can't promise that edge persists.
But it's still your best tool. Testing ideas before risking capital is the difference between systematic trading and expensive trial-and-error. The trader who backtests might still lose. The trader who doesn't is almost guaranteed to.