Home › Guides › Backtesting a Trading Bot

TESTING TRAPFREENO ACCOUNTAUTOMATED TRADE BOTSBacktesting aTrading BotWhy a good backtest can lieEDUCATION ONLY | NO SIGNALSEXAMPLE NUMBERS ARE LABELLEDAUTOMATED TRADE BOTSautomatedtradebots.com
A free page on backtesting a trading bot. Education only, with example numbers labelled.
TESTING TRAP

Backtesting a Trading Bot

Short answer

Backtesting runs a trading strategy over past prices to see what it would have done. It tests the idea cheaply, before any money is risked.

A backtest replays a strategy on old prices. It is the cheapest test there is, and the easiest to get wrong.

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: stress the result

The Monte Carlo simulator reshuffles trades to show how much of a backtest result is luck in the order of wins and losses.

Reading time4 minutes
Worked exampleExact arithmetic
Tools linked2 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
Chance that at least one of n useless settings looks significant (5% test)5.0%1 settingtried22.6%5 settingstried40.1%10 settingstried64.2%20 settingstried92.3%50 settingstriedChance = 1 - 0.95^n, for independent tests of settings that have no edge. Calculated by us on 28 Oct 2026, exact.
The picture for this page. Example numbers are made up unless the page says they were calculated.

Key facts

  • Backtesting runs a trading strategy over past prices to see what it would have done. It tests the idea cheaply, before any money is risked.
  • A backtest is only as honest as its costs and its data. Leaving out spread, slippage and fees makes almost any strategy look good.
  • Trying many settings and keeping the best one is a trap. If 20 useless settings are each tested at a 5 percent significance level, the chance that at least one looks significant by luck is 64.2 percent (calculated by us on 28 Oct 2026, exact).
  • The check that matters is data the bot never saw while it was being tuned. In the made-up example below, 0.18 R gross per trade on tuned data became 0.07 R on fresh data.
  • A passed backtest is a reason to test further, with forward testing, and not a reason to trade it.

What a backtest is

A backtest feeds historical prices to a strategy and records the trades it would have taken. From those trades you read the win rate, the average result, the drawdown and the number of trades. It is quick and free, so it is where most bot ideas are first tested and where most of them should be dropped.

The steps

  1. Write the rules first. Entry, exit, size and stop, in plain words, before looking at any result.
  2. Choose the data. Enough history to include more than one type of market, and clean data, with the price used at each step being one that was known at that moment.
  3. Add the costs. The full spread, a slippage allowance, commission and, for futures, funding. Use the pessimistic version.
  4. Split the data. Tune on one part and keep a later part untouched until the end.
  5. Run once on the held-back part. The result is what you carry forward. If you change the rules after seeing it, that part is no longer fresh.
  6. Look at the shape, not only the total. Drawdown, the longest losing run and how the result is spread across time.

Reading the result

Start with the number of trades, then the average result per trade after costs, then the worst drawdown and the longest losing run. A high total profit from a small number of trades is weak evidence, because one or two large wins can carry it. Check how much of the profit comes from the best five trades. Then ask whether you could stand the worst drawdown in the test, since a live account will usually see a worse one than the test did.

The costs a backtest must carry

A strategy that earns a small gross amount per trade is the one most hurt by costs. Take the made-up bot below. On tuned data it earns 0.18 R gross per trade, and a cost of 0.06 R takes that to 0.12 R net. On fresh data it earned 0.07 R gross, which is 0.01 R net, a result so close to zero that a different cost assumption would flip it.

Net per trade = gross per trade - costs
Tuned data: 0.18 - 0.06 = 0.12 R
Fresh data: 0.07 - 0.06 = 0.01 R
The same made-up bot on the data it was tuned on and on fresh data0.12 RTuned datagross 0.18 R0.01 RFresh datagross 0.07 RMade-up numbers, with a cost of 0.06 R per trade taken from both. Net = gross - cost. Calculated by us on 28 Oct 2026, exact.
The fall from the tuned data to the fresh data is the sign that some of the first result was fitted to noise. The cost then takes most of what is left.

The traps

  • Too many tries. Each extra setting you test is another chance of a lucky result. The picture at the top shows 40.1 percent at 10 tries and 92.3 percent at 50 for settings with no edge at all. This is overfitting.
  • Peeking at the future. A rule that uses a value not known at the time, such as a candle's final high, is look-ahead bias, and it can make a backtest look perfect.
  • Only the survivors. Testing on instruments that still exist leaves out the ones that failed. See survivorship bias.
  • Too few trades. A result from thirty trades has a wide range around it. The win rate calculator shows how wide.
  • Perfect fills. A backtest that fills a limit order whenever the price touches it ignores the queue. Real fills are rarer.
  • Bots with ladders. A martingale or grid backtest can look smooth for years and then show one large loss. Check the worst case, not only the average.

What a good backtest does and does not tell you

It tells you that the idea was not obviously broken on that data after those costs. It does not tell you the future. Markets change, and an edge that worked for one regime may not for the next. The next step is a forward test or a paper run, then a small live trial. To see how much the order of trades alone changes the outcome, run the Monte Carlo simulator.

FAQ

Frequently Asked Questions

What is backtesting?

Running a trading strategy over past prices to see what trades it would have taken and what they would have earned. It is a cheap first test of an idea.

How do I know if a backtest is overfitted?

Hold back a later part of the data and test on it once, after the settings are fixed. A large fall in the result on the held-back data is the sign.

What costs should a backtest include?

The spread, a slippage allowance, commission and fees, and funding on futures. Use pessimistic values, since real costs are usually higher than the ones a simple test assumes.

How many trades does a backtest need?

More is better. A few dozen trades leave a wide range around any win rate, and hundreds narrow it a lot. The number of trades matters as much as the length of time.

Does a good backtest mean a bot will make money?

No. It means the idea was not obviously broken on past data after the costs you included. Forward testing is the next check.

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. The numbers are made up and your data and costs 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