Guide
How to backtest a crypto trading bot, step by step
Last updated: 3 October 2026
Backtesting means replaying a trading bot's rules over price history and recording every trade it would have taken. Done carefully, it tells you in an hour whether an idea deserves weeks of attention. Done carelessly, it produces a beautiful equity curve that collapses the first day the bot meets a real market. This guide covers the careful version.
Where Crypto Robot fits. Crypto Robot does not run historical backtests. You backtest with the tools described below, then bring the strategy here to run on live prices with a virtual $10,000. The last section explains that handover.
What you need before you start
- A written rule set. Entry, exit, stop, position size. If a rule needs your judgement on the day, a backtest cannot test it.
- Historical candles for the pair and timeframe you will trade.
- A backtesting tool. A charting platform's strategy tester, a Python library or an open-source bot framework. Our comparison of free backtesting tools helps you choose.
- Your exchange's fee schedule, because fees decide whether many short-term strategies make or lose money.
Step 1: get data you can trust
Most exchanges publish historical OHLCV candles (open, high, low, close, volume) through their public API, and the open-source CCXT library fetches them from dozens of exchanges with the same code. Download more history than you think you need: at least one full bull phase, one bear phase and one long sideways stretch. Then check the file. Look for missing candles, duplicated timestamps and absurd spikes. A single bad print at a tenth of the real price can create a trade that never could have happened.
Use data from the exchange you plan to trade on, or one with similar liquidity. Prices for small coins differ from one venue to the next, and a strategy tuned on one exchange's quirks may not travel.
Step 2: split the history before you look at it
Cut the data into two parts and decide the cut date before running anything. Use the first part, around 70%, to design and tune the strategy. Keep the last 30% locked away. When the strategy is finished, run it once on the locked period. That out-of-sample result is the number that matters; the in-sample result mostly measures how hard you tuned.
For a stricter version, use walk-forward testing: tune on a window, test on the next slice, roll both forward, repeat, and stitch the test slices together.
Step 3: model costs honestly
- Fees. Apply the taker fee on market orders and the maker fee on limit orders, on both sides of each trade. A strategy that trades 300 times a year pays the fee 600 times.
- Slippage. Add a small penalty to every market order. Fast moves and thin order books make it larger than you expect.
- Funding. On perpetual futures, include funding payments for positions held across funding times.
Run the backtest once with no costs and once with them. If the edge disappears with costs, the strategy was trading noise.
Step 4: make the simulation match reality
The commonest bug in home-made backtests is deciding with information the bot would not have had. If the signal uses a candle's close, the trade can only happen at the next candle's open. Indicators must be computed from closed candles only. If the stop and the target could both have been hit inside the same candle, assume the worse outcome. Our list of backtesting mistakes covers the other traps.
Step 5: read the report beyond the total return
| Metric | What it tells you | Warning sign |
|---|---|---|
| Maximum drawdown | The worst fall from a peak, in % | Deeper than you could sit through, or than a -10% limit allows |
| Worst day | The largest single-day loss | Close to -5%: a live daily limit would have stopped the bot |
| Profit factor | Gross profit divided by gross loss | Below about 1.2 after costs leaves little margin |
| Number of trades | How much evidence you have | A few dozen trades prove very little |
| Win rate with average win and loss | How the profit is made | High win rate with rare, huge losses |
| Exposure | Share of time in the market | Returns that match buy-and-hold with more risk |
Always compare with a plain benchmark, such as buying and holding the same coin over the same period. A bot that earns less than holding, with a deeper drawdown, adds complexity for nothing.
Step 6: stress the result
- Move each parameter a little up and down. A robust strategy degrades gently; a fragile one falls off a cliff.
- Run the same rules on a second coin or a second timeframe.
- Double the fees and slippage and see what survives.
Step 7: hand it over to a live test
A backtest, however careful, is still a test on data you have already seen. The next step is to run the strategy forward on prices that do not exist yet. On Crypto Robot, your bot gets a virtual $10,000 on live crypto prices and three levels to clear, under fixed risk limits:
| Level | Target | Min. days | Max. days | Max. drawdown | Daily drawdown |
|---|---|---|---|---|---|
| Level 1 | +10% | 5 | 10 | -10% | -5% |
| Level 2 | +5% | 5 | No limit | -10% | -5% |
| Level 3 | +5% | None | No limit | -10% | -5% |
A drop of 5% in one day or 10% overall ends the challenge. Compare what happens with your backtest: if the live drawdown runs far deeper than anything the backtest showed, the backtest was too optimistic. Read forward testing vs backtesting for how to compare the two.
Frequently asked questions
Can you backtest a crypto trading bot for free?
Yes. Free strategy testers on charting platforms and open-source Python libraries such as backtesting.py, Backtrader or vectorbt cost nothing, and historical candles can be downloaded from exchange APIs.
How much historical data do I need for a crypto backtest?
Enough to cover different market regimes: at least one strong rise, one strong fall and one sideways period. For most strategies on hourly candles, that means several years of data.
Does a profitable backtest mean the bot will make money?
No. A backtest only shows how the rules would have performed on past data. Overfitting, missing costs and changing markets often make live results worse, which is why a forward test on live prices comes next.
Does Crypto Robot backtest strategies?
No. Crypto Robot is the live step: after you backtest with your own tools, your bot runs on live prices with a virtual $10,000 under fixed drawdown limits.
Backtest done? Find out how the strategy behaves on live prices.
Start a live test