Guide
How to Backtest a Pine Script Strategy
To backtest a Pine Script strategy on TradingLead, open Indicator Studio on /charts, paste or write a strategy() script, compile it and click Apply & backtest. You can also select it in the Backtesting tab with the TLScript-Pine strategy() language. TradingLead runs a documented Pine v5/v6 subset in a broker emulator and reports its actual fills, fees and equity. Results are not guaranteed to match TradingView.
TradingLead can backtest Pine Script strategy() scripts, the same kind of script you might use in TradingView's Strategy Tester, on your TradingLead chart. This guide covers getting a script running, configuring it and reading the results honestly.
How Pine strategies run on TradingLead
TradingLead supports a documented subset of Pine v5/v6 (TLScript-Pine). A strategy() script runs in a Pine broker emulator, and its actual fills, entry lots, allocated fees and candle-close equity are carried into the same report used for Python strategies. TradingLead does not re-simulate your signals with a different fill model.
This is not TradingView parity. Function coverage, fill details and edge cases can differ, so a script may produce different numbers than on another platform. For indicator-only scripts, see Run a Pine Script indicator and the Pine Script feature page.
Step 1: Open the chart
Go to tradinglead.in/charts and choose the feed, symbol and interval. The backtest uses this chart's data source.
Step 2: Write or paste the strategy in Indicator Studio
Open Indicator Studio, switch to Pine, and either load the bundled SMA crossover strategy example or paste your own script. It must call strategy(...) (not indicator(...)). Studio detects strategy scripts from the code itself.
Compile the script. If you get errors, check whether you used functions outside the supported subset, then simplify or replace them. Save the script so you can reuse it.
Step 3: Apply & backtest
For a strategy script, Studio's main action becomes Apply & backtest. It hands the exact draft, its typed inputs and per-run settings to the Backtesting panel.
Alternatively, open the Backtesting tab, set the language to TLScript-Pine strategy() and pick your saved Pine source.
Step 4: Configure inputs and execution settings
- Inputs: your script's
input.*values, keyed by declared variable name. - Execution settings (optional overrides): initial capital, default quantity type/value, commission type/value, slippage (whole ticks), pyramiding, long/short margin,
process_orders_on_closeand limit-fill verification ticks.
Leave an override empty to keep the value declared in your strategy() call. Set commission and slippage to values that reflect your broker and the instrument's liquidity.
Choose the history range: up to 20,000 closed candles, or explicit dates. If the source can't supply the range, the run fails rather than testing fewer candles.
Step 5: Run and review
Run the backtest and wait for completed. Then review:
- Summary metrics and Analytics: net P&L, max drawdown, win rate, profit factor, expectancy and buy-and-hold comparison.
- Pine strategy report: the emulator's own summary. Its drawdown may include intrabar extremes, while the main report uses candle-close equity.
- Execution assumptions: the panel shows that results come from the Pine
strategy()emulator. - Chart: actual fill markers plus the plots and drawings your script produced from the same execution. Toggle script plots and drawings separately from trade markers.
Fill behaviour to know
- Market orders normally fill at the next candle's open; with
process_orders_on_closean extra closing-price order pass runs after each candle. - Slippage applies to market and stop fills, not limit fills.
- Stop-limit orders activate their limit leg only after the stop is crossed.
calc_on_every_tick,calc_on_order_fills,calc_on_every_history_tick,use_bar_magnifierandfill_orders_on_standard_ohlcare rejected, not ignored.
Step 6: Go further
- Optimize declared inputs with the Strategy Optimizer using holdout or walk-forward splits.
- Branch a manual paper trading replay from the completed run. Pine branches start a new flat shared-engine account that does not inherit Pine costs or margin, and automatic Pine replay/forward execution is unsupported.
- Save the run to compare it later with other runs on the same candles.
Limitations
- Supported Pine is a documented v5/v6 subset. Some TradingView scripts won't compile or may behave differently.
- Pine backtests are vectorized only. Source lookahead (for example, misuse of higher-timeframe requests) remains the author's responsibility.
- Historical fills are candle-based, not tick-accurate.
- Backtests are simulations on past data. They are not investment advice and don't guarantee future results.
Steps
- Open /charts and choose symbol and interval.
- Open Indicator Studio, select Pine, and paste or write a strategy() script (or load the SMA crossover example).
- Compile and fix any errors, then save the script.
- Click Apply & backtest, or select the saved script in the Backtesting tab with language TLScript-Pine strategy().
- Adjust inputs and execution settings (capital, quantity, commission, slippage ticks).
- Run and wait for completion, then review metrics, Pine report and chart trades.
Limitations
- Documented Pine v5/v6 subset only; not full TradingView parity.
- Tick-level and bar-magnifier options are rejected; fills are candle-based.
- Pine runs are vectorized only, up to 20,000 candles.
- Setup presets and sequential callbacks are Python-only; automatic Pine replay/forward is unsupported.
- Simulated results on past data; not investment advice.
Frequently asked questions
- Can I paste my TradingView Pine strategy into TradingLead?
- You can paste it into Indicator Studio and compile it. Scripts that use TradingLead's documented Pine v5/v6 subset will run. Unsupported functions produce compile or runtime errors, and results are not guaranteed to match TradingView's Strategy Tester.
- Which strategy() settings can I change per run?
- Initial capital, default quantity type and value, commission type and value, slippage in ticks, pyramiding, long and short margin, process_orders_on_close and limit-fill verification ticks. Anything you don't override keeps the script's strategy() defaults.
- Which Pine strategy options are not supported?
- calc_on_order_fills, calc_on_every_tick, calc_on_every_history_tick, use_bar_magnifier and fill_orders_on_standard_ohlc are rejected rather than silently ignored. Historical fills are candle-based, not real-tick.
- Do I need Python to run a Pine strategy?
- No. Pine strategies run in the Pine runtime and don't depend on Python being available.
- Why is the drawdown different from the Pine report drawdown?
- The main report measures drawdown on completed-candle equity. The separate Pine emulator summary may include intrabar extremes, so the two numbers can differ.
Related
Last updated: