Day 20Backtesting your trades

Backtesting your trades

Day 20 of 26 · 11 min read · By DT Terminal

A backtest tells you whether your rules would have made money before you risk any. This lesson covers writing rules precise enough to test, replaying the chart tick by tick without looking ahead, how many trades to trust, the stats to read, the traps that make a backtest lie, and the path from backtest to demo to live.

Unlock the full lesson in the app

Worked examples, the quiz and the interactive tools are in the app. Free account.

Continue in the app, free
Chapter 1 of 7

What backtesting is, and what it is not

Backtesting finds out whether the strategy you wrote this week would have made money, before you trust it with any. Go back to a past date, hide everything after it, and step through one candle at a time, taking and writing down every trade your rules allow.

The loopfive steps, then round againReplay in the app
RULESwritten downbefore you startREPLAYtick by tickno peeking aheadRECORDevery tradethe same wayREVIEWthe statsand the missesADJUSTone thingor nothingnew sample, rules as writtenONE PASS = ONE SAMPLE
Each pass through the loop is one sample. Change one thing at most, then start a new sample, so you know what the change did.

A backtest is not:

  • A forecast. It shows how the rules behaved on the past you tested.
  • A search for perfect settings. Tweak until last year looks flawless and you have described last year.
  • Trading live. Nobody hesitates on a replay or moves a stop out of fear.
Go deeper

By now you have a whole strategy: the entry model with its stop and target, the volume filter and the golden zone as optional versions, the management rules, and a risk plan around it. In a backtest you take every trade exactly as you would live.

Markets change, so a result is an estimate, not a promise. And nobody skips a trade after three losses on a replay. Those habits are real, and only demo and live trading test them. The backtest cannot tell you whether you will follow the rules; it tells you which rules are worth following in the first place.

Chapter 2 of 7

Rules precise enough to test

A rule is testable when two people reading it would take the same trades, at the same prices, on the same chart. If it needs a decision in the moment, you are testing your mood. Rewrite each rule until nothing is left to decide. Here is the model from Day 15, rule by rule:

VagueTestable
Buy when the trend is upLong only after H4 makes a higher high and a higher low, while price holds above that higher low
Buy after the stops get runAn M15 wick trades below the equal lows, and that candle closes back above them
Wait for the turnAn M15 body then closes above the last lower high
Enter on the pullbackA buy limit at the top edge of the gap the shift left
Put the stop somewhere safeStop 2 pips below the sweep low. Skip the trade if that is more than 30 pips
Take profit when it looks doneTarget the next high, and only if it is at least 2R away. No early exit, no moving the target
Avoid the newsNo new trade from 15 minutes before to 15 minutes after a high-impact release for either currency
Do not overtradeAt most 2 trades a day, and stop after 2 losses

The structure in Day 10 and the news times in Day 6 test well: a point on the chart, or a time on the calendar.

Write the rules in Strategies first

Check your strategy against this table: entry rules and limits under Before the trade, the stop, target and management under In the trade. Rewrite any rule that still needs a decision in the moment.
Try it free in DT Terminal
Go deeper

A strategy's Rulebook has three phases: Before the trade holds the entry criteria, In the trade holds the stop, the target and how you manage it, and After holds what happens once it closes. Write each rule as something you could point at on a chart. Pick the strategy on the backtester's order ticket and its rules show under Rules followed, so every trade records which ones it met.

Chapter 3 of 7

Replay tick by tick, and record every trade

Bar replay shows the chart up to a point in the past, then reveals one candle at a time, so you decide with only what you could have seen. Scrolling a finished chart is not a backtest: your eye finds the winners and slides past the losers.

DT Terminal ChartsEURUSD · M15Replay paused
A replay frame as it looks in the backtester. Everything to the right of the last candle has not been played yet.

Your model says buy: a buy limit at 1.08800, stop 1.08640, target 1.09200. Press play. Then replay the same setups with the stop moved to breakeven, and compare the R.

Record every trade, losers and skipped setups too, with the same fields:

FieldWhy it is there
Date, time and instrumentTo find it again, and to see which sessions and markets carry the edge
Entry, stop and targetTo check the trade matched the rules, and to work out the R
Result in RThe one number every stat is built from, the same on any account size
Followed the rules: yes or noSeparates what the strategy did from what you did
Screenshot and a one line noteTo review the setup later, with what you saw at the time

Replay it in the backtester

Start a session and let Surprise me pick the start date. Play with Space, and press L or S to open a long or a short.
Try it free in DT Terminal
More on the replay and the record

In the frame above, the sweep, the shift and the gap have all closed, and price has not come back to the gap yet. The stop sits 2 pips below the sweep low and the target at the old high, which is at least 2R away. Record the ones you would rather forget too: a record that changes shape halfway through cannot be added up. Replaying the same setups under each management rule, hold or breakeven, is how you find which one your own trades favour.

In the backtester, a session needs an instrument, a start date and a starting balance. The 1y to 5y buttons and Surprise me pick the start date for you, so you cannot choose a stretch you remember. Set your risk per trade, commission and spread under More settings, then play with Space or step one candle with the arrow keys. After L or S, drag the stop and target into place, with economic news marked on the chart. Every trade is recorded in the session, and P drops a note while C saves a screenshot.

Chapter 4 of 7

How many trades before you trust it

