Strategy Backtester

How to Backtest a Pine Script Strategy on Your Own Data

Step by step: prepare Excel candles, convert a TradingView Pine Script strategy and read the results, including entries, exits, fills and costs.

Updated · 5 min read

Why test Pine Script outside TradingView

TradingView's strategy tester is convenient, but it only uses the data TradingView provides. If you trade an instrument, session or data vendor that differs from the chart, or you want to test a custom candle file, you need to run the logic on your own data.

Because Pine Script only executes inside TradingView, the strategy has to be translated into code that can run somewhere else. That translation must keep the same lengths, sources, conditions and order handling, otherwise the results are not comparable.

Step 1: prepare your candle file

Create an Excel or CSV file with one row per candle and the columns timestamp, open, high, low and close. Add volume if your script uses it, for example for VWAP.

Keep the timestamps in exchange time. Sort order does not matter, and duplicate timestamps are de-duplicated. The timeframe of the file is detected automatically, and you can test on that timeframe or any larger multiple of it.

Step 2: convert the Pine Script

Paste the script or upload a .pine file. The converter reads inputs, indicators, conditions and strategy.entry, strategy.exit and strategy.close calls, and turns each input() into a setting you can change before running.

Always read the converter notes. They list anything that was approximated or unsupported, such as drawing objects that do not affect trading or multi-timeframe calls that were mapped to completed higher-timeframe bars.

Step 3: choose fills and costs

Decide whether entries fill at the close of the signal bar, which matches a bot that acts on candle close, or at the next bar's open, which is the TradingView default. The choice can change results noticeably on fast timeframes.

Set commission per order and slippage in points. A strategy that looks profitable with zero costs often is not once realistic costs are included.

Step 4: read the results

Start with the trade list rather than the totals. Check a handful of entries and exits against the chart to confirm the logic behaves as you expect. Then look at profit factor, maximum drawdown and the monthly breakdown to see whether returns are consistent or driven by a few months.

Ready to try it? Open the backtester and run your strategy on your own candles.