What is Pine Script
Pine Script is TradingView's language for building custom indicators and strategies. Learn what it is for and how a script reads data, calculates, and draws.
Part of the Tools of the Trade: TradingView, Indicators, Pine track on Agenticks. About 10 minutes, written for a intermediate reader.
By now you know an indicator is just a calculation drawn on a chart. So where do those calculations come from? On TradingView, most of them are written in a language called Pine Script. Pine Script is TradingView's own scripting language. It is the tool you use to tell the platform what to calculate from price, volume, or time, and what to draw on the chart as a result. Every built in indicator, and every custom one shared by the community, is a Pine script underneath. When you add RSI to a chart, you are running someone's Pine code. The name itself is a small clue to the philosophy. Pine is meant to be lightweight, like a sketch rather than a full application. You are not building software in the usual sense. You are describing a calculation and a few things to draw, and TradingView handles the rest: feeding in the data, running your code on every bar, and updating the chart as new prices arrive.
Pine Script is how a calculation becomes a chart tool
The built in indicators cover the common cases, but your idea might not be one of them. Pine Script is the bridge: you write the math once, and TradingView plots it on every bar, on any symbol, updating live. It is not a general purpose language for building apps. It is a focused, chart first language for turning a market idea into something visible and testable on a price chart.
A Pine script generally does three things, in order. First it reads inputs: the price series (open, high, low, close), volume, and any settings you expose to the user, like a length or a color. Second it calculates: it runs your formula across the chart one bar at a time, so the value is recomputed as each new bar forms. Third it outputs: it plots a line, draws a shape, fills a band, or fires an alert when a condition is met. That is the whole loop. Read data, do arithmetic, draw the result. A 50 period moving average is a handful of lines. A full order flow style tool is more code, but it is the same pattern repeated. Nothing in that loop predicts the future. A script can only repackage the data you feed it, exactly like any other indicator.
A Pine script runs once per bar
This is the mental model that makes Pine click. Your code does not run once over the whole chart. It runs from left to right, once on each bar, as if it were living through history one candle at a time. On the live bar it runs again on every price tick until that bar closes. That is why a value updates as the candle forms, and it is also why a careless script can accidentally use information from a bar that has not finished yet.
It is worth saying plainly: Pine Script does not give a script special powers. It is a calculator with a drawing pen attached to a chart. A script written in Pine is held to exactly the same honesty test as any indicator you did not write yourself. In particular, Pine can be misused to create repainting tools, where the script quietly changes its past output after the fact so the chart looks perfect in hindsight. This usually happens when code peeks at data that was not final when a bar first formed. Reading the actual Pine code is the surest way to catch this, because the logic is right there. A label on a marketplace listing can lie. The formula cannot. This is the quiet superpower of knowing even a little Pine. You do not have to take anyone's word for what a tool does. You can open the script, find where it reads price, find where it draws, and check whether it ever reaches for data it should not have yet. That is the difference between trusting a screenshot and trusting the math. You can read a calculation and decide for yourself, instead of buying a story about it.
In one sentence, what is Pine Script for? Writing custom indicators and strategies that calculate and draw on a TradingView chart Right. Pine Script is TradingView's language for defining what a tool calculates from price or volume and what it plots on the chart. Every built in and community indicator is Pine underneath.
- //@version=6
- Declares which version of Pine the script runs
- indicator()
- Names the tool and sets overlay or separate panel
- ta.sma(close, 50)
- Calculates a value from the price series
- plot()
- Draws a calculated value on the chart
Put the three jobs of a Pine script in the order they run.
- Read the inputs: price, volume, and user settings
- Calculate the value across each bar
- Output the result: plot a line, mark a shape, or fire an alert
language TradingView calculation predict
You can now explain Pine Script clearly
Pine Script is TradingView's scripting language for building custom indicators and strategies. A script reads price and volume, calculates a value bar by bar, then draws or alerts on the result. It is still just a calculation, held to the same honesty test as any indicator, and tools like AlgoAgent can generate readable Pine v6 from a plain description.
Common questions
- What is Pine Script used for?
- Pine Script is the programming language built into TradingView. You use it to define how a custom indicator or strategy calculates its values and what it draws on the chart, so you can study an idea that no built in tool already shows.
- Do I need to know how to code to use Pine Script?
- To write it by hand, yes, you need some basic coding comfort. But you can read a finished script to understand what a tool does without writing it. Tools like AlgoAgent also generate Pine v6 from a plain description, so you can study the output rather than start from a blank file.
- Is a Pine Script the same as a trading signal?
- No. A script is just a calculation that draws on the chart. It can plot lines, mark conditions, or fire an alert, but it does not know the future and it is not advice. Whether anything it shows is useful still has to be tested honestly.
Terms defined in this lesson
Continue
Sources