Pine Script Indicator vs Strategy: Differences and When to Use Each
6 min read · Updated
On TradingView, an indicator and a strategy look almost the same in the Pine Editor. An indicator draws on your chart. A strategy simulates trades and reports what they would have earned. Mixing up the two is the most common reason a script that looks great on history disappoints live. This guide covers the differences that change your results, plus the third script type, the library.
Indicator, strategy and library: what each one is for
- Indicator (
indicator()): calculates and plots. Use it for levels, signals drawn withplotshape(), dashboards, market bias and alerts built withalertcondition(). - Strategy (
strategy()): everything an indicator can draw, plus simulated orders throughstrategy.entry,strategy.exitandstrategy.close. TradingView runs those orders and fills the Strategy Tester with trade stats. - Library (
library()): a set of reusable functions you publish and thenimportinto other scripts. A library is never added to a chart on its own.
A single script declares exactly one of the three, so one script cannot be both an indicator and a strategy. A common setup is a library holding your shared logic, an indicator for the chart and alerts, and a strategy for testing.
The one-line difference
The very first line of a Pine script declares which kind it is. A script that opens with indicator() can only calculate and plot, lines, colors, labels, fills. It has no concept of a position, a fill price, or profit. A script that opens with strategy() adds an order-simulation engine: it can call functions like strategy.entry and strategy.exit, and TradingView runs those orders against historical bars to produce the Strategy Tester report, net profit, max drawdown, win rate, profit factor, and the list of simulated trades.
So the split is: an indicator describes conditions; a strategy asserts what those conditions would have earned. The second claim is far heavier than the first, because the moment you simulate orders you inherit a stack of assumptions about when and at what price those orders filled.
Where the backtest engine quietly makes assumptions
A strategy's equity curve is only as trustworthy as the fill assumptions underneath it. Four defaults do most of the damage:
- Bar-close evaluation. By default the tester evaluates your logic when a bar closes. If a condition references the bar's own high, low, or close, the historical "fill" may use information a live trade could not have had until after the bar completed.
- Next-bar-open fills. A market order placed on a signal fills at the open of the next bar in the simulation. On a fast open, that printed price can sit several ticks, or points, away from where you'd actually get filled.
- Zero friction. If
commissionandslippageare left at zero in thestrategy()call, every simulated trade is free, while every real trade pays commission and slippage. - Sample size. The tester will happily report a gorgeous curve built on twelve trades. Twelve wins is noise wearing the costume of an edge.
A worked example
Say a strategy shows +$4200 over 40 trades on ES futures with costs left at zero. Add a round-turn commission of about $5, retail futures commissions vary widely by broker, so use your own, plus one tick of slippage per side. On ES a tick is 0.25 points, worth $12.50, so one tick each way is $25. That's roughly $30 of friction per trade, about $1200 across 40 trades, dragging a headline +$4200 down toward ~$3000. And that's the polite version: if entries cluster on volatile opens, real slippage runs wider than one tick and the gap grows. None of that friction appears in the indicator version of the same logic, because an indicator never claims a fill in the first place. For more on separating a real edge from a fitted one, see how to spot overfit trading systems.
Signals: plotshape in an indicator, orders in a strategy
An indicator marks a signal with plotshape() or plotchar(), a triangle or label on the bar where your condition was true. Nothing gets bought, so the indicator has no trade stats. A strategy turns that same condition into an order with strategy.entry(), and the Strategy Tester then reports net profit, win rate, drawdown and the full trade list. To measure signal accuracy, move the condition into a strategy, add realistic costs and read the trade list.
Testing signals: on close vs intrabar
By default a strategy calculates once per bar, on the close, and a market order fills at the next bar's open. Three settings change that:
process_orders_on_close = truefills orders on the close of the signal bar.calc_on_every_tick = truerecalculates on every live tick. History only has finished bars, so live and historical results can differ.use_bar_magnifier = trueuses lower-timeframe data to decide which of a bar's prices came first when a stop and a target both sit inside one bar.
Signals confirmed on the bar close give the closest match between backtest and live results.
Intrabar signals still have a place. A breakout strategy that must act the moment price crosses a level can use calc_on_every_tick live, as long as you forward test the live version on a paper account first, because the backtest cannot show how the signal behaves inside a bar. For indicators, the same split applies to alerts: "Once Per Bar Close" waits for the confirmed bar, and "Once Per Bar" fires the first time the condition turns true inside the bar, even when the bar later closes the other way. The Pine Script FAQ covers alert settings in more detail.
Which script type works in the Pine Screener?
The Pine Screener runs indicators. To screen for a strategy's setup, put the condition in an indicator and plot the value you want to filter on.
What repainting actually means
"Repainting" gets thrown at any script that shows different values in hindsight than it did in real time, but the label is often misapplied. The honest test is one question: could this decision have been made with the same information, at the same moment, live? A signal that only confirms on bar close simply asks you to wait for the close. The genuinely misleading cases are signals plotted on the still-forming bar that then jump once it finishes, or higher-timeframe data pulled with lookahead. Evaluating logic on a confirmed bar keeps your backtest and your live experience honest with each other, whether you're building an indicator or a strategy.
How this maps onto the Trade Plans
Trade Plans deliberately sidesteps the repaint problem by handing you fixed, pre-planned levels. The daily levels, the levels for ES, SPY, NQ and QQQ, are computed after the prior close and do not move during the session. There is nothing to repaint: each level is set before 9:30 ET and stays put. MyLinedChart, which draws those lines, works like an indicator. It plots the levels and simulates nothing, so they carry none of the fill or commission assumptions above. If a published level disagrees with what your own strategy is telling you, that disagreement is information, and often the answer is to wait.
Building a strategy from your own levels
Most strategies trade around prices that a trader already drew by hand: support, resistance, a pivot. MyLinedChart exports every line, level, note and indicator on your chart as JSON, CSV or XLSX. Hand that file to ChatGPT, Claude or your own code and ask for a Pine Script strategy that trades those exact prices. You and your AI decide how the strategy enters and exits.
A short checklist before you trust either script type
- Know which you're holding:
indicator()only draws;strategy()simulates orders and produces the Strategy Tester report. - On a strategy, set realistic
commissionandslippagefor the instrument you actually trade before reading a single profit number. - Confirm logic on closed bars so history and live share the same decision moment.
- Judge results on enough trades to matter.
- Keep contextual overlays (like published levels) separate from execution authority, the chart informs the call; your written rules make it.
Used this way, an indicator is a lens and a strategy is a hypothesis. Test both on real fills before you trust them.
Related Reading
Sources
- TradingView Pine Script Docs: Strategies
- TradingView Pine Script Docs: Repainting
- CFTC: Trading System Fraud Advisory
Educational content only. Not investment advice.
Educational content only. Not investment advice.