How to Backtest a TradingView Strategy: Complete Beginner's Guide
Last updated: 19 October 2026
Backtesting a TradingView strategy means running your Pine Script rules on old price data to see how they would have performed, before you risk real money. This beginner's guide shows how to backtest a TradingView strategy step by step: how to load a Pine Script strategy, choose historical data, read the Strategy Tester numbers (win rate, profit factor, drawdown), avoid the common traps, and then re-test the same strategy for free on PineBacktest.
strategy(), (2) add it to a chart, (3) pick the symbol, timeframe and date range, (4) set realistic commission, slippage and position size, (5) read the report, and (6) confirm the result on a second data set. A backtest shows how a strategy behaved in the past. It does not predict the future.What is backtesting in TradingView?
Backtesting is the process of applying trading rules to historical candles and recording every trade the rules would have made. TradingView does this with strategies, which are Pine Script programs that use strategy.entry(), strategy.exit() and strategy.close() to open and close simulated trades. An indicator only draws on the chart. A strategy places simulated orders and produces a performance report. TradingView's own help centre describes this report as showing an equity chart plus metrics such as Total P&L, Max drawdown, Profitable trades and Profit factor, and a full list of trades (TradingView Help Center).
TradingView has renamed and reorganised this panel over time. Many guides call it the Strategy Tester, and newer versions label it the strategy report. The idea is the same: it lives at the bottom of the chart and summarises what the strategy did.
Step 1: Get a Pine Script strategy
You can write your own or start from a public script. A minimal example is a moving-average crossover that buys when a fast average crosses above a slow one and exits when it crosses back:
//@version=5
strategy("SMA Cross", overlay=true, initial_capital=100000,
default_qty_type=strategy.percent_of_equity, default_qty_value=100,
commission_type=strategy.commission.percent, commission_value=0.05)
fast = ta.sma(close, 20)
slow = ta.sma(close, 50)
if ta.crossover(fast, slow)
strategy.entry("Long", strategy.long)
if ta.crossunder(fast, slow)
strategy.close("Long")
The first line, strategy(...), is what makes it a strategy and not an indicator. It also sets the starting capital, the position size and the commission, which matter a lot (see Step 4).
Step 2: Add it to a TradingView chart
Open a chart, open the Pine Editor, paste the script and add it to the chart. TradingView's help page explains that a strategy can also be picked from the Indicators menu, and that only one strategy can run on a chart at a time (TradingView Help Center). If the script has errors, the editor shows them with line numbers. Fix those first.
Step 3: Choose the symbol, timeframe and date range
Your result depends heavily on what you test it on:
- Symbol: test on the market you actually plan to trade.
- Timeframe: a strategy tuned on 1-minute candles will behave differently on 15-minute or 1-hour candles. Test the timeframe you will trade.
- Date range: use enough history to include trending, sideways and falling markets. A strategy tested only on a rising year can look brilliant and then fail.
- Number of trades: a few dozen trades is a very small sample. Aim for hundreds if you can, otherwise treat the result as luck until proven otherwise.
How much history you can load in TradingView depends on your plan and the symbol, so check what is available for your account. Deep Backtesting, a setting that unlocks a symbol's fuller price history, is described by TradingView as a premium-plan feature (TradingView Help Center).
Step 4: Set realistic costs, slippage and position size
This is the step beginners skip, and it is the main reason backtests look better than live trading. Every real trade pays a commission and usually suffers slippage, meaning you get a slightly worse price than the one on the chart. A strategy that makes a tiny profit per trade can turn into a loss once costs are added. Always set:
- Commission that matches your broker.
- Slippage, even a small amount, especially on fast or illiquid markets.
- Position size you would really use. Risking 100% of equity on every trade inflates both profit and drawdown.
Step 5: Read the results the right way
Do not look at net profit alone. These are the numbers to read together:
- Net profit and equity curve. A smooth rising curve is healthier than one with a single huge jump.
- Win rate. The share of trades that made money. A high win rate alone means little if the average loss is much bigger than the average win.
- Profit factor. Gross profit divided by gross loss. Above 1 means the strategy made more than it lost. Values far above 2 on a small sample are a warning sign, not a reward.
- Max drawdown. The largest fall from a peak. Ask yourself honestly whether you could sit through that loss in real trading.
- Number of trades. More trades make the statistics more trustworthy.
- Average win versus average loss. Together with win rate this gives the expectancy, the average result per trade.
- List of trades. Scroll through it. Odd entries, huge single trades or gaps often reveal a bug in the script.
Common backtesting mistakes to avoid
- Repainting. A script that uses information it would not have had at the time, so the past looks perfect and live trading does not. TradingView itself warns that leaking future information into the past is unacceptable (Pine Script docs). Read our guide on repainting and fake profit videos.
- Overfitting. Tweaking inputs until the past looks great. The strategy then fits noise, not a real edge. Test on data you did not use to tune it.
- Ignoring costs. No commission and no slippage almost always overstates results.
- Too few trades. Thirty lucky trades prove nothing.
- One market, one period. If it only works on one symbol in one year, be careful.
- Trusting a single number. A big profit with a huge drawdown is not a good strategy.
Backtest your Pine Script strategy free on PineBacktest
A second opinion on a different data source is one of the best ways to check a strategy. PineBacktest is a free Pine Script backtesting tool: you paste a TradingView strategy, pick a dataset and timeframe, and get the trades, equity curve and drawdown. Here is how to use it:
- Open the PineBacktest tester and paste your Pine Script strategy into the editor.
- Choose a dataset (Nifty, BankNifty or one of five forex pairs: EURUSD, GBPUSD, USDJPY, AUDUSD and EURJPY) and a timeframe.
- Pick the From and To dates. The date pickers only allow days that exist in the chosen file.
- Set your initial capital, position size, commission and slippage.
- Press run, then read the statistics, equity curve and list of trades.
The tool also checks for look-ahead behaviour and builds higher timeframes only by aggregating the 1-minute candles, which helps you avoid the most common way a backtest fools you. Open the tester and try the SMA example above, then change one input at a time and watch how the result moves.
A simple checklist before you trust a backtest
- Does the script have no repainting and no look-ahead?
- Are commission, slippage and realistic position size included?
- Are there enough trades, across different market conditions?
- Is the maximum drawdown something you could actually live with?
- Does it still work on a different period or a different symbol?
- Have you forward-tested it on a demo account before using real money?
Frequently asked questions
How do I backtest a strategy on TradingView for free?
Add a Pine Script strategy to a chart and open the strategy report at the bottom. A free TradingView account lets you run strategies, but the amount of history and some features depend on your plan. You can also paste the same strategy into PineBacktest, which is free.
What is the difference between the TradingView Strategy Tester and Pine Script backtesting?
Pine Script is the language you write the rules in. The Strategy Tester (the strategy report) is the panel that runs those rules on historical candles and shows the results.
How accurate is a TradingView backtest?
It is only as accurate as its data and assumptions. Missing costs, slippage, repainting or too little data can make a backtest much better than real trading. Treat it as a filter that removes bad ideas, not proof that an idea works.
What is a good profit factor and win rate?
There is no universal number. Many traders look for a profit factor comfortably above 1 after costs, on enough trades, with a drawdown they can tolerate. A high win rate with large losses is still a losing strategy.
Can I backtest on 1-minute data?
Yes. PineBacktest uses 1-minute candles and can aggregate them to higher timeframes, so you can test intraday strategies on the same data at different timeframes.
Can I backtest a strategy that uses multiple timeframes?
Yes, if the script requests higher-timeframe data correctly. Be careful: badly written multi-timeframe code is a common cause of repainting.
This article is educational and is not financial advice. Past performance does not guarantee future results, and trading can lose you money. TradingView's interface and plan features change, so check TradingView's current documentation for details.