Home › Guides › How to Backtest a Trading Strategy

TESTING TRAPFREENO ACCOUNTAUTOMATED TRADE BOTSHow to Backtest aTrading StrategyWhy a good backtest can lieEDUCATION ONLY | NO SIGNALSEXAMPLE NUMBERS ARE LABELLEDAUTOMATED TRADE BOTSautomatedtradebots.com
A free page on how to backtest a trading strategy. Education only, with example numbers labelled.
TESTING TRAP

How to Backtest a Trading Strategy

Short answer

To backtest a trading strategy, write the rules so exactly that a program can follow them, run them over past data, and record every trade with its costs.

A backtest replays rules over past prices and counts what they would have done. It is only as honest as its rules, its data and its costs.

The page explains the idea in plain words, works through the arithmetic with a table, and shows how it hits grid, martingale and DCA bots, then tells you what to check before you run one.

  • A worked example with real arithmetic
  • How it hits grid, martingale and DCA bots
  • How to check for it before you run a bot
  • No advice, no signals, no profit promises

Last reviewed 28 October 2026. Education only, not advice.

Free, no account Runs in your browser Worked numbers shown Not advice Examples labelled

Ready to go further

Next: reshuffle your trade list

The Monte Carlo simulator reorders a list of trades many times to show how much of a backtest result depends on the order of wins and losses.

Reading time5 minutes
Worked exampleExact arithmetic
Tools linked1 on this page
Reviewed28 Oct 2026

What is included

  • What it is, in plain words
  • The formula or mechanism, with exact arithmetic
  • How it hits grid, martingale and DCA bots
  • A check you can run before you switch a bot on

Who it is for

  • People who run or plan to run a trading bot
  • Anyone reading a backtest or a bot sales page
  • Readers who want the numbers, not the pitch
  • Not advice, and not a signal service
Cumulative net result of 12 made-up backtest trades, after costs-203048120Trade numberMade-up trades, percent of the traded amount. Calculated by us on 29 Oct 2026, exact.
The picture for this page. Example numbers are made up unless the page says they were calculated.

Key facts

  • To backtest a trading strategy, write the rules so exactly that a program can follow them, run them over past data, and record every trade with its costs.
  • The result table needs more than a total: number of trades, win rate, average win, average loss, expectancy, profit factor and the worst fall from a peak.
  • In the made-up example below, 12 trades add up to +1.70 percent before costs and -0.10 percent after a 0.15 percent cost per trade. Costs took 1.80 points (calculated by us on 29 Oct 2026, exact).
  • Four traps ruin most backtests: look-ahead bias, survivorship bias, missing costs and overfitting.
  • A good backtest is not proof. It says the idea was not obviously broken on that data. The next test is forward testing or paper trading.

Step by step

1. Write the rules down

List what opens a trade, what closes it, how big it is, and what happens when two things clash. "Buy when it looks strong" cannot be tested. "Buy at the next open after the 14 bar RSI closes below 30; sell when it closes above 50 or after 10 bars" can. If you change a rule after seeing the result, you have started a new test, and you should count it as one.

2. Get clean data

You need the same bar size the bot will trade, with open, high, low, close and volume, covering more than one type of market. Check for gaps, bad ticks, and splits or contract rolls that make a price jump. Data can also differ from what you will trade live, since the quote you see from a broker is not the quote from another source.

3. Decide the fill rules before you run

Say at which price each order fills. A signal on a bar's close can only be traded at the next price, not the close itself. A limit order that the price only touched may not have filled in real life. A stop can fill worse than its level. Choose the pessimistic version when you are unsure.

4. Add every cost

Include the spread, commissions or fees, slippage and any overnight or funding charge. The table below shows what a small fixed cost does to a strategy with many small trades. The costs vary by broker and venue, so use the numbers from your own account.

5. Run it and keep the trade list

Save every trade with its entry, exit and result, not only the total. You will need the list to compute the rest and to see which trades carry the result.

6. Read the result table

Compute the number of trades, the win rate, the average win and loss, expectancy, profit factor and the max drawdown. A total with 8 trades behind it is a story, not a measurement.

7. Test it again on data you kept back

Split the data before you start. Build and tune on one part. Test once on the part you hid. If the hidden part is much worse, the tuning fit the noise.

A worked example on 12 made-up trades

A bot backtest produces the trade list below. Each result is a percent of the traded amount, and every figure is made up. The cost is 0.15 percent per trade, which stands in for the spread, the fee and slippage together. Everything was calculated by us on 29 Oct 2026 and is exact.

