Backtesting guide

A practical Pine Script backtesting workflow

Pine Script backtesting uses a script declared with strategy() on a TradingView chart. TradingView simulates its orders and produces the Strategy Tester report; the script defines the rules, not the historical data or execution engine.

Read the practical guide

Key Takeaways

  • Use strategy() rather than indicator() when the script must place simulated orders.
  • Set commission, slippage, sizing, pyramiding, and order timing explicitly.
  • Avoid look-ahead logic and synthetic chart prices when they do not represent executable prices.
  • Pineify can generate source and automate inputs, while TradingView runs the backtest.

Build the smallest complete Pine strategy

Declare the script with strategy(), expose only the inputs that serve a real rule, calculate signals from data available at that bar, and place entries and exits with explicit position behavior. Add sufficient-history guards so indicators do not trade before their lookback is available. Plot important signals when visual review will help catch implementation mistakes.

Configure Strategy Tester assumptions

TradingView documents commission and slippage properties for strategy simulations and notes that their defaults may not represent real trading. Record the symbol, timeframe, date range, order-processing settings, initial capital, sizing, pyramiding, commission, and slippage. Avoid drawing conclusions from nonstandard chart types when synthetic prices do not match executable market prices.

  • Save script version and all inputs.
  • Model costs before comparing parameter sets.
  • Inspect the List of Trades for impossible order behavior.

Use free access carefully

Current TradingView and Pineify plan limits can change, so verify official product terms instead of relying on a timeless “free” label. Regardless of plan, the validity of the test depends on the same rules: documented data, realistic assumptions, no future information, a frozen baseline, and confirmation on unseen data.

Direct Pineify workflow

Create the Pine strategy, then automate deliberate input tests

Pine Script AI Coding Agent can generate editable strategy source from an explicit specification. Strategy Optimizer can automate selected inputs after you verify the baseline in TradingView.

Pine Script AI Coding Agent

Generate editable strategy() code from documented entry, exit, and risk rules.

Generate Pine Script strategy code
Strategy Optimizer

Automate a bounded input grid after the baseline script is correct.

Optimize the reviewed strategy

Boundary: Pineify does not provide TradingView chart data or run Strategy Tester. Generated source and optimized parameters must be reviewed for logic, bias, and stability.

Primary sources

This page is educational and does not provide investment advice. Backtests are hypothetical, depend on their data and assumptions, and do not guarantee future results. Trading can result in substantial loss.

Frequently Asked Questions