Pine Script: Indicator vs Strategy, and When to Use Each
In Pine Script, an indicator just displays information on your chart, while a strategy simulates real trades so TradingView can backtest it and show results. An indicator script uses the indicator() declaration and plots things like lines, shapes, or alerts, but it never places orders or tracks profit and loss. A strategy script uses the strategy() declaration and adds commands like strategy.entry and strategy.exit, which let TradingView pretend to buy and sell across historical bars and then report metrics like win rate, drawdown, and net profit. So the quick rule is this: if you want to see something on the chart, write an indicator. If you want to test whether a set of rules would have made or lost money, write a strategy.
An indicator draws context. A strategy simulates entries and exits and gives you stats. Which to build, and how to convert one to the other.
Key points
- An indicator starts with indicator() and only shows information, like lines, shapes, or alerts, without placing any simulated orders.
- A strategy starts with strategy() and can place simulated buy and sell orders using commands like strategy.entry and strategy.exit.
- Only a strategy produces a backtest report with metrics like net profit, win rate, and drawdown in TradingView's Strategy Tester.
- Indicators are best for spotting or highlighting conditions; strategies are best for testing whether trading rules hold up over history.
- You can't mix the two declarations in one script, so a script is either an indicator or a strategy, never both at once.
- Backtest results from a strategy show what would have happened on past data, which is context, not a promise about the future.
Frequently asked questions
What's the simplest way to tell an indicator and a strategy apart?
Look at the first line. If it says indicator(...), the script only draws on the chart. If it says strategy(...), it can simulate trades and give you a backtest report. That one line changes what the whole script is allowed to do.
Can an indicator show buy and sell arrows?
Yes, an indicator can plot arrows or shapes where a condition is true, and it can fire alerts. What it can't do is track those arrows as actual trades or calculate profit and loss. For that you need a strategy.
Does a strategy backtest mean the rules will work going forward?
No. A backtest only shows how the rules would have behaved on past bars. Markets change, and past results are context, not a guarantee. Treat a good-looking backtest as a reason to study further, not proof of future returns.
Which one should a beginner learn first?
Start with indicators. They teach you the language with less to go wrong, since you're just plotting values. Once you're comfortable, moving to a strategy is mostly about adding entry and exit rules on top of what you already know.
Do I have to write either one by hand?
Not necessarily. In Agenticks you can tell the AlgoAgent what you want to see or test, and it writes the Pine Script indicator or strategy for you, then you run it in TradingView. It's a faster way to go from an idea to working code you can read and edit.
Related on Agenticks
This content is for educational purposes only and does not constitute financial advice. Trading involves risk, including possible loss of capital.