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

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.
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.
| Feature | Basic (free) | Essential | Plus | Premium | Ultimate |
|---|---|---|---|---|---|
| History by day and higher timeframes | All | All | All | All | All |
| History by the minute | No | 180 days | 365 days | All | All |
| History by the second | No | No | No | All | All |
| History by the tick | No | No | No | No | 7 days |
| Indicators replay | Yes | Yes | Yes | Yes | Yes |
| Trading in bar replay | Yes | Yes | Yes | Yes | Yes |
| Strategy backtesting: basic report metrics | Yes | Yes | Yes | Yes | Yes |
| Advanced report metrics | No | Yes | Yes | Yes | Yes |
| Deep backtesting | No | No | No | Yes | Yes |
| Historical bars available | 5K | 10K | 10K | 20K | 40K |
Free Bar Replay, in short
- Daily and higher charts: all history
- No minute, second or tick history
- Indicators and trading work in replay
- Intraday replay starts on the Essential plan
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
- Open a chart of the market you will trade, on the daily timeframe.
- Click Bar Replay on the top panel of the chart. The replay panel opens and the chart waits for a starting point.
- Click the date to start from. Everything after it is hidden.
- 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.
- 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
- Add a strategy to the chart. Use a built-in one, one from Community Scripts, or your own, written in Pine Script.
- Open the Strategy Report tab under the chart. It has two sections: Metrics and List of Trades.
- Set commission and slippage in the strategy's properties before you read any result.
- 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.
- 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.
- Set the symbol, timeframe and dates you want to test.
- Pick a tick mode from the table below. It sets how much price detail the test uses.
- 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.
- 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.
- Read the report, then score each trade in R, the same as a manual test.
MT5 tick modes, from MetaQuotes' docs
| Mode | What MetaQuotes says it does | Good for |
|---|---|---|
| Every tick based on real ticks | Tests on the real tick history stored by your broker | The final check, closest to live |
| Every tick | Generates every tick from one-minute data; the docs call it the most accurate but the slowest | Detailed tests when real ticks are thin |
| 1 minute OHLC | Uses only the open, high, low and close of each one-minute bar | Faster first passes |
| Open prices only | Uses only the open price of each bar on your test timeframe; the docs call it quick but rough | EAs that only act on a new bar |
| Math calculations | Downloads no price history and generates no ticks | Maths 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
- Use the symbol you will actually trade.
- Use the timeframe you will actually trade.
- Make sure it covers mixed conditions: trending and ranging.
Step 2: Hide the future
- Use a bar replay tool: TradingView Bar Replay, free on daily charts, or the RB Trading Pro Journal backtest replay on Pro.
- Set a starting bar. Everything after it stays hidden until you step forward.
- Each step reveals one new bar.
Step 3: Apply your rules at each bar
- Does this candle complete a setup I would take?
- If yes: log entry, stop, target and size BEFORE you step forward.
- Step forward bar by bar.
- Record the exit: target hit, stop hit, manual exit or time exit.
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:
- Count it as a stop. This is the safe choice, and it never flatters the test.
- Or look at a lower timeframe for that day, if your plan has the history, and log what it shows.
- Never pick whichever answer looks better on the day. That is hindsight again.
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:
- Date, time, symbol, timeframe
- Setup name (the same names you use live)
- Entry, stop, target, position size
- Outcome in R: R-multiples explained if R is new to you
- Notes on context: session, news, market type
Step 5: Calculate the real numbers
- Win rate
- Average win and average loss in R
- Expectancy: the average R per trade
- Profit factor: total R won divided by total R lost
- Longest losing run (this drives your mental prep)
- Largest drop from a peak in R
Step 6: Stress test
- Take 10 points off your win rate. Is expectancy still positive?
- Make every loss 20% bigger, for slippage. Still positive?
- Could you sit through a losing run twice as long as the test's longest?
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.
| Trade | Exit | Result | Running total |
|---|---|---|---|
| 1 | Stop | -1R | -1R |
| 2 | Target | +2R | +1R |
| 3 | Stop | -1R | 0R |
| 4 | Stop | -1R | -1R |
| 5 | Target | +2R | +1R |
| 6 | Target | +3R | +4R |
| 7 | Stop | -1R | +3R |
| 8 | Stop | -1R | +2R |
| 9 | Stop | -1R | +1R |
| 10 | Target | +2R | +3R |
| 11 | Closed by hand | +1.5R | +4.5R |
| 12 | Stop | -1R | +3.5R |
| 13 | Target | +2R | +5.5R |
| 14 | Stop | -1R | +4.5R |
| 15 | Stop | -1R | +3.5R |
| 16 | Target | +2R | +5.5R |
| 17 | Stop | -1R | +4.5R |
| 18 | Closed by hand | +1.5R | +6R |
| 19 | Stop | -1R | +5R |
| 20 | Target | +2R | +7R |
Scoring the example log
- Wins: 9 of 20, a 45% win rate. Losses: 11.
- Average win: 18R from 9 wins = +2R.
- Average loss: 11R from 11 losses = -1R.
- Total: 18R - 11R = +7R.
- Expectancy: +7R ÷ 20 trades = +0.35R a trade.
- Same answer by formula: (0.45 × 2R) - (0.55 × 1R) = 0.90R - 0.55R = +0.35R.
- Profit factor: 18R won ÷ 11R lost = 1.64. Above 1 means the wins paid for the losses.
- Longest losing run: 3 trades (7 to 9).
- Largest drop from a peak: 3R, from +4R after trade 6 to +1R after trade 9.
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
- Win rate 10 points lower (35%): (0.35 × 2R) - (0.65 × 1R) = +0.05R. Still positive, only just.
- Losses 20% bigger (1.2R): (0.45 × 2R) - (0.55 × 1.2R) = 0.90R - 0.66R = +0.24R.
- Break-even win rate with 2R wins and 1R losses: 1 ÷ (1 + 2) = 33%.
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 error | Likely range (95%) |
|---|---|---|
| 20 | 11.1 points | 23% to 67% |
| 50 | 7.0 points | 31% to 59% |
| 100 | 5.0 points | 35% to 55% |
| 200 | 3.5 points | 38% to 52% |
| 400 | 2.5 points | 40% 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:
- Standard deviation of the 20 results: 1.56R.
- Standard error: 1.56R ÷ √20 = 1.56R ÷ 4.47 = 0.35R.
- For 20 trades the 95% multiplier is 2.09 (the t value for 19 degrees of freedom).
- Range: +0.35R plus or minus 0.73R, so anywhere from -0.38R to +1.08R.
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
- Four times the trades halves the error
- Halve the edge and you need four times the trades
- Wider swings in R need more trades
- Run the sums on your own log
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:
- Asks at every entry "would I really take this on a Friday afternoon?" You had no emotions in the test, so ask the question for yourself.
- Tags every trade with the market type: trending, ranging, after news.
- Splits the results by setup, session and market type.
- Includes "trades I almost took", with the reason.
- Records the longest losing run, so you know what to expect live.
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:
- Simple and indicator-based (a moving average crossover, an RSI mean-reversion)
- Mechanical, with no judgement
- Going to run as an EA or an algorithm
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:
- Backtest the exact strategy you will trade, manually or in code.
- Log enough trades that the 95% range of your expectancy sits above zero. In the example that took about 80; work out your own.
- Pass the stress tests: still positive with a win rate 10 points lower and losses 20% bigger.
- Forward test on demo with the same rules and the same logging.
- 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
- Write your setup's rules in five lines
- Pick free Bar Replay or the MT5 tester
- Log 20 trades in R, future hidden
- Time those 20, then plan the rest
- Work out expectancy and its range
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.
- TradingView pricing: Bar Replay and Strategy backtesting rows by plan
- TradingView: how much data is available for Bar Replay
- TradingView: how to turn Bar Replay on
- TradingView: strategies, backtesting and forward testing
- TradingView Pine Script docs: strategies
- MetaTrader 5 download, testing, tick generation and visual testing (MetaQuotes)
- NIST/SEMATECH e-Handbook of Statistical Methods: confidence limits for a proportion and for a mean
- Our glossary: R-multiple and expectancy
Educational, not financial advice.
Stop guessing. Start tracking.
30-day money-back guarantee · Cancel anytime · First 50 trades free
Find your edge →