Exchanges

Tools / Strategy backtester

Strategy backtester

Test a trading strategy on years of daily prices before you risk money on it. Pick any coin, currency pair, precious metal, share, oil, copper or US index fund, choose one of ten strategy templates or build rules of your own, and read the full report: net profit, yearly growth, deepest fall, win rate, profit factor, Sharpe ratio and every trade. Free, with nothing to sign up for.

Set up a test

1. The market
2. The strategy

Buys when the 50-day simple moving average closes above the 200-day one, and sells when it closes back below.

3. The period
4. Stops, if you want any
5. Costs and capital

Start again

Moving average crossover on Gold

Between 5 Jan 1999 and 26 Nov 2026, $10,000.00 grew to $81,055.65: a gain of 710.56% over 18 trades. That is +7.79% a year, compounded. Buying and holding over the same days gained 1,163.04%. 18 trades are too few to tell skill from luck.

Net profit
+710.56%
+$71,055.65
Growth a year (CAGR)
+7.79%
Deepest fall
−37.52%
6 Sept 2011 – 11 Jul 2017
Trades
18
Win rate
50.0%
9 won, 9 lost
Profit factor
4.92
Buy and hold
+1,163.04%
$126,303.66
Against buy and hold
−452.48%

All the figures

Starting capital$10,000.00
Final equity$81,055.65
Gross profit$89,179.24
Gross loss−$18,123.60
Average trade+$3,947.54 (+15.98%)
Average win+$9,908.80
Average loss−$2,013.73
Payoff ratio4.92
Largest winning trade+$40,389.90 (+99.32%)
Largest losing trade−$4,499.63 (−10.80%)
Longest winning streak5
Longest losing streak5
Average time in a trade273.9 days
Average time in a winning trade448.6 days
Average time in a losing trade99.3 days
Time in the market67.9%
Sharpe ratio (monthly, TradingView’s method)0.14
Sharpe ratio, annualised (× √12)0.47
Sortino ratio (monthly, TradingView’s method)0.24
Sortino ratio, annualised (× √12)0.83
Calmar ratio0.21
Commission paid$0.00

The trades

No.SideEntryExitDaysReturnProfitClosed byEquity
18Long6 Dec 2023
2,028.72
29 Jun 2026
4,043.68
668+99.32%+$40,389.90Signal$81,055.65
17Long13 Jan 2023
1,891.99
29 Sept 2023
1,880.63
185−0.60%−$245.59Signal$40,665.75
16Long15 Feb 2022
1,863.58
7 Jul 2022
1,751.55
102−6.01%−$2,616.72Signal$40,911.34
15Long3 Dec 2021
1,773.09
28 Jan 2022
1,806.91
40+1.91%+$814.74Signal$43,528.06
14Long28 Jun 2021
1,780.70
11 Aug 2021
1,731.98
32−2.74%−$1,201.57Signal$42,713.32
13Long18 Jan 2019
1,290.71
18 Feb 2021
1,785.10
544+38.30%+$12,162.33Signal$43,914.89
12Long15 May 2017
1,230.62
27 Jun 2018
1,257.97
292+2.22%+$690.40Signal$31,752.56
11Long1 Mar 2016
1,239.68
23 Nov 2016
1,209.04
191−2.47%−$787.35Signal$31,062.15
10Long2 Jul 2014
1,326.47
23 Sept 2014
1,217.28
59−8.23%−$2,856.99Signal$31,849.50
9Long24 Mar 2014
1,332.23
4 Jun 2014
1,244.57
52−6.58%−$2,444.59Signal$34,706.49
8Long21 Sept 2012
1,765.55
22 Feb 2013
1,574.81
110−10.80%−$4,499.63Signal$37,151.08
7Long28 Feb 2012
1,770.30
17 Apr 2012
1,655.38
35−6.49%−$2,891.39Signal$41,650.71
6Long12 Feb 2009
929.5539
14 Feb 2012
1,722.75
783+85.33%+$20,508.32Signal$44,542.10
5Long22 Dec 2006
620.3175
3 Sept 2008
800.5445
443+29.05%+$5,410.74Signal$24,033.78
4Long18 Aug 2005
440.1901
23 Oct 2006
594.2348
307+35.00%+$4,827.69Signal$18,623.05
3Long5 Oct 2004
413.9729
1 Jun 2005
415.7864
171+0.44%+$60.17Signal$13,795.36
2Long30 May 2001
269.6248
8 Jun 2004
393.1268
789+45.81%+$4,314.95Signal$13,735.19
1Long26 Oct 1999
281.3265
5 May 2000
265.0162
128−5.80%−$579.76Signal$9,420.24

This market has one price a day here: signals are filled at the next day’s close, stops are tested against each close, and the ATR is the average close-to-close move.

Daily reference rates published by the European Central Bank and other central banks, compiled by Frankfurter. Reference rates are not prices you could have traded at.

How the test is run

A backtest replays a rule over past prices: it shows what the rule would have done, not what it will do. Every test here follows the same fixed rules, so that two results can be compared.

Fills. A signal is read on a day’s closing price and filled at the next day’s opening price, never on the day that gave it; a signal on the last day makes no trade. Coins, currencies and metals have one price a day here, so their signals are filled at the next day’s close.

Position. One position at a time, with all of the capital in it, so gains and losses compound. Long only unless you choose short, or long and short. A position still open on the last day is closed at that day’s close. A trade’s days are days that have a price: trading days, not calendar days.

Stops. A stop-loss, take-profit or trailing stop is tested against each day’s high and low. If a day opens beyond the level, the fill is the open (a gap), not the level. If one day holds both the stop and the target, the stop is taken: the cautious reading. The trailing stop follows the highest high since the entry, by a percentage or by a multiple of the 14-day ATR. Where there is only one price a day, levels are tested against each close and filled there, and the ATR is the average close-to-close move.

Costs. Each buy and each sell pays the commission and is filled worse than the quoted price by the slippage. Unless you change them: commission 0.10% and slippage 0.05% for crypto, commission 0.05% and slippage 0.05% for shares and funds, commission 0.00% and slippage 0.02% for currencies and metals. Borrowing costs, dividends, interest, spreads wider than the slippage and taxes are not counted.

Buy and hold, the yardstick, buys at the test’s first possible fill, pays no costs and holds to the last day.

What the figures mean

Growth a year (CAGR) is (final ÷ starting capital) to the power of 365 ÷ days, less 1. The deepest fall (maximum drawdown) is the largest drop of the equity from an earlier high, measured on closing values. Profit factor is the winning trades’ total divided by the losing trades’ total. The average trade is the net profit divided by the number of trades.

The Sharpe ratio is worked out as TradingView’s strategy tester does: the average monthly return of the equity less a risk-free 2% a year (a twelfth a month), divided by the standard deviation of the monthly returns. It is a monthly figure; the annualised one multiplies it by the square root of 12. The Sortino ratio divides by the deviation of the months that fell short of the risk-free rate only. The Calmar ratio is growth a year divided by the deepest fall.

What a backtest cannot tell you

Past results do not predict future ones. A rule tuned until it fits the past will usually disappoint afterwards, and a result built on a handful of trades means little: look for dozens. The markets on this site are ones that exist today, so coins and companies that failed are missing (survivorship bias), which flatters any test of buying.

Share prices are adjusted for splits but not for dividends, so a long test of a share that pays dividends understates what a holder earned. Coin history on this site reaches back two years. Currency and metal prices are daily central bank reference rates, not prices anyone could trade at. Short selling is tested without borrowing fees or margin calls.

An estimate for study, not investment advice. Nothing you enter leaves your browser except the address of this page.

All trading tools