Setting up a walk-forward backtest is less about software and more about discipline: keeping the data the strategy tunes on strictly separate from the data it is judged on. Done right, the result is an honest estimate of how a strategy behaves on conditions it has never seen. Done loosely, you are back to grading a strategy on its own homework.
Before you start
Decide three things up front: the pair and timeframe you are testing, the length of your in-sample (tuning) and out-of-sample (validation) windows, and the cost model you will charge. Charging realistic costs from the first run keeps you honest — a strategy that only works at zero fees is not worth tuning.
Steps
- Split the history into windows. Divide your data into successive in-sample and out-of-sample windows that never overlap. Each in-sample window is for tuning; the following window is for validation only.
- Tune on in-sample only. Optimise parameters using only the in-sample window, so the next window stays genuinely unseen. Resist the urge to peek at validation results while tuning.
- Apply the realistic cost model. Charge fees, spread, and a slippage buffer inside the test so the strategy must beat its full friction, not just predict direction.
- Validate and roll forward. Score the strategy on the unseen window, then roll both windows forward and repeat across every fold until you have covered the history.
- Read the gap. A wide in-sample to out-of-sample gap is the signature of overfitting. Treat a passing run as permission to paper trade — never as permission to go live.
What a good result actually means
A clean walk-forward run with costs included and a narrow gap is a meaningful signal — but it is still a simulation. Real markets diverge from any model, and a passing backtest does not guarantee future results. That is exactly why the paper-trading gate exists between a tested strategy and live funds.
For the theory behind this process, read walk-forward testing explained. To understand the cost model you are applying, see the cost-beating rule for trading signals. When a strategy passes, the next stop is the Kraken API trading bot — in paper mode first.