How to Backtest a Trading Strategy on TradingView

Learn how to backtest a trading strategy on TradingView, dial in the right settings, and avoid fake results from curve fitting and repainting.

Share
How to Backtest a Trading Strategy on TradingView
How to backtest on TradingView.

Want to test a trading strategy without risking a single dollar? Learning how to backtest a trading strategy on TradingView lets you fact-check your returns, spot exactly what's dragging your performance down, and make adjustments before real money is on the line.

But here's the catch most tutorials skip: it's surprisingly easy to build a beautiful backtest that falls apart the moment you go live. In this guide, TC Trading walks you through the full process — from generating your strategy code to configuring the settings that actually make your results match real trading.

By the end, you'll know how to build a working backtest and how to stress-test it so you don't get fooled by results that look too good to be true.

Table of Contents

Key Takeaways

  • Backtesting on TradingView lets you simulate a strategy against historical data before risking real capital.
  • You need a TradingView account and a way to generate Pine Script code — AI tools like Claude or ChatGPT make this fast.
  • Your strategy must be built as a strategy, not an indicator, or it won't generate buy/sell signals to test.
  • The Properties tab (order size, commission, slippage) is where your backtest either mirrors real trading or drifts far from it.
  • Results that look too good to be true usually signal curve fitting or repainting — the two biggest backtesting traps.
  • Forward testing with a tool like Alpha Insider is the most reliable way to confirm your backtest reflects real fills.

Prerequisites: What You'll Need

Before you build your first backtest, gather these essentials:

  • A TradingView account — the free basic plan is enough to start.
  • A way to generate Pine Script code — your own coding skills, or an AI assistant like Claude or ChatGPT.
  • A trading strategy idea — even a rough concept you want to test (e.g., a crypto swing trading breakout system).
  • Time: roughly 20–30 minutes for your first run-through.
  • Skill level: beginner-friendly. No prior coding experience is required if you're using AI to generate the code.

Do You Need a Paid TradingView Plan?

Short answer: no, not to start.

You can begin backtesting on the basic (free) plan. You'll just be limited — you won't get deep backtesting, which lets you go further back in time and gives you a more detailed look at your data.

