← All articles Guide / TradingView

How to Backtest a Strategy in TradingView (and What the Strategy Tester Won't Tell You)

Backtesting in TradingView takes a few minutes: add a strategy to a chart, open the Strategy Tester and read the results. Getting a result you can trust takes a little longer. This guide covers the steps, the settings that quietly change your numbers, manual backtesting with Bar Replay, and the three checks that tell you whether a TradingView backtest means anything for live trading.

Quick answer

1. Add a strategy script to your chart and open the Strategy Tester. It trades every bar loaded on the chart and reports the results.

2. Set commission and slippage in the strategy's Properties first. Both start at zero, so an untouched backtest shows results before costs.

3. A good Strategy Tester result shows how well the rules fit that history. Test the strategy on data it never saw before you trust it.

Want worked examples?

The Strategy Starter Playbook walks through example breakout strategies with the real settings Tomas uses, so you've got something solid to put into the Strategy Tester. See The Strategy Starter Playbook.

How to Backtest a Strategy on TradingView, Step by Step

TradingView backtests a strategy by running it over the bars on your chart and simulating every order it would have placed. Here's the full routine.

  1. Open the exact chart you'd trade. The backtest uses this chart's symbol, timeframe and session. A continuous futures contract and a single month behave differently, and so do regular and extended sessions, so pick the one you'd actually trade.
  2. Add a strategy, not an indicator. Only strategy scripts place simulated orders. You can add one from the community scripts, or paste your own into the Pine Editor and click Add to chart.
  3. Open the Strategy Tester tab under the chart. It shows the headline figures, the performance breakdown and the list of trades.
  4. Set the Properties. Open the strategy's settings and go to Properties: initial capital, order size, commission and slippage. The next section covers what each one does to your numbers.
  5. Check how much history you tested. The Strategy Tester trades the bars loaded on the chart, and how many you can load depends on your plan. Deep Backtesting, on higher-tier plans, runs over a longer date range you choose and shows its results in the report rather than on the chart.
  6. Read the trades, not just the net profit. Click through the list of trades and check that entries and exits land where your rules say they should. Then look at how many trades there are. A few dozen trades can't tell skill from luck.

That gives you a backtest. Whether it tells you anything about the future is a different question, and it's where most TradingView strategies come unstuck.

The Strategy Tester Settings That Change Your Results

The same rules can show a profit or a loss depending on a handful of settings. These are the ones to set before you read a single number.

SettingWhat it doesWhat to set
CommissionCharges a cost on every orderYour broker's real commission. It starts at zero
SlippageAdds ticks to market and stop fillsAt least a tick on liquid futures, more on thinner markets. It also starts at zero
Order sizeContracts, shares or a percentage of equity per tradeA fixed size while you judge the rules. Percent of equity compounds, so the later trades dominate the totals
Initial capitalThe starting balanceYour real account size, so drawdown percentages mean something
PyramidingHow many entries the strategy can add in the same directionOne, unless your rules are meant to add to positions
Fill settingsHow orders are filled inside a barSee below. On higher-tier plans, try the Bar Magnifier

Costs matter most for strategies that trade often. A day-trading strategy with a small average trade can look profitable at zero cost and lose money once commission and a tick of slippage come off every fill.

How TradingView fills orders inside a bar

On historical bars the Strategy Tester only knows each bar's open, high, low and close. It has to assume the path price took between them. When a stop and a target both sit inside the same bar, that assumption decides which one filled, and the real market may have done the opposite. The Bar Magnifier setting uses lower-timeframe data to work these fills out more accurately.

Very tight stops make this worse. If a stop is smaller than the bars it's trading, the backtest can't reliably tell whether it was hit on the entry bar, so it can record a winner that would've been a loss. Tomas's rule is to keep stops at least 1.5 to 2 times the size of the biggest 1-minute bar on the chart, so the backtest can resolve them.

Repainting and lookahead

A strategy that uses information it couldn't have had at the time will backtest beautifully and fail live. In Pine Script the usual causes are pulling higher-timeframe values with lookahead switched on, or signals that change after the bar has closed. If a strategy's past trades move when you reload the chart, or it reads another timeframe's data, check that before you look at anything else.

Manual Backtesting with Bar Replay

Bar Replay hides everything to the right of a date you choose, then plays the bars forward one at a time while you decide where you'd enter and exit. It's the way to backtest rules you trade by hand, and a good way to practise reading a setup in real time.

It has limits. It's slow, so samples stay small. You know roughly what happened next, so hindsight creeps into your decisions. And how far back you can replay intraday bars depends on your plan. Use Bar Replay to learn a setup. Use the Strategy Tester, or a dedicated testing tool, to measure one.

Why a Good Strategy Tester Result Can Still Fail Live

The Strategy Tester answers one question exactly: how did these rules, with these inputs, trade these bars? It doesn't check whether the result holds on bars the strategy never saw.

That matters because the easiest way to improve a backtest is to keep changing the inputs until the curve looks good. Every change fits the strategy a little more closely to that one stretch of history. TradingView doesn't split your data into a development period and an untouched test period, and it has no built-in walk-forward analysis, which repeats that test across many windows. Tomas covers why those two checks matter in Why Pine Script Strategies Fail Live.

Three Checks Before You Trust a TradingView Backtest

  1. Hold back recent data. Build and tune the strategy on the older part of your history only. Then run it once on the most recent 20 to 30%. In Tomas's E-mini NASDAQ example he used 10 years of data and held back the last 3. If the strategy falls apart on the held-back years, it was fitted to noise.
  2. Move the inputs a little. If a 2.0 ATR multiplier works but 1.8 and 2.2 fall apart, the strategy depends on one lucky value. In Tomas's moving average and ATR build on NASDAQ, the neighbours at 1.8 and 2.2 held up too, which is what you want to see.
  3. Count the trades and add the costs. Make sure there are enough trades to mean something, then rerun with realistic commission and slippage. A strategy whose edge disappears after costs never had one you could trade.

You can do the first two by hand in TradingView with date ranges and input changes. It works for one strategy. Across dozens of candidates it gets slow, and it's easy to peek at the held-back data by accident.

Where BreakoutOS Fits

BreakoutOS does that testing before a strategy reaches your chart. It builds breakout strategies on one slice of data, tests them on data they never saw, scores how robust each one is, then exports the one you pick as a Pine Script strategy for TradingView. You don't write any code.

To check the export, Tomas ran one strategy in both places: an E-mini NASDAQ opening gap strategy on 60-minute bars, using TradingView's own NQ data. BreakoutOS showed 393 trades and TradingView's Strategy Tester showed 392, with 389 trades identical. The other four came from three Thanksgiving-week early closes. Both runs were hypothetical backtests with no commission or slippage, so add your real costs in Properties before you rely on the numbers. The full comparison is on the BreakoutOS for TradingView page.

Build your first strategy for TradingView

Answer four quick questions and see which BreakoutOS tools fit how you trade, and what to do next.

Get Your Free Roadmap  →

Testing on Another Platform?

The three checks above apply on every platform. Each one has its own strategy tester, with its own settings for costs and fills. BreakoutOS exports strategies to all seven of these:

  • TradingView: a Pine Script strategy, checked in the Strategy Tester.
  • NinjaTrader: a NinjaScript strategy for the Strategy Analyzer.
  • TradeStation: an EasyLanguage strategy.
  • MultiCharts: a PowerLanguage strategy.
  • MetaTrader 5: an MQL5 Expert Advisor for the Strategy Tester.
  • AmiBroker: an AFL strategy.
  • Python: a Python strategy you can run in your own backtester.

Need a strategy to test?

The Strategy Starter Playbook gives you the Mr. Breakouts Formula with 11 example strategies, including the logic and code. See The Strategy Starter Playbook.

The Strategy Starter Playbook - the Mr. Breakouts Formula with 11 example strategies, logic and code
The Strategy Starter Playbook. See what's inside →

Frequently Asked Questions

Open a chart of the market and timeframe you want to test, add a strategy script (from the community scripts or your own in the Pine Editor), then open the Strategy Tester tab under the chart. Set commission, slippage, order size and initial capital in the strategy's Properties before you read the results, then check the list of trades as well as the headline figures.
It's accurate about what it measures: how your rules traded the bars on your chart. The usual gaps are costs (commission and slippage start at zero), fills inside a bar (it only knows each bar's open, high, low and close unless you use the Bar Magnifier), the amount of history your plan loads, and the lack of a built-in out-of-sample or walk-forward test. Set the costs, check the fills and test on held-back data before you trust a result.
Yes. The Strategy Tester and Bar Replay are available on the free plan, with less chart history than paid plans. Deep Backtesting and the Bar Magnifier are on higher-tier plans. Check TradingView's current plan page for the exact limits.
Bar Replay hides the chart after a date you pick and plays the bars forward one at a time, so you can practise and test rules you trade by hand. It's useful for learning a setup, but it's slow and hindsight creeps in, so use the Strategy Tester to measure a strategy across a large number of trades.
Not built in. You can imitate an in-sample and out-of-sample split by changing the date range by hand, but there's no built-in walk-forward engine or robustness score. Tools like BreakoutOS do that testing first and export the finished strategy as Pine Script.
Tomas Nesnidal

About the Author

Tomas Nesnidal, known to the systematic trading community as Mr. Breakouts, is a breakout trading specialist, hedge fund co-founder, and creator of BreakoutOS. He has managed institutional portfolios using breakout strategies for over 15 years, trading from 65+ countries. He is the author of The Breakout Trading Revolution and co-founder of Breakout Trading Academy.