Matana Labs

What is backtesting?

Backtesting means running a trading rule on past market data to see what it would have done: every entry, exit, profit and loss, as if you had traded it. It tells you whether an idea is clear enough to test and how it behaved in the past, but not whether it will keep working. A useful backtest has realistic fills and costs, and is checked on data it wasn’t tuned on.

The worked year: 16 trades, −8.8% before costs and −10.2% after, against −6.9% for buying and holding.
The worked year: 16 trades, −8.8% before costs and −10.2% after, against −6.9% for buying and holding.

How a backtest works, step by step

  1. Write the rule so a computer could follow it: when to enter, when to exit, how much to trade.
  2. Pick the data: the instrument, the period and the detail (daily, minute or second prices).
  3. Replay the past: the engine walks through the data in time order and acts on the rule only with what was known at that moment.
  4. Book the trades at the prices they would have filled at, minus commissions and slippage.
  5. Read the result: total return, drawdown, number of trades, win rate and more.

The most common mistake is step 3: letting the rule see the future, for example deciding at the open on a price that only appeared at the close.

A worked example: one rule, one year

Rule: hold the market while its closing price is above its 20-day average; sell when it closes below. We tested it on one year (252 trading days) of daily prices, trading at the close, with 0.05% of the trade value as commission and slippage on each side.

Here is the catch: the year is synthetic. We generated it as a random walk with no trend (a 1% typical daily move, fixed random seed), so the market had no pattern for the rule to find. Whatever the rule made or lost here is pure luck. That is the most important thing a beginner can learn about backtesting.

What one backtest can and can’t tell you

We ran the same rule on 1,000 synthetic years like the one above. It made money after costs in 39% of them. The median year was −3.2%; the best was +51.2% and the worst −28.7%. A rule with no edge at all still produced a +51.2% year somewhere in that list.

So a backtest can tell you that a rule is precise, that it trades as often as you expect, and how deep its drawdowns were. It can’t tell you, from one good period, that the rule has an edge. For that you need more data, out-of-sample tests and robustness checks.

1,000 years of the same rule on a market without trend: it made money in 39% of them, from −28.7% to +51.2%.
1,000 years of the same rule on a market without trend: it made money in 39% of them, from −28.7% to +51.2%.

Data detail: daily, minute or second

Daily data is enough for rules that act once a day at the close. Anything with stops, targets or intraday entries needs finer data, because a daily bar can’t tell whether your stop or your target was hit first, or what price you got after a gap. Our guide to 1-second vs 1-minute backtesting measures how often that changes the result.

Costs and slippage

Every trade pays a commission and usually some slippage: the difference between the price you wanted and the price you got. In the example, a modest 0.05% per side took 1.4 percentage points in one year from 16 round trips. Strategies that trade many times a day for small gains can look great before costs and lose money after. Always test with costs, then test again with costs doubled.

Overfitting in one picture

If you try enough variations of a rule on the same data, one of them will look excellent by chance. In our overfitting experiment, the best of 96 settings, picked on two years of a market with no edge, averaged +5.1% a year where it was picked and −1.4% in the year after. The backtest of the winner was real; its edge wasn’t.

How to check a backtest is robust

Matana Labs runs 31 such checks on a strategy and gives it a score out of 100; the full list is in the overfitting guide.

How to backtest without writing code

You don’t need to program. You can test by hand in a spreadsheet, replay charts, or use a rule builder that turns blocks or plain-English rules into an automated test. Our guide on how to backtest without coding compares the three and shows why the wording of a rule matters.

The numbers to read in a backtest report

Updated 2026-11-19. Educational content, not financial advice.

Keep reading

See Matana Labs plans, from free

Questions

What is backtesting in trading?

Running a trading rule on historical prices to see what it would have done, trade by trade, with realistic fills and costs. It shows how an idea behaved in the past; it does not guarantee how it will behave next.

Is backtesting reliable?

It is reliable at telling you what a precise rule would have done on the data you used. It is unreliable as proof of an edge from one period or one tuned setting: in our example a rule with no edge still made money in 39% of 1,000 random years.

How much data do I need for a backtest?

Enough for many trades in different market conditions. A rule that trades once a month needs many years; a rule that trades several times a day can be judged on less, but should still cover calm, volatile, rising and falling periods.

What is the difference between backtesting and paper trading?

A backtest replays the past quickly; paper trading follows the rule forward in real time with no money at stake. A forward test catches problems a backtest can hide, such as rules that quietly used future information.

Can I backtest for free?

Yes. A spreadsheet works for simple daily rules, and several platforms have free plans, including Matana Labs’s Explore plan. Check what data detail and history each free plan includes.