Here's TC Trading's honest advice on upgrading:

  • Don't rush to buy premium. Only upgrade once you hit a real snag — like needing to test further back in history or wanting features you genuinely lack.
  • Never pay full price. Two ways to save:
    1. Use a discount link (TC Trading's link saves around $15 on any paid plan).
    2. Upgrade during Black Friday week — TradingView runs a huge sale. A smart move is to go monthly first, then upgrade to a yearly plan on that date for a dramatic discount.

Step-by-Step Guide to Backtesting on TradingView

Step 1: Generate Your Pine Script Strategy

You need Pine Script code to run a strategy. With AI, this is now fast and accessible.

TC Trading's approach: keep a dedicated trading strategy project inside Claude. Feed in your past strategies for context, then describe exactly what you want. For example: "I'm looking to develop a crypto swing trading strategy for the big names — ETH, Bitcoin, Sol — with the ability to toggle different settings so I can fully customize it."

Claude then spits back the full Pine Script code — often in just minutes.

Important — prompting is an art:

  • Typing "build me a profitable trading strategy and make no mistakes" will get you a useless response.
  • Give real context, specify the settings you want to toggle, and treat the output as a starting point, not a finished product.
  • Expect to experiment, customize, edit, and adapt over time.

Step 2: Paste the Code Into the Pine Editor

Once you have your code:

  1. On TradingView (web version), find the little pine tree icon — it's on the bottom of the screen (they occasionally move it around). The app/desktop version is very similar.
  2. Open the Pine editor and look at your list of scripts.
  3. Click Create New — and make sure you select Strategy, not Indicator.
  4. Paste in your generated code.
  5. Save it and give it a name (TC Trading's example is called Crypto Swing Lab v1).

Why "strategy" matters: An indicator is just an indicator — it doesn't execute buys and sells. A strategy tells you when to buy, sell, go long, or go short. You can use indicators inside a strategy, but only a strategy is valid to backtest.

Step 3: Add the Strategy to Your Chart

After saving, click Add to Chart. Your strategy now appears on the left-hand side of the chart, just like an indicator would.

From there, using the three-dot icon on the right of the strategy, you can:

  • Edit the settings
  • Toggle it on/off (hide or show it)
  • View the source code
  • Delete it
  • Add alerts and other actions

Step 4: Borrow From the Community Library

Don't want to start from scratch? TradingView has a massive, constantly refreshed library of strategies.

  1. Go to the Community tab.
  2. Drop down to the Indicators & Strategies section.
  3. Sort by Strategies and filter to open source.

You can read about how each strategy works, then pull up its source code. From there:

  • Apply it to your own charts to see if you like it.
  • Copy the code into your AI assistant and say: "I like this, this, and this — but I don't like this. Can we change it? Can we add this?"
  • In a couple of minutes, you have a brand-new strategy built off a proven starting point, saving you a ton of time.

Step 5: Read the Strategy Report

Once your strategy is running, head to the Strategy Report in the bottom corner of the screen. This is your backtest dashboard.

A key section to understand is Strategy Outperformance. It compares:

  • Your strategy's return (all the buys, sells, longs, and shorts), versus
  • Buy and hold — what you'd have made simply buying the asset at the start of the backtest and holding it.

In TC Trading's Bitcoin example, the strategy annualizes to just shy of 25% per year since 2016/2017 — better than the S&P 500's ~10% historical average. But the outperformance tab reveals it actually underperforms buy-and-hold Bitcoin.

So why keep it? Because of the risk profile:

  • Many small losing trades, offset by occasional huge winning trades — an outsized reward-to-risk ratio.
  • A max drawdown of just 7.59%, while Bitcoin itself fell 75% from high to low over the same period.

For swing trading, that kind of downside protection can be worth giving up some raw return.

The Properties Tab: Where Backtests Live or Die

Inside the Strategy Report settings, the Properties tab is one of the most crucial parts of backtesting. Get this wrong, and your backtest won't align with reality.

Order size is the big one. Here's how the same strategy can produce wildly different results:

Order Size Setting What It Means
100% of equity Every trade uses your entire account. Maximum compounding — but not how most people actually trade.
% of equity (e.g., 10%) Each trade risks a fixed slice of your account. Mirrors disciplined position sizing.
Quantity Trade a fixed number of units (e.g., 10 Bitcoin) every signal.
USD Trade a fixed dollar amount (e.g., $1,000) per position — no compounding shown.

If you manually trade with only 10% of your account per position, but your backtest uses 100% of equity, the two will never match. Set the order size to reflect how you actually trade.

Portfolio tip: Platforms like Alpha Insider let you automate multiple strategies with different allocations — one at $1,000, one at 5% of your account, another at 20%. Blend those individual backtests together and you get a more realistic, diversified portfolio return.

Other Properties settings worth knowing:

  • Pyramiding — default is 0. If you don't know what it is, leave it. Changing it can throw off your results.
  • Bar magnifier / detailization — set to High for more tick data (32 ticks per bar) instead of just open/high/low/close. TC Trading recommends this for most people.
  • Commission — always add one, even a slightly high estimate, to model real trading accurately.
  • Slippage — always include a couple of ticks. There's always a gap between when a signal fires and when the trade actually executes. Try increasing slippage to see how fast your edge decays — a great stress test.
  • Leverage, limit order execution, and execution delay — configure these to match your live setup.

There's also a Style tab (purely visual — how signals and alerts appear) and a Visibility tab (which time frames the strategy displays on). Neither changes how the strategy operates.

Testing Different Time Frames

Changing the chart's time frame — say from 4-hour to 1-day — automatically updates the backtest report.

Why does this matter? Your entry logic (a breakout, an EMA cross, an RSI level) gets recalculated on each new time frame. Many strategies are highly sensitive to this: it works beautifully on one time frame and falls apart on another.

TC Trading's guidance:

  • For swing trading strategies, the best go-to time frames are typically 1-hour, 4-hour, daily, and weekly.
  • For day trading strategies, you'll want shorter frames like the 5-minute chart.
  • A swing strategy applied to a 5-minute chart usually won't align — it's meant to hold trades for longer periods.

Cycle through the time frames and find the settings that fit your strategy's intended style.

The Gut Check: Too Good To Be True

Here's the warning most people won't give you: when a backtest looks almost too good to be true, there's a very good chance one of two problems is hiding underneath:

  1. Curve fitting
  2. Repainting

A beautiful equity curve means nothing if it's built on either of these. Let's break them both down.

Curve Fitting Explained

Curve fitting is when you optimize your settings so perfectly for the past that they fail in the future.

You look at your data, tune the parameters until "this thing literally doesn't lose" — but the future is never identical to the past. It might rhyme, but a slight shift in market conditions can flip your strategy from wildly profitable to not even close.

How to test for curve fitting: Apply the strategy broadly to other assets.

  • If your Bitcoin strategy still holds up reasonably on Ethereum — maybe not as strong, but still profitable — that's a good sign.
  • On Solana it might degrade more, yet still show a similar, somewhat-profitable resemblance.
  • If the chart doesn't completely unravel across assets, your strategy isn't overly curve fit.

Also check your trade count. More trades = more statistical confidence. TC Trading's example had 99 trades, which is solid for a swing strategy (aim for at least ~100 when possible). But some strategies just don't fire often, so you work with what the logic gives you.

The ultimate test? Deep backtesting across many market regimes — bull markets, bear markets, recessions, COVID, booming economies. A strategy that survives all of them is far less likely to be a boom-and-bust trap.

Repainting Explained (And How to Catch It)

Repainting is when a strategy appears to fire at one point during a live candle, but after the candle closes, the signal moves or disappears — because it used data you couldn't have known in real time.

You'll spot the symptom in your trade logs: the entry or exit doesn't match where the criteria were actually met. That means your backtest is showing trades you could never have taken live.

Here are three ways to catch repainting:

  1. Forward test with Alpha Insider (best method). Your TradingView strategies send live alerts to Alpha Insider when they fire. Compare those real-time prices and fills against your backtest's trade list. If they line up closely, you're clean. If not, you've got repainting to investigate. (Note: web-hook alerts require a paid TradingView plan — the Essential plan or higher.)
  2. Paper trade or trade the signals live. Go to your strategy → three dots → Add Alert, and create an alert that fires when conditions are met. Track how the live signals compare to the backtest.
  3. Use the Bar Replay feature. Start a new replay and watch closely. A clean signal fires and stays put. If a signal fires and then moves after the candle finalizes, that's repainting — because in real life you'd execute the signal live and you're in or out, no hindsight edits allowed.

The whole point: if you can verify your live fills match your backtest, you can trust the backtest data. If they don't, the backtest is telling you a story that won't hold up with real money.

Frequently Asked Questions

Do I need to pay for TradingView to backtest?
No. You can backtest on the free basic plan. You'll be limited — no deep backtesting and less historical data — but it's enough to start. Only upgrade when you hit a genuine limitation.

What's the difference between a strategy and an indicator in TradingView?
An indicator only displays information; it doesn't execute trades. A strategy generates actual buy/sell signals and can be backtested. You must build a strategy to test performance.

Can AI write my Pine Script strategy?
Yes. Tools like Claude and ChatGPT can generate Pine Script from a plain-language description. But prompting is an art — give real context and specific requirements, and treat the output as a customizable starting point, not a finished product.

Why do my backtest results not match my live trading?
Usually one of three reasons: your order size settings don't match how you actually trade, you're not accounting for commission and slippage, or the strategy is repainting. The Properties tab is the first place to check.

What is curve fitting in backtesting?
It's over-optimizing your settings for past data so the strategy looks flawless historically but fails when market conditions shift. Test for it by applying the strategy to other assets and checking whether it still holds up.

What is repainting?
Repainting is when a strategy's signals change position after a candle closes, using information that wasn't available in real time. It makes a backtest look better than what you could actually trade. Forward testing and bar replay are the best ways to catch it.

How many trades should a backtest have to be reliable?
More is better for statistical confidence. TC Trading aims for at least ~100 trades on a swing strategy, though some strategies fire less often and you work with what the logic produces.

What settings should I always add in the Properties tab?
Always add a realistic commission and a couple of ticks of slippage to model live trading accurately. Set your order size to match how you truly size positions, and use High bar detailization for more accurate tick data.

What is forward testing and why does it matter?
Forward testing runs your strategy on live (or paper) markets going forward, so you can confirm real fills match your backtest. It's the single most reliable way to verify you don't have repainting problems before committing real capital.

Conclusion

Backtesting a trading strategy on TradingView is one of the most powerful ways to fact-check your trading before risking real money. Generate your Pine Script, add it as a strategy, read the report, and — most importantly — dial in the Properties tab so your backtest reflects how you actually trade.

But never stop at a pretty equity curve. Run the gut check: test other assets for curve fitting, and forward test for repainting. A backtest is only valuable if it tells the truth about live performance.

Ready to put this into practice? Head to TradingView, build your first strategy, and start testing. If you upgrade your plan, use TC Trading's link to save $15 — and wait for the Black Friday sale for the biggest discount. And if you want to forward test automatically and verify your fills without watching every trade, check out AlphaInsider.com. Then subscribe to TC Trading for deeper dives into building profitable strategies with AI.

Watch the full video here: