Pine Script Explained, and What You Can Build Without Learning It
What Pine Script is, what it can and cannot do, where to write it, and how far you can get describing what you want instead of coding it.
Key Takeaways
- Pine Script runs only on TradingView and evaluates once per bar.
- The Pine Editor is built into every chart and works on the free plan.
- Indicators draw and alert. Strategies place simulated orders and backtest.
- Most beginner confusion is the bar-by-bar execution model, not the syntax.
- You can get a working script by describing it rather than writing it.
Pine Script is the language TradingView uses for custom indicators and strategies. If you have ever wanted a chart to mark something specific — the previous day's range, a session high that held on retest, a break with an ATR filter — Pine is how that gets built.
This covers what it is, what it will and will not do, and how far you can get without learning it.
What it actually is
A domain-specific language that only runs on TradingView. You write a script, TradingView compiles and runs it against the chart in front of you, and the output appears on that chart.
Two kinds of script, and the distinction matters because it changes what is available to you:
An indicator draws and alerts. Lines, shapes, labels, tables, background colours, plus alert conditions. It does not place orders and produces no performance report.
A strategy places simulated orders and produces a backtest — trades, equity curve, drawdown, profit factor. You get the Strategy Tester panel with a full trade list.
If you want to know whether a set of rules would have made money, you need a strategy. If you want the chart to point something out and leave the decision to you, an indicator is simpler and enough.
The one concept that causes most confusion
Pine evaluates your script once per bar, from the oldest bar to the newest.
That sounds obvious and produces almost all early mistakes. On the bar currently forming, values are not final — the close is whatever price happens to be at that instant, and it changes until the bar completes. So a condition that references the current close can be true, then false, then true again, all within one bar.
This is why the same script can appear to signal something in real time and show nothing there afterwards. It is also why close[1] — the previous bar's close — behaves predictably while close does not.
Where to write it
The Pine Editor opens from a tab along the bottom of any TradingView chart, and it works on the free plan.
Practice workflow
From code to chart
- Open any chart on tradingview.com
- Click Pine Editor at the bottom of the window
- Delete the placeholder code that appears
- Paste or write your script
- Click Save and give it a name
- Click Add to chart
If it compiles it appears immediately. If not, the error and its line number show at the bottom.
What a simple script looks like
Even without knowing the language, the structure is legible:
//@version=6
indicator("Previous Day Range", overlay = true)
[prevHigh, prevLow] = request.security(syminfo.tickerid, "1D", [high[1], low[1]], lookahead = barmerge.lookahead_on)
plot(prevHigh, "Prev Day High", color = color.red)
plot(prevLow, "Prev Day Low", color = color.green)
Line by line: the version declaration, then the script's name and that it draws over the price rather than in a separate pane, then a request for yesterday's completed high and low, then two plots with colours.
The [1] is doing important work. Without it you would get today's forming high and low, which change as the session progresses.
What Pine cannot do
Worth knowing before you plan around it.
It cannot place real orders. A strategy trades simulated positions and can fire alerts. Connecting those alerts to a broker requires an external service, which is outside TradingView.
It cannot read arbitrary external data. You get TradingView's symbols and a limited set of built-in sources. No calling your own API from inside a script.
It cannot run anywhere else. Pine is not portable. MetaTrader uses MQL, cTrader uses C#, NinjaTrader uses NinjaScript. A Pine script does not transfer to any of them; the logic has to be rewritten in that platform's language.
Bar limits apply. How much history a script can access depends on your plan, which matters when backtesting a rule that triggers rarely.
How far you can get without learning it
For a long time the only options were to learn Pine or pay someone. That has changed, and the honest version of what changed is worth stating carefully.
Describing an indicator in plain English and getting working Pine back is reliable today for most retail setups — moving averages, breakouts, session levels, previous-day ranges, strategies with stops and targets. The generated code compiles and runs.
What still needs you is the description and the checking. Anything vague in what you asked for becomes a guess in the script, and the most common failure is not a compile error but a script that builds cleanly and does something slightly different from what you meant. Verifying that does not require reading Pine — it requires checking the chart. Does anything draw on the price pane, do the levels sit where you expect, does it mark the bars you intended, and does it stay quiet on the ones you did not.
That last check is the one people skip. A condition looser than you described is invisible if you only look at the signals that fired.
Learning it properly, if you want to
If you do want to write it yourself, the order that works:
- Plot something. A moving average, then a level you calculate. Get used to the editor and the save-and-add cycle.
- Understand bar-by-bar evaluation before anything else. Everything confusing later comes back to this.
- Learn
input()so values are adjustable from settings rather than edited in source. - Add conditions and shapes.
plotshapewithlocation.abovebarandlocation.belowbarcovers most marking. - Only then attempt a strategy. Order management has its own rules, and the argument names are exact —
from_entry, notfromEntry.
The reference documentation is genuinely good and searchable. Most errors that look mysterious are a function name that does not exist, and searching the exact name settles it in seconds.
Review checklist
Before you rely on any script, written or generated
- It compiles with no errors
- Something visible appears on the price pane rather than only the data window
- Levels line up with the bars they are meant to describe
- It marks the bars you expected
- It stays silent on the near-misses you did not want marked
- For a strategy, the exit reasons in the trade list match your intent
The part the language does not decide
A script that compiles and draws correctly can still be a bad idea, and Pine will implement a bad idea faithfully. We tested a session range strategy that built with zero errors and executed precisely as written, finishing at a profit factor of 0.939 because the session-close rule cut winners short while losers ran the full stop distance.
Nothing was wrong with the code. The rules were lopsided, and that only shows up when you test them and then practise reading them on charts you have not already studied.
Next step
Replay strategy code setups inside SkillCandle
Move from reading about the setup to actually practicing it with a partial chart, replay reveal, and tracked review notes.
FAQ
Questions traders ask about this topic
What is Pine Script?
TradingView's own programming language for building indicators and strategies. Scripts run on TradingView's servers against the chart you are viewing, so you can plot custom levels, mark conditions, and backtest a set of rules without leaving the platform. It only runs on TradingView.
Where do I write Pine Script?
In the Pine Editor, which opens from a tab along the bottom of any TradingView chart. It works on the free plan. Paste or type your code, save it with a name, then click Add to chart.
Is Pine Script hard to learn?
Easier than a general purpose language because it does one thing, and harder than it looks because it evaluates once per bar. Most confusion comes from that execution model rather than from the syntax, particularly which values are final and which are still forming.
What is the difference between Pine v5 and v6?
Version 6 is stricter about types and changed some namespaces. Most v5 code still runs, but pasting older snippets into a v6 script tends to produce type and namespace errors rather than logic errors. The version is declared on the first line.
Can Pine Script place real trades?
No. A strategy can be backtested and can fire alerts, but Pine cannot execute orders with a broker by itself. People route alerts to external services to automate, which sits outside TradingView.
Related Reads
Keep building the cluster
How to Generate a TradingView Indicator With AI (Full Walkthrough)
Describe an indicator in plain English and get Pine Script that runs on TradingView. A full worked example, from prompt to chart, with the checks that matter.
Pine Script v6 Errors That Stop Your Script Compiling
The Pine v6 mistakes that actually break a TradingView build, what each error means, and the ones that compile cleanly and still draw nothing on your chart.
How to Backtest a Trading Strategy (And Read the Result Honestly)
What backtesting actually tells you, how to run one on TradingView, and how to read the report so a losing strategy does not look like a winning one.