Backtesting

How to backtest a trading strategy, free on TradingView and MT5

Nathan · RB Trading Updated 9 Nov 2026 15 min read
Price charts on a trading screen, with the title How to backtest
Photo: Lorenzo Cafaro, CC0, via Wikimedia Commons

Backtest a trading strategy in four steps: write its rules down, replay past charts bar by bar with the future hidden, log every trade the rules give in R, then work out the average R per trade. Yes, it can be free: TradingView's free plan replays daily and higher charts, and MetaTrader 5's Strategy Tester is free.

This guide covers both free routes step by step: what TradingView's free plan does and does not include for Bar Replay (checked on TradingView's own pages on 9 Nov 2026), the MT5 Strategy Tester and its tick modes, how many trades a backtest needs, worked out with simple statistics, and a 20-trade example log scored in R.

Backtesting AAPL in the journal: pick the symbol and date, place entry and stop, replay bar by bar to the result, then log the trade.

Most traders "backtest" by scrolling through old charts, noting where they would have entered, and deciding the strategy works. That is not backtesting. It is hindsight dressed up as research, because you can see what happened next. A real backtest has structure that stops you lying to yourself.

The two ways to backtest

1. Manual bar-by-bar replay

You walk through past price action one candle at a time, with future candles hidden. At each candle you decide: take a trade or not? If yes, where is the stop, where is the target, what is the size? You record the result, then repeat until you have enough trades (the section on how many trades you need shows how to work that out).

This is the way to backtest discretionary strategies (chart patterns, price action, intraday judgement), because those decisions are hard to code. If you use your eyes to trade live, use your eyes, with the future hidden, to backtest.

2. Automated backtesting (Pine Script, Expert Advisors, Python)

You write code that defines exact entry and exit rules. The code runs over past data and gives you a report. This is the way to test mechanical strategies: fixed rule sets, indicator crossovers, algorithms. On TradingView the code is Pine Script; on MetaTrader 5 it is an Expert Advisor.

How to backtest on TradingView for free

TradingView's free plan is called Basic. It gives you both tools: Bar Replay for manual testing and the Strategy Tester for coded strategies (its results tab is called "Strategy Report"). The catch is how much history the free plan can replay.

What the free plan includes for Bar Replay

From TradingView's pricing page, Bar Replay and Strategy backtesting rows, checked on 9 Nov 2026. TradingView can change its plans, so check the page before you rely on it.

FeatureBasic (free)EssentialPlusPremiumUltimate
History by day and higher timeframesAllAllAllAllAll
History by the minuteNo180 days365 daysAllAll
History by the secondNoNoNoAllAll
History by the tickNoNoNoNo7 days
Indicators replayYesYesYesYesYes
Trading in bar replayYesYesYesYesYes
Strategy backtesting: basic report metricsYesYesYesYesYes
Advanced report metricsNoYesYesYesYes
Deep backtestingNoNoNoYesYes
Historical bars available5K10K10K20K40K

Free Bar Replay, in short

TradingView's help centre says the same from the other side. Its page on how much data Bar Replay has says daily and daily-based intervals show all available data, and that intraday depth depends on the plan: Essential gets 6 months of 1-minute data and Plus gets a year. So on the free plan, test a daily (or weekly) strategy, or upgrade before you test an intraday one.

Bar Replay, step by step

  1. Open a chart of the market you will trade, on the daily timeframe.
  2. Click Bar Replay on the top panel of the chart. The replay panel opens and the chart waits for a starting point.
  3. Click the date to start from. Everything after it is hidden.
  4. Click Forward to move one bar at a time. Play runs bars on their own, at a speed you set; for a backtest, stepping is safer, because you decide at every bar.
  5. When your setup appears, write entry, stop and target before the next bar. Then step on until the stop or target is hit, and log the result in R.

Two limits from TradingView's Bar Replay help page: it does not work with spread charts or tick-based charts, and non-standard chart types are not compatible with it.

The Strategy Tester, for coded rules

  1. Add a strategy to the chart. Use a built-in one, one from Community Scripts, or your own, written in Pine Script.
  2. Open the Strategy Report tab under the chart. It has two sections: Metrics and List of Trades.
  3. Set commission and slippage in the strategy's properties before you read any result.
  4. Read the List of Trades, not only the headline profit. Score the trades in R so you can compare them with your manual tests.

Know how it fills orders. TradingView's Pine Script strategies guide says that by default the test uses only the chart's bars: orders on past bars run after a bar closes, and a market order fills at the open of the next bar. It cannot see what price did inside each bar unless you use the "Bar detalization" setting, which needs Premium or Ultimate. On the free plan, Deep backtesting is not included and the pricing page lists 5K historical bars available.