TradeGrossCostNetRunning total
1+1.20-0.15+1.05+1.05
2-0.80-0.15-0.95+0.10
3+0.60-0.15+0.45+0.55
4-0.80-0.15-0.95-0.40
5+2.00-0.15+1.85+1.45
6-0.80-0.15-0.95+0.50
7-0.80-0.15-0.95-0.45
8+0.90-0.15+0.75+0.30
9-0.80-0.15-0.95-0.65
10+0.70-0.15+0.55-0.10
11-0.80-0.15-0.95-1.05
12+1.10-0.15+0.95-0.10

The result table for the same list reads like this:

  • Trades: 12. This is too few to trust, and is used only to show the arithmetic.
  • Win rate: 6 winners of 12 before costs (50.0 percent). After costs, 6 (50.0 percent), because the cost turns no winner into a loser here.
  • Average win and loss, after costs: +0.93 and -0.95 percent.
  • Expectancy per trade: +0.14 percent before costs, -0.01 after. Total +1.70 before and -0.10 after.
  • Profit factor, after costs: 0.98. It is the sum of the winners divided by the sum of the losers.
  • Worst fall from a peak: 2.50 points, between the highest running total and the lowest point after it.

Look at how much the cost takes. It is the same 0.15 on every trade, and it removes 1.80 of +1.70. A bot that trades twice as often with the same edge per trade loses twice as much to cost. This is why a backtest with no costs is a common way to get a result that disappears live.

The same 12 trades before and after a 0.15 percent cost per trade (made-up)+1.70%Before costssum of 12-1.80%Cost drag12 x 0.15-0.10%After costssum of 12Made-up numbers. Costs take a fixed slice from every trade, so a strategy with many small trades is hit hardest. Calculated by us on 29Oct 2026, exact.
Costs are a fixed slice of every trade. They do not depend on whether the trade wins.

The traps, one by one

Look-ahead

The test uses information that was not available at the time of the trade. A common form is trading at a bar's close using an indicator that needs that same close. Another is using a daily high or low to decide an entry earlier the same day. The check: for each signal, ask what was known at that moment. See look-ahead bias.

Survivorship

The data only holds the instruments that still exist, so the ones that failed or were delisted are missing. A stock test run on today's index members looks better than one run on the members of that day. See survivorship bias.

Costs left out

See the example above. Add spread, fees and slippage to every trade, and test with higher costs as well. If the result vanishes when costs rise a little, it was thin.

Overfitting

Trying many settings and keeping the best one finds noise. As a made-up example, suppose a test of 12 settings gives results from -0.60 to +0.90, an average of +0.03. Reporting only the best, +0.90, hides the other eleven. The more settings and rules you try, the more likely the top one is luck. The fix is the data you kept back, simple rules, and settings that still work when moved a little. See overfitting.

What a backtest does not tell you

It does not tell you the future, how the market will treat your orders, or how you will behave in a losing run. A backtest also cannot show events that were not in the data. For a martingale or grid bot, whose worst case is rare, a clean backtest can hide a loss that ends the account. Run the result through the Monte Carlo simulator to see how the order of trades changes the fall.

FAQ

Frequently Asked Questions

How do I backtest a trading strategy?

Write exact rules, run them over clean past data with realistic fills and costs, save every trade, then read the trade count, win rate, expectancy, profit factor and max drawdown. Finally test once on data you held back.

How much data do I need to backtest?

Enough to give a few hundred trades and to include more than one type of market. A short sample with few trades gives a wide range of possible true results.

What are common backtest mistakes?

Leaving out costs, and using information that was not known at the time of the trade. Both make the past look better than it was.

Can I backtest in a spreadsheet?

Yes, for simple rules on daily data. Bots that trade often, or that depend on order fills, usually need code and tick or fine bar data.

Does a good backtest mean a bot will make money live?

No. It means the idea was not obviously broken on that data. Markets change, and live fills are worse than test fills, so forward testing comes next.

Are the numbers on this page real?

Example numbers are made up to show how the maths works, and the page says so. A figure only counts as exact when the page says it was calculated on a stated date. Nothing you enter in a calculator leaves your browser.

Can I use this to decide whether to run a bot?

It can show whether a bot's numbers hold together and how much an account can lose. It cannot say what the market will do, and it is not advice. Use it to ask better questions, then read the terms of your own broker or exchange.

Is this financial advice?

No. It is general education about testing. All the numbers are made up, and your data, costs and results will differ.

Know the Risk Before You Run It

Free calculators and guides, added every week. Leave your details and we will email you when new ones go up.

Trading carries a risk of loss