Step-by-step guide to backtesting trading strategies

Stop Guessing: How to Actually Backtest Strategies on TradingView

Most traders fail not because their logic is bad, but because they never test it against market reality. Backtesting is the process of running your trading rules against historical data to see if the strategy makes money in the past. If it doesn’t work in the past, it almost certainly won’t work in the future. TradingView is the most accessible tool for doing this, but it has pitfalls that can give you false confidence. Here is the concrete, step-by-step process to do it right, without wasting time on vanity metrics.

1. Pin Down Your Rules Before You Touch the Mouse

You cannot test a vague idea like "buy when it looks low." TradingView’s strategy tester requires binary, mathematical rules. You must define:

If you haven’t written these rules down, you are not ready to open Pine Editor. Vague strategies lead to "curve fitting," where you tweak parameters until the backtest looks good, but the strategy is actually over-optimized and will fail in live trading.

2. Use the Strategy Tester, Not the Indicator Panel

A common mistake is using regular indicators to visually scan charts. This is subjective and impossible to quantify. You need to use Pine Script to create a Strategy, not an Indicator.

  1. Open the Pine Editor at the bottom of the TradingView chart.
  2. Click "New blank file".
  3. Type "strategy()" at the top of the file. This initializes the backtesting engine.
  4. Add your strategy.entry(), strategy.exit(), or strategy.close() commands based on your rules.
Once you click "Add to Chart," a "Strategy Tester" panel appears at the bottom. This is the only section that calculates profit, loss, and win rate.

3. The Critical Settings: Slippage, Fees, and Bars

Default settings often make strategies look better than they are. Adjust these before judging performance:

4. Interpret the Metrics That Matter

The Strategy Tester outputs many numbers. Ignore "Profit Factor" alone and look at this combination:

5. Out-of-Sample Testing to Prevent Overfitting

This is the step most people skip. If you optimize a strategy on data from 2018–2023, it will look perfect. Then you trade it in 2024, and it fails. You must reserve a period of data that your strategy has never seen. For example, if you optimize on 2015–2020, you must test the exact same parameters on 2021–2023 data. If the strategy performs poorly on this "out-of-sample" data, it is curve-fitted and worthless. If it performs consistently across both periods, it has statistical robustness.

6. Forward Test on Paper

Backtesting is historical. It assumes you could execute every trade perfectly at the close of the bar. In reality, you might not see the signal, or the market might gap against you. After a successful backtest, run the strategy in TradingView’s "Paper Trading" mode for at least two weeks. Do not risk real capital until the paper trades match the backtest results closely.

When You Need More Control

If manual Pine scripting feels too slow or you want to test complex risk management rules without coding every line, there are tools designed to automate the construction of these strategies. The Automated Strategy Builder offers a free demo of a platform that helps generate and structure automated trading strategies, allowing you to test logic with less friction if you prefer a guided environment over writing code from scratch. You can check it out here: Automated Strategy Builder
free demo of a platform that builds automated trading strategies
See it

More guides