Data leakage in backtests: six ways your strategy sees the future
Your model scores 74% out of sample. Your equity curve barely dips. And a small voice says that is too good — because it is, and the reason is almost always the same one.
Every other mistake in strategy research makes your result worse. Bad data adds noise. Missing costs add optimism, but only by the size of the costs. Overfitting adds a flattering tilt that a holdout can expose. Leakage is different in kind: it lets the backtest see tomorrow, and a backtest that can see tomorrow will find an edge in anything, including a random walk.
That is why it survives review. Nobody argues with a great result. They argue with a bad one, and leakage never produces a bad one. It produces the strategy that looks best on the day you go live and dies the week after.
What counts as leakage
A backtest is honest when every decision it makes at bar t uses only information that was known at the close of bar t — or, more strictly, at the moment a real trader could have acted. Leakage is any information from after that moment reaching the decision. It is also called look-ahead bias, and the two terms are used interchangeably; "look-ahead" tends to mean the obvious version (using tomorrow's close today) and "leakage" the subtle ones.
The subtle ones are the problem. Nobody writes buy if tomorrow_close > today_close. They write something that looks nothing like that and does exactly that.
The six routes
1. Filling at the bar that made the signal
Your rule evaluates on a closed bar. The earliest you can act is the next bar's open. A backtest that fills at the signal bar's close has given you a price from before you knew to want it. On daily bars that is a full session of hindsight per trade; on hourly bars it is an hour. Either is enough to turn noise into a strategy.
Catch it: delay every fill to the next bar's open and rerun. If the edge shrinks a little, that is the real cost of acting late. If it vanishes, it was never there.
2. Indicators that repaint
Some indicators change their past values when new bars arrive — pivot detectors that need bars on both sides, zigzags, anything that uses a centred window, anything that reads the current unclosed bar. Plotted on a finished chart they look prophetic, because they are: their historical values were computed with knowledge of what came after.
Catch it: replay the chart bar by bar and watch whether signals move or disappear. The repainting guide covers the three kinds and how each one fakes a backtest.
3. Scaling fitted on everything
Machine-learning pipelines normalise features — subtract the mean, divide by the standard deviation, or squash into 0–1. If that mean and standard deviation were computed over the whole dataset, every training row knows something about the future: the overall level and spread of the series, including the test period. Same for PCA, same for any feature selection step run on the full series.
This is the leak that makes deep-learning price predictors look miraculous in tutorials. The scaler saw the 2021 high before the model was asked about 2019.
Catch it: fit every transformation on the training window only, then apply it forward. If the score drops, the old score was partly the scaler's.
4. Labels that overlap their own features
Suppose the label is "did price rise over the next 10 bars?" and the split is chronological. The last 10 rows of the training set have labels that reach into the test period, and the first rows of the test set share features with training rows whose labels already revealed the answer. The split looks clean. It is not.
Catch it: put an embargo gap of at least the label horizon between training and test — Marcos López de Prado's Advances in Financial Machine Learning (2018) calls this purging and embargoing, and the out-of-sample guide walks through it.
5. Data that already knows who survived
If the universe was built from what exists today, the dataset itself leaks: it contains only the assets that made it. Restated fundamentals, back-adjusted prices, and "cleaned" series that silently filled gaps carry the same problem in smaller doses. The backtest is not seeing tomorrow's bar, but it is seeing tomorrow's list of winners.
Catch it: rebuild the universe as it stood on each date, or test on a single asset that was always there. Details in the survivorship guide.
6. Leakage through you
You looked at the out-of-sample result, changed one thing, and ran it again. Then again. Each run leaked a little of the test period into your choices, and after twenty runs the "untouched" holdout has been touched twenty times. No line of code did it. Your eyes did.
Catch it: count. Write down every run against the holdout, and treat the best of twenty as "the best of twenty", not as a result. Then keep one final stretch of history that you genuinely never open until the strategy is frozen.
The six routes side by side
| Route | What it looks like | Fix |
|---|---|---|
| Same-bar fill | Trades at prices from before the signal | Fill at next bar's open |
| Repainting indicator | Past signals move when new bars arrive | Bar-by-bar replay; only closed-bar values |
| Global scaling | Score improves with every added feature | Fit scalers and PCA on training only |
| Overlapping labels | Clean-looking split, too-good first test rows | Embargo gap ≥ label horizon |
| Survivor data | Great on old data, universe built from today | Point-in-time universe |
| Researcher | Holdout consulted twenty times | Count runs; keep a sealed final stretch |
How to prove a backtest does not leak
You cannot prove a negative, but you can make leakage very unlikely with four checks that take minutes:
- The shift test. Delay every signal by one bar. A real edge degrades gracefully; a leaked one collapses.
- The shuffle test. Randomise the labels, retrain, and record the score. Do it ten times. Your real score should sit far outside that distribution. If it does not, the model is not learning from the features — and if it is still high, something else in the pipeline is feeding it the answer.
- The reconstruction test. Pick one trade and rebuild its decision by hand from raw closed bars up to the signal bar. Every feature value must be reproducible from that data alone.
- The recency test. Freeze the rules and run them forward on bars that did not exist when you built them. Time is the one holdout you cannot peek at.
What to expect when you fix it
Usually, disappointment. A leak-free result is smaller, noisier, and has a drawdown you can see without squinting. Many strategies do not survive the fix at all, and that is the fix working — the result you lost was never available to you.
What survives is worth more than what you had. A modest edge measured honestly compounds. A spectacular one measured with hindsight costs you exactly as much as you bet on it.
How Wise Apple handles leakage
The routes above are the reason Wise Apple's guardrails are defaults rather than options. Fills are scheduled for the bar after the decision. Feature scaling and Train-Only PCA are fitted on the training window alone. The chronological split carries Embargo Bars sized to the label horizon, and the Walk-Forward Window rolls the test forward so your eyes get fewer chances to leak. Sizing reads volatility and ATR from the bar before the fill, because reading the fill bar is a one-bar look-ahead too. There is also an experimental "training wheels" mode that does the opposite on purpose — leaks a few future candles and scales on the full series — so you can watch a clean result and a lying one side by side. Reports produced that way are permanently stamped, and the Alert Node refuses to run them.
Questions traders ask about data leakage
How do I know if my backtest has data leakage?
Run the shift test: delay every signal one bar and rerun. A genuine edge gets a little worse; a leaked one falls apart. Then shuffle the labels and retrain — if the model scores nearly as well on nonsense, the features are not where the skill came from. A result that is suspiciously good and keeps improving as you add features is the classic symptom.
What is the difference between data leakage and look-ahead bias?
They describe the same problem. Look-ahead bias is the older term and usually means the obvious case — using a price before it existed. Data leakage comes from machine learning and covers the subtle routes too: scalers fitted on the whole series, labels overlapping the test period, survivor-only universes. In a backtest, treat them as one thing.
Does normalising my features cause data leakage?
It does if the mean, standard deviation, or min/max were computed over data that includes the test period. Fit the scaler on the training window only and apply it forward. The same rule applies to PCA, feature selection, and any statistic derived from the series.
Can data leakage happen without machine learning?
Easily. Filling at the signal bar's close, using a repainting indicator, and testing on a universe built from today's survivors are all leakage, and none of them involve a model. The machine-learning versions are just harder to see.