Backtest a rule — see exactly how it would have traded.
We replay a trading rule bar-by-bar over the price path and show the full record: every trade, the equity curve, your win rate, average R, profit factor and max drawdown — plus notes on what each number means. The demo rule is a 20-day moving-average crossover (long when price closes above its 20-day average, exit when it closes below, with an 8% stop). Fills happen at the bar close, so there is no look-ahead, replayed on real multi-year daily history (1256 bars).
Equity curve — the rule's running NAV
| Sharpe | 0.87 | Sortino | 1.27 |
| Calmar | 0.47 | Annualized | +30.24% |
| Avg win | +17.33% | Avg loss | -3.59% |
Fills execute at the bar CLOSE on the signal bar — no look-ahead. Profit factor = gross gains ÷ gross losses; avg R = average win ÷ average loss; max drawdown = the deepest peak-to-trough fall in this curve.
The rule under test
Trade ledger — every fill the rule made
| # | Entry bar | Exit bar | Held | Return | Why exit |
|---|---|---|---|---|---|
| 1 | 21 @ 199.50 | 22 @ 194.58 | 1 bars | -2.47% | rule |
| 2 | 24 @ 197.98 | 44 @ 219.00 | 20 bars | +10.62% | rule |
| 3 | 48 @ 224.82 | 49 @ 220.81 | 1 bars | -1.78% | rule |
| 4 | 63 @ 217.46 | 98 @ 306.93 | 35 bars | +41.14% | rule |
| 5 | 100 @ 324.27 | 102 @ 304.90 | 2 bars | -5.97% | rule |
| 6 | 113 @ 309.45 | 116 @ 295.86 | 3 bars | -4.39% | rule |
| 7 | 118 @ 301.21 | 119 @ 292.90 | 1 bars | -2.76% | rule |
| 8 | 143 @ 251.08 | 146 @ 239.49 | 3 bars | -4.62% | rule |
| 9 | 147 @ 242.67 | 151 @ 236.42 | 4 bars | -2.58% | rule |
| 10 | 168 @ 244.96 | 183 @ 244.07 | 15 bars | -0.36% | rule |
| 11 | 218 @ 178.51 | 228 @ 169.74 | 10 bars | -4.91% | rule |
| 12 | 251 @ 157.62 | 268 @ 170.86 | 17 bars | +8.40% | rule |
| 13 | 269 @ 180.97 | 276 @ 178.49 | 7 bars | -1.37% | rule |
| 14 | 307 @ 131.67 | 310 @ 121.14 | 3 bars | -8.00% | stop |
| 15 | 320 @ 124.66 | 359 @ 165.71 | 39 bars | +32.93% | rule |
| 16 | 374 @ 159.09 | 402 @ 206.55 | 28 bars | +29.83% | rule |
| 17 | 404 @ 236.64 | 437 @ 264.95 | 33 bars | +11.96% | rule |
| 18 | 440 @ 270.02 | 443 @ 271.04 | 3 bars | +0.38% | rule |
| 19 | 448 @ 272.26 | 491 @ 408.22 | 43 bars | +49.94% | rule |
| 20 | 492 @ 423.02 | 514 @ 442.69 | 22 bars | +4.65% | rule |
| 21 | 527 @ 469.67 | 540 @ 455.72 | 13 bars | -2.97% | rule |
| 22 | 556 @ 447.82 | 557 @ 435.17 | 1 bars | -2.82% | rule |
| 23 | 558 @ 440.41 | 567 @ 439.38 | 9 bars | -0.23% | rule |
| 24 | 579 @ 435.06 | 598 @ 467.70 | 19 bars | +7.50% | rule |
| 25 | 607 @ 480.88 | 620 @ 475.69 | 13 bars | -1.08% | rule |
| 26 | 622 @ 490.97 | 653 @ 674.72 | 31 bars | +37.43% | rule |
| 27 | 654 @ 785.38 | 681 @ 894.52 | 27 bars | +13.90% | rule |
| 28 | 688 @ 906.16 | 689 @ 881.86 | 1 bars | -2.68% | rule |
| 29 | 699 @ 877.35 | 702 @ 830.41 | 3 bars | -5.35% | rule |
| 30 | 703 @ 858.17 | 729 @ 789.52 | 26 bars | -8.00% | stop |
| 31 | 748 @ 131.38 | 750 @ 127.40 | 2 bars | -3.03% | rule |
| 32 | 751 @ 129.24 | 753 @ 126.36 | 2 bars | -2.23% | rule |
| 33 | 773 @ 116.14 | 787 @ 108.00 | 14 bars | -7.01% | rule |
| 34 | 794 @ 119.14 | 796 @ 116.78 | 2 bars | -1.98% | rule |
| 35 | 799 @ 117.87 | 800 @ 116.00 | 1 bars | -1.59% | rule |
| 36 | 801 @ 116.26 | 829 @ 132.76 | 28 bars | +14.19% | rule |
| 37 | 832 @ 139.91 | 840 @ 141.98 | 8 bars | +1.48% | rule |
| 38 | 842 @ 147.01 | 845 @ 141.95 | 3 bars | -3.44% | rule |
| 39 | 852 @ 145.14 | 854 @ 142.44 | 2 bars | -1.86% | rule |
| 40 | 865 @ 139.67 | 868 @ 137.01 | 3 bars | -1.90% | rule |
| 41 | 869 @ 137.49 | 870 @ 134.29 | 1 bars | -2.33% | rule |
| 42 | 871 @ 138.31 | 876 @ 135.91 | 5 bars | -1.74% | rule |
| 43 | 881 @ 137.71 | 886 @ 126.69 | 5 bars | -8.00% | stop |
| 44 | 896 @ 133.57 | 906 @ 126.63 | 10 bars | -5.20% | rule |
| 45 | 907 @ 131.28 | 908 @ 120.78 | 1 bars | -8.00% | stop |
| 46 | 925 @ 121.41 | 927 @ 113.76 | 2 bars | -6.30% | rule |
| 47 | 937 @ 114.33 | 938 @ 105.18 | 1 bars | -8.00% | stop |
| 48 | 939 @ 110.93 | 942 @ 102.06 | 3 bars | -8.00% | stop |
| 49 | 947 @ 106.43 | 1027 @ 175.64 | 80 bars | +65.03% | rule |
| 50 | 1031 @ 179.81 | 1035 @ 174.18 | 4 bars | -3.13% | rule |
| 51 | 1042 @ 177.33 | 1046 @ 174.88 | 4 bars | -1.38% | rule |
| 52 | 1048 @ 176.24 | 1066 @ 180.03 | 18 bars | +2.15% | rule |
| 53 | 1074 @ 186.26 | 1083 @ 188.08 | 9 bars | +0.98% | rule |
| 54 | 1085 @ 199.05 | 1088 @ 186.86 | 3 bars | -6.12% | rule |
| 55 | 1104 @ 185.55 | 1107 @ 180.93 | 3 bars | -2.49% | rule |
| 56 | 1113 @ 180.99 | 1129 @ 183.14 | 16 bars | +1.19% | rule |
| 57 | 1130 @ 187.05 | 1132 @ 178.07 | 2 bars | -4.80% | rule |
| 58 | 1135 @ 187.67 | 1141 @ 185.61 | 6 bars | -1.10% | rule |
| 59 | 1145 @ 185.41 | 1150 @ 182.81 | 5 bars | -1.40% | rule |
| 60 | 1152 @ 187.98 | 1158 @ 184.89 | 6 bars | -1.64% | rule |
| 61 | 1167 @ 186.03 | 1168 @ 183.14 | 1 bars | -1.55% | rule |
| 62 | 1184 @ 177.64 | 1205 @ 196.50 | 21 bars | +10.62% | rule |
| 63 | 1206 @ 207.83 | 1220 @ 212.60 | 14 bars | +2.30% | rule |
| 64 | 1223 @ 224.36 | 1225 @ 214.75 | 2 bars | -4.28% | rule |
| 65 | 1248 @ 204.12 | 1255 @ 202.81 | 7 bars | -0.64% | eod |
Exit reasons: rule = the exit predicate fired; stop = the protective stop was hit; target = the take-profit was hit; eod = closed at the last bar. Bar index = position in the price path, not a calendar date.
Backtest glossary
- Backtest
- Replaying a fixed set of trading rules over historical prices to estimate how they would have performed.
- Sharpe ratio
- Annualised return divided by the volatility of returns — reward per unit of total risk.
- Sortino ratio
- Like Sharpe but only counts downside volatility in the denominator.
- Calmar ratio
- Annualised return divided by the maximum drawdown — reward per unit of worst-case pain.
- Max drawdown
- The largest drop from a peak in the equity curve to a subsequent trough.
- Profit factor
- Gross profit divided by gross loss; above 1 means the strategy is net profitable.
- Exposure
- The fraction of bars the strategy was actually in a position (capital at work).
- Stress test
- Re-running the strategy on a deliberately worse price path to see if it survives bad conditions.
- Sim-to-live promotion
- The gate that decides whether a paper-traded rule-set is trustworthy enough to run with real consequences.