For Business

Backtesting & Statistics

How to Backtest on TradingView

On TradingView a backtest is a short script in Pine added to the chart, with the Strategy Tester panel underneath drawing the trades on the bars and counting them. This paper shows you TradingView in five lines; the example rule from the backtesting paper written as six lines of Pine; the script's trades on the euro for 17 to 21 August 2026 on real hourly bars, 39.0 pips for the week; the Overview panel's six numbers for that week and what each means; and the tabs along the bottom of the screen that take a sentence to a result.

Difficulty
Beginner
Reading time
5 min
Pages
8
Reviewed by
Saman Rahbar

This paper is locked

Read it in the browser and keep the PDF with Premium, or buy this one paper.

TradingView in five lines

On TradingView the rule is a short script in Pine, TradingView's own language, added to the chart, and the Strategy Tester panel underneath counts what it did. It needs the script, a symbol and a timeframe, and it runs over the bars the chart has loaded. It gives back arrows on the bars where the script bought and sold, an Overview of totals, and a list of trades. The one setting to know is the date range, because by default the test covers only the loaded bars. The example rule, buy at 10:00 and sell at 18:00, written in six lines and run on 17 to 21 August 2026, made 39.0 pips, where a pip is the fourth decimal place of the price; the week after, in the earlier paper, it lost 56.7.

The rule as six lines

Here is the rule as a script, six lines of Pine in the editor. The first line names the language version and the second names the strategy; the third and fourth say buy at the 10:00 bar, the fifth and sixth say close at the 18:00 bar. Nothing is hidden in the frame. One thing to set before trusting it: the chart's clock, because hour is read off the clock the chart shows, and a chart set to New York time would buy at a different bar from one set to the feed's time. If a rule cannot be written in six lines like these, it was not a rule yet, and there is nothing to test.

This paper is locked