As Day 9 showed, a handful of trades tells you almost nothing: luck is loud over a few and quiet over many. The likely range of a measured 40% win rate:

Sample sizea measured 40% win rate, and where the true one likely isReplay in the app
0%20%40%60%80%20 trades22% to 61%50 trades28% to 54%100 trades31% to 50%200 trades33% to 47%500 trades36% to 44%
Roughly 95% ranges. With 20 trades a 40% result is consistent with anything from a poor strategy to a strong one. With 500 it is pinned to a few points.
Trades in the sampleMargin, roughlyLikely true win rate
1026.0 pts17% to 69%
2019.7 pts22% to 61%
5013.1 pts28% to 54%
1009.4 pts31% to 50%
2006.7 pts33% to 47%
5004.3 pts36% to 44%
For a measured 40% win rate, roughly 95% ranges. The margin halves only when the sample is four times larger.

Worked example

Example 01: Is a 50% win rate at 1:1.5 an edge?

The worked example, with every number walked through, is in the app.

Go deeper

These are common rules of thumb, not magic numbers. A win rate close to breakeven needs a big sample before the two can be told apart.

Chapter 5 of 7

The stats to read

Once the sample is big enough, a few numbers describe it. Each answers a different question:

StatHow it is worked outWhat it tells you
Win rateWins divided by wins plus lossesHow often the rules are right. Meaningless without the size of the wins and losses
Average win and lossThe mean of the winners, and of the losers, in RThe reward to risk you actually got, not the one you planned
ExpectancyTotal R divided by the number of tradesWhat one trade is worth on average. Above zero after costs is an edge
Profit factorAll the winning R divided by all the losing RHow much the winners outweigh the losers. Above 1 makes money
Max drawdownThe biggest fall from a peak in the running totalThe worst stretch you would have had to sit through. Size your risk for it
Longest losing runThe most losses in a rowWhat your nerve and your daily limits must survive
Number of tradesA countHow far to trust every number above it

Worked example

Example 02: Ten trades, worked by hand

The worked example, with every number walked through, is in the app.

Interactive tool

Backtest stats calculator

This interactive tool runs in the app, with your own numbers.

The running total, and the three samples

No one of these stats is enough alone.

The running total goes 0, 2, 1, 0, −1, 1.5, 1.5, 0.5, 2.5, 1.5, 3.5. From the peak of 2 after trade 1 it falls to −1 after trade 4: a max drawdown of −3R, which is also the longest losing run, 3 in a row. The arithmetic is the same at 100 trades, and the calculator does it for any list.

Try the three samples. The 30 trades at 1:2 sample wins under half the time and still earns about a quarter of an R a trade. High win rate wins more than three trades in four and earns less, because each win is less than half the size of the average loss. Only 5 trades looks better than both, which is exactly why five trades are not a result.

Chapter 6 of 7

The traps that make a backtest lie

A backtest can be honest arithmetic on a dishonest test:

  • Curve fitting. Adding a filter for every losing stretch. Change one thing at a time.
  • Cherry picking. Testing the months you remember, or skipping setups. Take every trade the rules allow.
  • Looking ahead. Peeking right, or replaying a week you have seen. Decide on closed candles.
  • Ignoring costs. Spread and commission can wipe out a thin edge. Put them in the test.
  • Ignoring the news. A fill just before a major release is a different trade.
  • One kind of market. Test quiet, ranging and fast months, not just a trend.
Go deeper
  • Curve fitting: each tweak fits the noise of that stretch. Test the change on a stretch of data you have not used yet.
  • Cherry picking: testing the months you remember trending nicely, or quietly skipping a setup that "did not look right". Let something else pick the start date.
  • Looking ahead: glancing at the right side of the chart. Replay tick by tick.
  • Costs come off every trade, winners and losers.
  • News: a setup that fills a minute before a major release has wider spreads and slippage. Test it the way your rules say you would trade it, or skip it the way your rules say you would.
  • One kind of market: three months of a strong trend tells you how the rules do in a trend. Test across quiet months, ranging months and fast ones before you call it an edge.

Keep the old sample as it was, and let the new rules earn their own.

Chapter 7 of 7

From backtest to demo to live

A good backtest earns the next step, not real money. Each stage tests something the last could not:

StageWhat it testsMove on when
BacktestWhether the rules have an edge on past dataAt least 50 to 100 trades, a positive expectancy after costs, and a drawdown you could live with
Paper or demoWhether you can follow the rules in real time, with live spreads, news and no fast forwardSeveral weeks of trades by the rules, with results in the same range as the backtest
Live, small sizeWhether you still follow them when the money is realThe live record matches the practice one. Then raise size slowly

Expect live results a little below the backtest: worse fills, missed trades, hesitation. A small drop is normal. A large one means the live sample is still small, the market has changed, the edge was never there, or your execution differs. Your record tells you which. Practice in real time is covered in Day 7.

This is where your own record earns its place. Put your practice stats next to your real-money ones: your numbers show whether an edge holds live or decays.

Go deeper

A large drop is information. If the edge was never there, a bigger sample would have shown it. If your execution differs from your rules, your record will show it.

Keep backtests apart from your real P&L, and compare the two instrument by instrument: win rate, profit factor and expectancy from practice next to the same figures from real money.

Quick review

Check yourself

Quick review · 0 of 0

Try it on your own account

Connect your broker once and Edge learns from your trades, journal and practice to help you trade better in the live markets. Free to start.