TradingView / Source CodeSeptember 4, 2026 · 10 min read

How to Backtest a Strategy in TradingView (Without Fooling Yourself)

The TradingView Strategy Tester will happily show you a beautiful equity curve that means nothing. Here is how to run a backtest whose results you can actually trust.

Backtesting in TradingView is easy to do and remarkably easy to do badly. The Strategy Tester will produce a net profit figure, a win rate and an equity curve within seconds of adding a strategy to a chart — and none of those numbers mean anything until several unglamorous settings are correct.

This guide covers the mechanics of running a backtest and, more importantly, the specific ways backtests mislead traders on futures and gold.

Step 1: add the strategy to the right chart

  1. 01Open the exact instrument and data feed you intend to trade — not a similar one. NQ from one provider and a CFD proxy are not interchangeable, and spot XAUUSD is not Gold futures.
  2. 02Set the exact timeframe the strategy was designed for. A 1-minute execution model tested on 5 minutes is a different system with different behaviour.
  3. 03Open the Pine Editor, paste the strategy source code and click 'Add to chart'.
  4. 04Open the Strategy Tester panel at the bottom of the chart.

Step 1 already eliminates a large share of misleading results. Most disappointing live performance traces back to a backtest run on a different symbol, feed or timeframe than the one traded.

Step 2: set commission and slippage before you look at anything

By default, a backtest can assume frictionless trading. On an intraday futures strategy that takes several trades a day, friction is not a rounding error — it is often the entire difference between a profitable curve and a losing one.

In the strategy Properties tab, set the commission to your broker's real cost per contract or per trade, and set slippage to a realistic number of ticks for the instrument and session you trade. Then look at the results. A strategy that only works at zero cost has already told you what you needed to know.

Step 3: check the sample size before the profit

The first number most traders read is net profit. The first number worth reading is the number of closed trades.

Thirty trades tell you almost nothing — a single lucky sequence dominates the result. A few hundred trades across different market conditions start to describe behaviour. If a strategy only produces a handful of signals over the available history, the correct conclusion is 'not enough evidence', not 'promising'.

A backtest with too few trades is not a weak result. It is not a result.

Step 4: test the periods you would rather skip

Every trend-following system looks excellent during a strong directional stretch. The useful question is what it did during the chop — the range-bound months, the low-volatility summer, the transition after a major reversal.

Use the date range tools to isolate those periods deliberately. A system whose drawdown during choppy conditions is survivable is a system you can actually trade. A system that only works in the good half of the data is a curve fit waiting to disappoint you.

Step 5: is the TradingView Strategy Tester accurate?

It is accurate about what it simulates, and its simulation has known limits. Three matter most.

  • Intrabar behaviour: on standard backtesting the tester works from bar data, so when both stop and target could have been hit inside the same bar, assumptions are made. On fast instruments like NQ, this can flatter results.
  • Historical depth: available history depends on your TradingView plan and the instrument, and shorter history means smaller samples.
  • Repainting: strategies referencing higher timeframe or non-confirmed values can behave differently live than in history. This is exactly why source-code access matters — you can read whether future-referencing is involved instead of guessing.

None of this makes the Strategy Tester useless. It makes it a filter rather than a forecast: excellent at rejecting bad systems, unreliable as a promise of future numbers.

Step 6: forward test before you size up

After a backtest survives realistic costs and unfavourable periods, the next step is not real capital — it is watching it in real time. Run the strategy live on a chart, or on a simulated account, for enough sessions to see whether live signals match the historical ones in timing and character.

This is also the phase where repainting reveals itself. If signals in real time appear at moments the historical chart does not reflect, you have learned something no backtest would have told you.

Step 7: change one thing at a time

Optimisation is where honest backtesting most often becomes self-deception. Adjusting six parameters until the equity curve looks beautiful produces a system tuned to the past, not to the market.

A more defensible approach: change one parameter at a time, and prefer settings that work acceptably across a range of neighbouring values rather than the single best number. A parameter that only works at exactly 14 and fails at 13 and 15 is describing noise.

Why locked scripts cannot be backtested honestly

Everything above assumes you can inspect and adjust the strategy. With an invite-only or obfuscated script, you can run the tester, but you cannot see what triggers an entry, cannot check for future-referencing, and cannot adjust filters to test robustness. You are testing a black box and calling the output evidence.

With the complete Pine Script in hand, backtesting is a normal engineering activity: read the conditions, set realistic costs, run, isolate periods, vary one parameter, compare, decide.

Frequently asked questions

How much history do I need?

Enough to include several distinct market conditions and a few hundred trades. For a 1-minute intraday system that may be a few months; for a swing system it can require years.

Should I trust a vendor's backtest screenshot?

No — not because vendors are dishonest by default, but because a screenshot omits the instrument, feed, period, commission and slippage assumptions that determine the result. Run your own.

Does a good backtest mean the strategy will work?

No. Historical and backtested performance does not guarantee future results. A good backtest means the strategy is not obviously broken and behaves as described — which is a necessary condition, not a sufficient one. Trading involves substantial risk and nothing here is financial advice.

Related system

Backtesting needs code you can actually read

Futures Confluence Matrix Pro ships with the complete, editable Pine Script source code — no lock, no obfuscation — so you can run it in the Strategy Tester on your own instrument and data feed, adjust parameters and verify every condition yourself. Installation guide and FAQ document included.

Secure checkout and instant digital delivery through Etsy — buyer protection included, no account with us required.

Keep reading