How to backtest in MT5 (Strategy Tester)

MetaTrader 5 is free: MetaQuotes' download page offers it at no cost for Windows, macOS, Linux, phones and the web. Its Strategy Tester runs Expert Advisors (coded strategies) over past data, so it suits mechanical rules. For a discretionary strategy, use bar replay instead, or code the rules as an EA first.

  1. Open the tester from the Navigator. Right-click your Expert Advisor in the Navigator window and choose Test. The EA is then selected in the Strategy Tester.
  2. Set the symbol, timeframe and dates you want to test.
  3. Pick a tick mode from the table below. It sets how much price detail the test uses.
  4. Tick "Visualization" to use visual mode. It opens a chart that shows exactly how the EA trades during the test. Turn optimisation off first: visual mode only works in plain testing.
  5. Add a delay if you want the test to wait between placing an order and filling it, as a live broker would. Delays only apply to trades the EA places.
  6. Read the report, then score each trade in R, the same as a manual test.

MT5 tick modes, from MetaQuotes' docs

ModeWhat MetaQuotes says it doesGood for
Every tick based on real ticksTests on the real tick history stored by your brokerThe final check, closest to live
Every tickGenerates every tick from one-minute data; the docs call it the most accurate but the slowestDetailed tests when real ticks are thin
1 minute OHLCUses only the open, high, low and close of each one-minute barFaster first passes
Open prices onlyUses only the open price of each bar on your test timeframe; the docs call it quick but roughEAs that only act on a new bar
Math calculationsDownloads no price history and generates no ticksMaths jobs, not price strategies

Sources: MetaQuotes' help pages on testing, tick generation and visual testing, read on 9 Nov 2026.

The 5 biases that ruin a backtest

1. Look-ahead bias

You "see" the chart and think "yes, I would have taken this at the breakout." But you can see the next 50 candles. Of course you would have taken it. Hide the future or the test is worthless.

2. Skipping the hard setups

You only count the trades you "would have taken" and skip the ones that look unclear in hindsight. Live trading does not let you skip unclear setups: you decide in the moment. Log every setup your rules give, including the ugly ones.

3. Optimisation bias

You tweak the rules ("if I just used a 10 EMA instead of an 8, this would have worked") until the backtest looks great on the data you tested. This is curve-fitting. The strategy then fails on new data. Keep some data back that you never tune on, and test the final rules on it once.

4. Perfect fills

You assume every entry fills at your price, with no spread, no commission and no slippage. Put your broker's real spread and commission into the test, and add a slippage allowance. TradingView sets commission and slippage in a strategy's properties, MT5's tester can add a delay between order and fill, and the stress test below shows what bigger losses do to your numbers.

5. One kind of market

You test three months of trend and decide your trend strategy works. Then the market ranges and you lose. Test across trending, ranging and falling periods, and check the result in each one separately.

How to manual-backtest properly (step by step)

Step 1: Pick your data

Step 2: Hide the future

Step 3: Apply your rules at each bar

When one bar hits both stop and target

A daily bar can reach your stop and your target, and the bar alone cannot tell you which came first. Decide the rule before you start, and use it every time:

The same problem hits coded tests. By default, TradingView's test guesses the path inside a bar from its open, high, low and close: price goes from the open to whichever of the high or low is nearer, then to the other. Its "Bar detalization" setting (Premium and Ultimate) uses lower-timeframe bars instead. In MT5, the "Every tick" and real-tick modes test inside each bar.

Step 4: Log everything in a journal

Each backtest trade should have:

Step 5: Calculate the real numbers

Step 6: Stress test

If the numbers stay positive, you have a strategy worth forward testing on demo. If any of them break, the strategy probably will not survive real markets. The worked example below runs these tests step by step.

A worked example: 20 backtest trades in R

Example log. Every trade below is made up and rounded to show the method. These are not real trades, real results or trade calls.

One setup, tested on a daily chart. Each trade risks 1R. A stop loses 1R, a target pays 2R (once 3R), and two trades were closed by hand at +1.5R.

TradeExitResultRunning total
1Stop-1R-1R
2Target+2R+1R
3Stop-1R0R
4Stop-1R-1R
5Target+2R+1R
6Target+3R+4R
7Stop-1R+3R
8Stop-1R+2R
9Stop-1R+1R
10Target+2R+3R
11Closed by hand+1.5R+4.5R
12Stop-1R+3.5R
13Target+2R+5.5R
14Stop-1R+4.5R
15Stop-1R+3.5R
16Target+2R+5.5R
17Stop-1R+4.5R
18Closed by hand+1.5R+6R
19Stop-1R+5R
20Target+2R+7R

Scoring the example log

Run your own numbers through the trade expectancy calculator. If you would rather describe a strategy in words and let the software test it, see AI backtesting in plain English.

Stress testing the example

The example passes. But 20 trades is far too few to trust, and the next section shows why with the same numbers.

Testing rules that put risk first? So does the free weekly letter, built on the 3-Gate method. Get the free letter

How many trades do you need in a backtest?

There is no magic number. The honest answer is: enough trades that the range of likely results no longer includes a losing strategy. Two simple sums show how fast that range shrinks, and you can run both on your own log.

The win rate: its error shrinks with the square root of n

The standard error of a win rate p measured over n trades is √(p × (1 - p) ÷ n). The usual 95% range is the measured win rate plus or minus 1.96 standard errors. This is the common normal approximation from the NIST statistics handbook, which warns it is rough when the sample is very small.

Worked example, using the example log's 45% win rate:

Trades (n)Standard errorLikely range (95%)
2011.1 points23% to 67%
507.0 points31% to 59%
1005.0 points35% to 55%
2003.5 points38% to 52%
4002.5 points40% to 50%

Four times the trades halves the error. This strategy breaks even at a 33% win rate. At 20 trades the likely range (23% to 67%) still includes losing; at 100 trades (35% to 55%) it just clears break-even.

The expectancy: the same idea, using the spread of your R

The standard error of expectancy is the standard deviation of your R results divided by √n (the confidence limits for a mean, in the same handbook).

Worked example, on the 20 example trades:

So the test cannot yet tell this strategy from a losing one. How many trades would it take, if the results kept the same average and spread? You need 2 × 1.56R ÷ √n to fall below 0.35R. That means √n above 8.9, so n above 79: about 80 trades. (2 is a round stand-in for the t value at that size, which is close to 1.99.)

What the sums mean

Treat these as rough guides. They assume each trade is independent and the market behaves the same way across the whole test. Neither is fully true, which is why a forward test on demo comes next.

What separates a good backtest from a great one

A good backtest logs entries and exits and works out the net R.

A great backtest also:

A journal lets you do all of this, and the same tags carry over to live trading, so you can compare your backtest with your live results.

When automated backtesting matters

If your strategy is:

Use Pine Script on TradingView or MQL5 on MetaTrader 5. Both testers suffer the same biases, so be especially careful with optimisation: test on data you did not tune on.

The funded-trader workflow

The workflow before you pay for a prop firm challenge:

  1. Backtest the exact strategy you will trade, manually or in code.
  2. Log enough trades that the 95% range of your expectancy sits above zero. In the example that took about 80; work out your own.
  3. Pass the stress tests: still positive with a win rate 10 points lower and losses 20% bigger.
  4. Forward test on demo with the same rules and the same logging.
  5. Then pay the challenge fee. Our guide to how to pass a prop firm challenge covers the rest.

In RB Trading Pro Journal, backtesting is a Pro feature: create a session, pick a symbol and a start date, replay the market bar by bar on timeframes from 1 minute to weekly, and log trades as you go. Pro also has the AI Strategy Backtest. Pro is $29.99 a month or $299 a year, with a 30-day money-back guarantee, and the free plan covers your first 50 trades.

What to do this week

What to do this week

Questions traders ask

How do you backtest a trading strategy?

Write the rules down, replay past charts bar by bar with the future hidden, log every trade the rules give in R, then work out the expectancy, the average R per trade. Add real costs, stress test the result and forward test on demo before you risk money.

Can you backtest on TradingView for free?

Yes. On 9 Nov 2026 TradingView's pricing page listed Bar Replay on the free Basic plan with all history on daily and higher timeframes, but no minute, second or tick history. The Strategy Tester's basic report metrics are free too. Deep backtesting is not.

Is the MT5 Strategy Tester free?

Yes. MetaQuotes offers MetaTrader 5 as a free download, and the Strategy Tester is part of it. It tests Expert Advisors, so your rules need to be coded. Visual mode shows the EA's trades on a chart, and you pick a tick mode from open prices only up to real ticks.

How many trades do you need in a backtest?

Enough that the likely range of your expectancy no longer includes zero. The standard error is the standard deviation of your R results divided by the square root of the number of trades. In our made-up 20-trade example, that worked out at about 80 trades.

Is backtesting the same as forward testing?

No. Backtesting runs a strategy over past data. Forward testing runs it in real time, as new bars arrive. Do both: backtest first, then forward test on demo with the same rules and the same log.

Sources and definitions

Every outside fact on this page was opened at its source on 9 Nov 2026. The example log is made up to show the method.

Educational, not financial advice.

RB Trading Pro Journal

Stop guessing. Start tracking.

30-day money-back guarantee · Cancel anytime · First 50 trades free

Find your edge →
BacktestingStrategyRisk