2026-12-04 · The Spera team
How to Backtest a Crypto Trading Strategy (and Not Fool Yourself)
How to backtest a crypto trading strategy step by step: honest costs and funding, holdout and walk-forward tests, the metrics that matter, and biases to avoid.
Short answer: to backtest a crypto trading strategy, write its rules down so precisely that a computer can follow them, run them over historical candles that include both bull and bear markets, and charge every trade the fees, slippage and funding it would really pay. Then judge the result on data you did not tune against, before you risk money on it.
The mechanics take minutes. The hard part is not fooling yourself, because a backtest is very good at telling you what you want to hear. This guide covers the process, the numbers worth reading, and the mistakes that turn a good-looking backtest into a losing bot.
What is a backtest, and what isn't it?
A backtest replays a set of trading rules over past market data and records what would have happened: every entry, every exit, every fee, and the account balance after each one. It answers one narrow question: if I had followed exactly these rules over exactly this period, what would the result have been?
It is not:
- A forecast. It describes one history. Markets change, and an edge that existed in 2021 may not exist now.
- Proof of skill. A strategy that was long during a rally made money because the market rose. That is market exposure, not an edge.
- A test of one idea. If you tried fifty variations and kept the best, the backtest of the winner reflects the search as much as the strategy.
Keep those three limits in mind and the rest of the process follows from them.
How do you backtest a crypto trading strategy, step by step?
1. Define the rules precisely
Write the strategy so there is no judgement left in it. "Buy when momentum turns up" is not testable. "Enter long when the 20-period EMA crosses above the 50-period EMA on the 4h close; exit when it crosses back below, or at a 3% stop" is.
Every rule needs four things:
- Entry condition, evaluated on a closed candle.
- Exit condition, including stops and take-profits.
- Position size: a fixed amount, a percentage of equity, or a risk-based size.
- Market and timeframe: which pair, spot or perpetual, which candle interval.
If you can't write a rule down, you can't backtest it, and you can't trust yourself to follow it live either.
2. Choose the data, timeframe and period
The period matters more than most people expect. Crypto moves through very different regimes: long trends up, long trends down, and months of chop. A strategy tested only on a rising market will mostly measure that rise.
- Cover more than one regime. Include at least one sustained uptrend, one downtrend and one sideways stretch. If your data only spans a bull run, say so when you report the result.
- Match the timeframe to the idea. A 1-minute strategy needs far more data quality and far more realistic fills than a daily one.
- Use the right instrument. Spot and perpetual futures prices are close but not identical, and only perpetuals pay funding and can be liquidated.
- Watch for gaps and bad prints. A single erroneous wick can trigger a stop or a fill that never could have happened.
3. Model costs: fees, slippage and funding
This is where most backtests lie. Costs look small per trade and compound into something large.
- Trading fees. Exchanges publish maker and taker rates, for example on Binance's fee schedule. Use the rate you would actually pay, not the best VIP tier.
- Slippage. Market orders fill at worse prices than the last candle close, especially in fast markets and thin pairs. Assume some, every trade.
- Funding on perpetuals. Perpetual futures have no expiry. Instead, longs and shorts pay each other at regular settlements, every 8 hours by default on Binance; when the rate is positive, longs pay shorts (Binance's funding explainer). A strategy that holds longs for days pays this repeatedly.
Here is hypothetical arithmetic to show why this matters. Suppose a strategy makes 300 round trips a year, pays an assumed 0.1% fee on each side, and loses an assumed 0.05% to slippage on each side. That is 0.3% per round trip, or roughly 90 percentage points of return a year spent on costs before the strategy earns anything. Now suppose it also holds an unleveraged long perpetual position through an assumed funding rate of 0.01% every 8 hours: that is about 11% of the position's value a year. Neither number is a forecast; both are reasons to put your own costs in before you look at the result.
Zero-cost backtests are fiction
A strategy that only works with no fees and perfect fills does not work. If you are unsure of your costs, set them higher than you expect, not lower.
4. Run it
Simulate candle by candle, in order, so each decision only sees data that existed at the time. Signals should fire on a closed candle and fill on or after the next price, not at a price the candle had already passed. If you use leverage, the simulation must also model margin and liquidation; a backtest that ignores liquidation will happily survive a move that would have closed the position.
5. Read the metrics together
No single number tells you whether a strategy is good. Read them as a set, and always next to the baseline of simply holding the asset over the same period. The table below covers the ones that matter.
6. Hold out data and walk it forward
Everything you see while building is in-sample: you have, consciously or not, shaped the strategy around it. Every time you nudge a parameter because the result improved, you fit it a little harder to that window.
Two techniques break that circle:
- Out-of-sample holdout. Before you start, cut off the most recent slice of your data by time (say the last 20 to 30%) and don't look at it. When you are done building, test once on that slice. If the risk-adjusted return collapses there, the in-sample result was mostly fit.
- Walk-forward analysis. Split the full period into several consecutive windows and score each on its own. An edge that shows up in most windows is more believable than one that lives in a single lucky quarter.
Every edit, every setting you tried, every result you looked at.
Scored once, at the end. Never seen while tuning.
The holdout only works once. If you test on it, adjust, and test again, it has become in-sample data.
7. Paper trade before money
A backtest, however careful, still ran on history you could see. The only data you cannot have tuned to is data that hasn't happened yet. Run the strategy forward on live candles with a simulated account for a while, and check that its trades look like the backtest's. If the live behaviour diverges, something in the backtest was unrealistic.
Which backtest metrics matter, and how do you read them?
| Metric | What it measures | How to read it |
|---|---|---|
| Net return vs buy-and-hold | Total return after costs, compared with holding the asset over the same period | If holding did better, the strategy added risk and complexity without adding return. |
| Max drawdown | The largest fall from a peak to a later trough | Ask whether you could sit through it with real money. A high return behind a 60% drawdown is often untradeable. |
| Sharpe ratio | Return per unit of volatility | Higher is better, but a high Sharpe over a short window, or after many tries, is weak evidence. |
| Sortino ratio | Like Sharpe, but only penalises downside volatility | Useful for strategies with lumpy upside; read it alongside Sharpe, not instead. |
| Profit factor | Gross profit divided by gross loss | Above 1 means winners outweigh losers. Barely above 1 means a small change in costs can erase it. |
| Trade count | How many trades produced the result | A handful of trades proves nothing. Few trades means the other numbers are mostly noise. |
| Exposure | Share of time the strategy holds a position | A strategy in the market 95% of the time is close to buy-and-hold; judge it against that. |
Two patterns to watch for. A high win rate with a low profit factor usually means many small wins and a few large losses, which feels fine until the large loss arrives. And an equity curve that is flat and then jumps usually means one or two trades made the whole result: look at the trade log before you trust it.
What are the most common backtesting mistakes?
These are the classic biases. Each one makes a backtest look better than reality, and none of them produces an error message.
| Bias | What it is | How to spot it | How to avoid it |
|---|---|---|---|
| Look-ahead bias | The strategy uses information that wasn't available at decision time, such as a candle's close before it closed | Results that are too good, especially near-perfect entries at turning points | Evaluate only on closed candles; fill on the next price; replay a few trades by hand |
| Survivorship bias | Testing only on assets that still exist and are popular today | A coin universe chosen from today's top list | Pick the universe as it was at the start of the test, including coins that later collapsed or delisted |
| Overfitting (curve-fitting) | Rules or parameters tuned until they match the noise in one history | Many parameters; performance that vanishes when a setting moves one step | Few rules; test neighbouring parameter values; judge on held-out data |
| Data snooping (multiple testing) | Trying many ideas and keeping the best, so luck looks like skill | You can't say how many variations you tried | Count every attempt; demand stronger evidence the more you tried |
| Ignoring costs | No fees, no slippage, no funding | Lots of small trades with a thin average profit | Charge realistic or pessimistic costs on every trade |
| Too few trades | A result built on a handful of trades | Trade count in the single or low double digits | Longer history, lower timeframe, or accept the result as unproven |
Overfitting and data snooping deserve extra attention, because they are easy to commit without noticing. Bailey, Borwein, López de Prado and Zhu show how readily a backtest can be overfit when many configurations are tried, and why its in-sample Sharpe then says little about out-of-sample performance (Pseudo-Mathematics and Financial Charlatanism, Notices of the AMS, 2014). Bailey and López de Prado's Deflated Sharpe Ratio gives a way to correct a Sharpe ratio for the number of trials behind it. The intuition is simple: if you test twenty ideas with no edge at all, about one of them will pass a 5% significance test by luck.
Keep a trial log
Write down every variation you run, including the ones you threw away. The number of attempts is part of the result. Without it, nobody (including you) can tell how much of the winner is luck.
A checklist for reporting a backtest
Before you share a result, or believe one, make sure it states:
- The exact rules, including entries, exits, stops and sizing
- Pair, instrument (spot or perpetual) and timeframe
- Start and end dates, and which market regimes they cover
- Fees, slippage and funding assumptions, per trade
- Leverage and margin mode, and whether liquidation was modelled
- Net return next to buy-and-hold over the same period
- Max drawdown, Sharpe or Sortino, profit factor and trade count
- Which data was in-sample and which was held out, and the out-of-sample result
- How many variations were tried before this one
- Whether it has been paper traded, and for how long
A result that can't fill in this list isn't ready to trade.
How do you backtest a strategy in Spera?
Spera is built around the process above. The short version:
- Quick and deep backtests. A quick backtest runs over the candles on your chart in seconds, for the edit-and-test loop. A deep backtest runs over an explicit date range as a job, so you can cover several regimes. Both use the same engine that powers paper trading, so a backtest and a paper run on the same data agree exactly.
- Costs are settings, not afterthoughts. Backtest settings set the starting balance, fees, slippage, margin, sizing and an optional risk policy. Leveraged runs are judged like a Binance futures account: positions can be liquidated, and futures runs are charged the funding settlements Binance actually made. The buy-and-hold benchmark pays funding too.
- Metrics read as a set. Results show Total PnL, Win Rate, Profit Factor and Max Drawdown up front, with Sharpe, Sortino, Calmar, trade count and more one click away, plus a comparison with buy-and-hold. Reading your results explains each one.
- Holdout and walk-forward on deep runs. You can hold back the final 20%, 25% or 30% of the window by time, and split it into 4, 6 or 12 walk-forward periods, each scored on its own. Quick runs deliberately show no out-of-sample number, so you can't tune against it. Out-of-sample and walk-forward covers how the window is cut and what each verdict means.
- An Edge Report that tries to break the result. The Edge Report runs up to eight checks, including random-entry and shuffled-market comparisons and parameter sensitivity, and says plainly when a check didn't run. The Edge Rating letter discounts market exposure, harsher costs, luck and the number of versions you tried.
- Forward before money. A forward run tests a saved version on candles since you saved it, and a paper bot trades new candles with a simulated wallet.
If you want a guided path, the Learn course walks through running your first backtest and then trying to break it with a deep run, a holdout and the Edge Report. When you're ready, open the Builder and test your own idea.
FAQ
How much historical data do I need to backtest a crypto strategy?
Enough to cover more than one market regime and to produce a meaningful number of trades. There is no single answer in years: a daily strategy may need several years to trade often enough, while an hourly one may get there in months. If the trade count is low, the result is unproven however good it looks.
How many trades does a backtest need to be meaningful?
More than most people use. A few dozen trades is a bare minimum for any statistic to mean much, and small edges need far more. As one reference point, Spera's out-of-sample check refuses to score a held-out stretch with fewer than 20 closed trades.
What is a good Sharpe ratio for a crypto backtest?
There is no universal threshold, because the same Sharpe means different things depending on how long the test was and how many variations you tried. A high Sharpe from a short window, or from the best of many attempts, is weak evidence. Compare it with buy-and-hold over the same period, and check whether it survives on held-out data.
Should I backtest on spot or perpetual futures data?
Test on the instrument you will trade. Perpetuals add funding payments and liquidation risk, and both can change the result materially, especially for strategies that hold positions for days or use leverage.
What is the difference between backtesting and paper trading?
A backtest replays history you could see while building. Paper trading runs the strategy on new candles as they close, with a simulated account and no real money. Paper trading is the first test the strategy could not have been tuned for.
Why does my live result differ from my backtest?
The usual causes are underestimated costs, look-ahead bias in the backtest, overfitting to the tested period, or a market regime that has changed. Compare live trades with backtested trades over the same dates to find which.
Can a backtest prove a strategy will be profitable?
No. A careful backtest can show that a strategy had an edge in the past that survived costs and held-out data. That raises confidence; it does not guarantee anything about the future.
Summary
To backtest a crypto trading strategy honestly: write precise rules, test across bull and bear regimes, charge real fees, slippage and funding, read return together with drawdown and trade count, compare with buy-and-hold, keep a slice of data you never tuned on, count every variation you tried, and paper trade before you fund anything. A backtest that survives all of that is worth taking seriously. One that doesn't has already saved you money.
Backtests describe the past; they don't promise future results. Nothing here is investment advice.