Explainer
How to backtest a trading strategy in TradingView
In TradingView you apply a strategy to a chart and read its results report; the result depends on the chart data, fill rules and properties you set.
Updated
The steps
TradingView shows a strategy’s results in a results report in the bottom panel of the chart. The strategy is a script, written in TradingView’s Pine Script language or taken from its library. The steps are short.
- Open a chart of the market and the bar size your rules use.
- Add a strategy to the chart, or write your rules as a Pine Script strategy.
- Open the strategy’s properties and set the order size, commission and slippage.
- Read the results report and its list of trades.
- Check a few trades against the chart by hand.
- Results report
- The panel under the chart that lists the simulated trades and their summary figures.
- Pine Script
- TradingView’s scripting language, used to write indicators and strategies.
- Broker emulator
- The part of the platform that decides how a strategy’s orders fill on historical bars.
- Bar magnifier
- An option that uses lower-timeframe bars to decide fills inside a historical bar.
The properties that matter
The properties page lets you set commission as a percentage of value, per contract or per order, applied to entries and exits. Slippage is set in ticks and is added to the fill price of market and stop orders. By default, limit orders fill as soon as their price is touched, and a setting lets you require price to pass the limit by a number of ticks.
Set these before you read any result. A results report with no commission and no slippage shows a result no account could have had.
How TradingView decides fills
By default the broker emulator uses only the chart’s own bars. A strategy runs once per bar at the close, and its orders fill at the next bar’s open.
Inside a bar it has to guess the order of the prices. TradingView’s documentation says the emulator assumes the price moved open, high, low, close when the open is closer to the high, and open, low, high, close when the open is closer to the low. It also assumes there are no gaps inside a bar. If price crosses an order’s level in the gap between bars, the order fills at the next bar’s open.
Read the fill rules of any platform before you trust its report. They are part of the result.
Bar magnifier and its limits
The bar magnifier retrieves prices from a lower timeframe to decide what happened inside a historical bar. TradingView’s documentation says it is available on its Premium and Ultimate plans. Scripts can request at most 200,000 bars of a lower timeframe, so early bars may lack the extra detail and fall back to the default assumptions.
The documentation also says that on the default range individual data is kept for up to the latest 9000 trades. Intraday history can be limited by plan, too. Check the vendor for what your plan includes.
What to check for futures
Futures add contract expiry. Find out how the symbol you chart joins contract months, and whether its prices are back-adjusted. That is set by the data behind the chart, so read the vendor’s notes. A roll that is treated as a price move can trigger an entry or hit a stop that never happened.
Then check how the platform treats a same-bar tie, where a stop and a target sit in one bar. Our method uses 1-minute bars to decide which was hit first, and takes the stop if both are in the same 1-minute bar. Neither approach is wrong. They are different assumptions, and you should know which one you have.
When a different route fits
If you do not want to write a script, or you want held-back months and every assumption written out, our service runs rules written in plain language on 1-minute CME data. A version is $19.
Questions and answers
Can you backtest futures in TradingView?
A strategy can be applied to a chart of a market. What the report means depends on the data behind that chart and the fill assumptions, so check the vendor for futures data on your plan.
Does TradingView include commission and slippage?
It has properties for both. Commission can be a percentage, a per-contract amount or a per-order amount. Slippage is in ticks and is added to market and stop fills.
What is the bar magnifier?
An option that uses lower-timeframe bars to decide fills inside a historical bar. TradingView’s documentation says it is available on its Premium and Ultimate plans.
Is TradingView backtesting free?
TradingView lists a Basic plan at $0 forever. Which backtesting features each plan holds is for the vendor to say, so check its plan table.