How to Backtest on TradingView in 2025

TradingView is also a great platform to backtest a trading strategies, as long as you know how to use it.
Tradingview is best known for its charts, which they humbly call their "Supercharts". What many don't know is that TradingView is also a great platform to backtest your trading strategies.
The only problem is, you have to turn your trading strategy into Pine Script to backtest it on a symbol. But you don't need to be a seasoned coder to do this. In the age of AI, any software is just a prompt away.
As an example strategy, I'll be coding the Incredible Strategy into TradingView's Pine editor and running it on SPY. This is a long-term strategy and does a good job at predicting when a stock, future, or currency has entered a bullish trend. More details in that post.
That said, this method of backtesting works with any strategy and any symbol.
For this to work, ChatGPT will do the heavylifting. Go to chatgpt.com, and enter the details of your trading strategy. You don't even need to login. Here's the prompt that I used for the Incredible Strategy:
Hi, I need you to write a Pine Script based on a 12 month SMA. Enter a
long trade when there are 2 consecutive bars that close above the SMA
and the close for each bar is higher than the open. If there is a bar
that closes below the 12 SMA, then exit the position.
And this is the code that ChatGPT wrote.
//@version=5
strategy("12-Month SMA Strategy", overlay=true)
// Define the length for the 12-month SMA (assuming monthly data)
length = 12
sma12 = ta.sma(close, length)
// Conditions for long entry
bar1_condition = close[1] > sma12 and close[1] > open[1] // Previous bar closes above SMA and is bullish
bar2_condition = close > sma12 and close > open // Current bar closes above SMA and is bullish
long_condition = bar1_condition and bar2_condition
// Condition for exiting the trade
exit_condition = close < sma12
// Execute trades
if (long_condition)
strategy.entry("Long", strategy.long)
if (exit_condition)
strategy.close("Long")
// Plot the SMA
plot(sma12, title="12-Month SMA", color=color.blue)
Not a bad first draft. Now we need to put this into TradingView. You'll need at least a free TradingView account to use the Pine Editor under each chart. If you don't have an account, you can get one here. And that's an affiliate link, by the way.
Now, with your fancy new account, go to SPY and click the "Pine Editor" tab at the bottom of the chart.
Copy and paste the code ChatGPT gave you into the Pine Editor and hit "Add to Chart".
You'll get taken to the "Strategy Tester" tab and see the profit (or loss) made from the strategy.
Congratulations, you can now officially backtest whatever strategy you want without paying for some $100 per month software.
You may notice that the gains or losses are lower than expected. This is because TradingView by default sets the simulated initial capital at $1,000,000 but only trades 1 share or contract at a time. To fix this, click on the hexagon icon that looks like a lug-nut to go to the settings. Here, change the initial capital to whatever you want and the "Order size" to 100 % of equity. This will go all-in on each trade and show the compounding of your returns.
If you ran into an error, and ChatGPT can't fix it. Leave a comment and I'll help you out.
Thanks for reading.