PineScript v6: What Traders Need to Know Before Building Indicators
Before building in Pine Script v6, know that it's the current version of TradingView's charting language, and your script tells TradingView which version to use with a line at the very top: //@version=6. Starting on the right version matters because v6 changed some rules, so code copied from older tutorials may not compile. A few basics to keep in mind: every indicator or strategy has one declaration line, indicator() or strategy(), right after the version. Pine works bar by bar, running your code once for each candle from left to right, which trips up beginners who expect it to run once. Built-in functions live under namespaces like ta. for calculations and request. for outside data. Get the version line and the bar-by-bar idea straight first, and the rest of the language gets much easier.
The key syntax and structural differences in v6 that traders should understand before writing or modifying PineScript code.
Key points
- Pine Script v6 is the current version of TradingView's language, and you select it with //@version=6 at the very top of the script.
- Version matters because v6 changed some syntax, so older copied code may not compile until you update it.
- Right after the version line comes one declaration, indicator() or strategy(), that sets the script's type and behavior.
- Pine runs bar by bar, executing your code once for each candle from left to right, not once for the whole chart.
- Built-in tools live under namespaces, like ta. for technical calculations and request. for pulling other data, so names look like ta.sma().
- Getting the version line and the bar-by-bar model straight first makes everything else in the language easier to learn.
Frequently asked questions
How do I set the Pine Script version to v6?
Put //@version=6 as the very first line of your script, before anything else. TradingView reads that line to decide which rules to apply, so if it's missing or wrong, the rest of your code may not behave the way tutorials show.
Why won't my old Pine Script code compile in v6?
v6 changed some syntax and removed older parameters, so code written for earlier versions can throw errors until it's updated. If you're pasting code from an old guide, expect to fix a few lines to match the current version.
What does it mean that Pine runs bar by bar?
Your code executes once for each candle, moving left to right across the chart, and it keeps track of values as it goes. Beginners often expect it to run one time for the whole chart, and understanding the bar-by-bar flow clears up a lot of confusion.
What are namespaces like ta. and request. in Pine?
They group built-in functions by purpose. ta. holds technical analysis tools like ta.sma() for a moving average, and request. pulls in outside data like a higher timeframe. The prefix tells you what kind of function you're calling.
Is there a faster way to get correct v6 code as a beginner?
In Agenticks, AlgoAgent can generate Pine Script v6 code from a plain description, following current version rules, so you get a working starting point to paste into TradingView and study. It's a learning aid, not a promise of trading results.
Related on Agenticks
This content is for educational purposes only and does not constitute financial advice. Trading involves risk, including possible loss of capital.