What is backtesting? How it works and what it can tell you
By Bec, futures trader and founder of Wildflower · Updated
Backtesting means running a trading strategy’s exact rules over past prices to see which trades they would have taken. A backtest shows where each trade would have entered and exited, and what that would have added up to under the costs and fills it assumes. It can’t tell you what will happen next.
What backtesting is
A Running a strategy’s exact rules over past prices to see which trades they would have taken.More in the glossary takes a set of trading rules and applies them to past prices, one One bar on a price chart. It shows where price opened and closed, and the highest and lowest it reached, in one stretch of time.More in the glossary at a time, as if you were trading back then. Every time the rules say “enter”, it opens a trade. Every time they say “exit”, it closes one. At the end you have a list of trades the rules would have taken.
The rules have to be exact. “Buy when it looks strong” can’t be tested. “Buy when a candle closes above the highest high of the three candles before it” can. The pictures on this page use that made-up rule, with a stop 2 points below the entry and a target 3 points above. It’s only there to show how a backtest works.
The name is plain: you test the rules back in time. A backtest is also called a historical test or a strategy test.
How a backtest works, step by step
1. Write exact rules
Here: find the highest high of the last three candles.
2. Walk forward one candle
The test only sees candles that have closed. Candle 4 closes above the line: a signal.
3. Enter at the next price
The trade opens at the next candle’s open, 102.50, with its stop and target.
4. Exit at the stop or target
Two candles later, price trades through 105.50. The trade closes at its target.
Then it carries on to the next candle, and the next, to the end of the history. The pictures take one trade at a time, so signals while a trade is open are ignored. That’s a rule too, and it has to be written down like the others.
What a backtest can tell you
- Whether the rules do what you meant. Seeing every trade on a chart shows mistakes fast, like a stop on the wrong side or a rule that never fires.
- How often the rules trade, and at what times of day.
- How the trades played out on that history: how far each one went for and against, and the biggest drop from a high in the test, called the maximum A fall in an account’s balance from a high point. On a funded account, it also names the loss limit the balance has to stay above.More in the glossary.
- What changes when you change one rule. Run two versions on the same history and compare the trades.
- How much costs matter to these rules, if you include What your broker and the exchange charge for each contract you trade, often quoted per contract for the round trip: in and out.More in the glossary and slippage.
What a backtest can’t tell you
What happens next. Markets change. A backtest describes how rules behaved on one stretch of history. It can’t prove a strategy will behave the same way in the future.
Your exact fills. A backtest has to guess how each order would have filled. Live, your orders meet a real market. Read why backtest and live results differ.
How it feels. A run of losses looks small in a table. Living through it with real money is different, and a backtest can’t measure that.
The assumptions inside every backtest
A candle only records four prices: open, high, low and close. It doesn’t say what happened in between. So every backtest has to make choices about fills. These are the main ones:
- When a trade enters. A signal at a candle’s close can only be traded after that close. Some tests fill at the close price, some at the next candle’s open. Live, the first price you can get comes after the signal.
- Market and stop orders. They fill at the next price available, which can be worse than the price you wanted. That difference is The difference between the price you expected and the price your order filled at.More in the glossary.
- Limit orders and targets. Price touching your level doesn’t mean your order filled. Some tests count a touch, some need price to trade through.
- Stop and target in one candle. Like the picture above. Some tests count the stop, some the target, some look at smaller candles to find out.
- The spread. Charts show traded prices. You buy at the ask and sell at the bid. Read about the spread.
- Fees. Commissions and exchange fees per contract, in and out.
None of these choices is wrong on its own. What matters is knowing which ones your test made. Each one that leans your way makes the results look better than live trading could.
Mistakes that make a backtest look better than it was
Look-ahead. A backtest mistake: using a price the strategy couldn’t have known yet at the moment it made its decision.More in the glossary is using a price the strategy couldn’t have known yet. On the left, the rule needs the candle’s close to decide, but the test buys at that candle’s open. It quietly gets a better price than anyone could have. Look-ahead can also hide in an indicator that uses a candle before it has closed.
Overfitting. Tuning a strategy’s rules so closely to one stretch of past prices that they describe that stretch’s quirks more than anything that carries on.More in the glossary is adjusting rules until they fit one stretch of history very closely. Change enough numbers and almost any rules can be made to look good on past prices. The result describes the past, not anything that carries on. Read about overfitting.
Too few trades. With a small How many trades a test is based on. A small sample can look very different from a larger one just by chance.More in the glossary, a few lucky or unlucky trades can swing the whole result. There’s no single number that’s enough. Read about sample size.
Prices that never traded. A continuous futures chart joins one contract to the next, and some platforms shift the older prices to line them up. Stops and targets can then land on prices that never traded.
One kind of market. A test over one calm month, or one strong trend, only shows how the rules behaved in that kind of market.
Keeping some history back
One way traders check for overfitting is to split the history. They build and adjust the rules on the first part, called in-sample. Then they test once on the part they kept back, called out-of-sample, without changing anything. If the kept-back part looks very different, the rules may fit the first part’s quirks. Read about in-sample and out-of-sample testing.
Walk-forward testing repeats that split many times, moving forward through the history. Read about walk-forward testing.
Manual and automated backtesting
Automated backtesting. Software runs the exact rules over the whole history in seconds. It needs rules with no judgement left in them.
Manual backtesting. You step through a chart candle by candle, with the future hidden, and note each trade yourself. It’s slower, and it’s also called replay. It suits rules that still have some judgement in them. Read about forward testing and replay.
Backtesting a strategy without code
See every trade your own rules would have taken
Describe your strategy in plain words, build it from building blocks, or bring it from an indicator you’ve made. Wildflower’s Backtest runs your rules over past prices and draws every trade on the chart with its entry, stop and target. Open any trade to see it on its own, and ask why a candle had no trade. Enter your own fee per contract for the round trip and extra slippage in ticks, and every result says what it assumed about fills. No coding needed.

Set it up and see how it works, free. Only pay when you backtest on real market history.
Common questions
What is backtesting in simple terms?
Running a strategy’s rules over past prices to see which trades they would have taken.
Does a good backtest mean a strategy will make money?
No. It shows how the rules behaved on past prices, under the fills it assumed. The future can be different.
What’s the difference between backtesting and forward testing?
A backtest runs on past prices. A forward test runs the rules on new prices as they happen, on a demo or small account, without looking back.
How much history do I need for a backtest?
There’s no single rule. More trades, across different kinds of market, give the result less room to be luck. Read about sample size.
What is look-ahead bias?
Using a price the strategy couldn’t have known yet at the moment it decided. It makes a backtest look better than any real trading could.
What is overfitting in backtesting?
Adjusting rules until they fit one stretch of history very closely, so they describe its quirks more than anything that carries on.
Should a backtest include slippage and fees?
A backtest without them assumes every fill was free and perfect, which live trading isn’t. Whether and how much to add is your choice.
Can I backtest without coding?
Yes. Some tools let you describe the rules in plain words or build them from parts. Wildflower’s Backtest does both. See Backtest.
What’s the difference between manual and automated backtesting?
Automated runs the exact rules in software. Manual means stepping through a chart yourself and noting each trade.