Pine Script in TradingView: Language, Limits, Workflow

ZynIQ guide · updated September 2026

Pine Script is TradingView’s built-in language for indicators, strategies and alerts. You write it in the Pine Editor, compile it on the chart, and it runs on TradingView’s servers, not on your machine. This page covers what it can and cannot do, how versions work, and a concrete workflow you can follow without promising any trading result.

What Pine Script actually is

Pine Script is a domain-specific language for time-series charts. It is not a general programming language. You do not open files on disk, you do not spawn threads, and you do not talk to your broker from Pine. You declare inputs, read OHLCV (and a limited set of other series), compute plots, and optionally fire alerts or run a strategy tester with simulated orders.

Scripts compile to a sandboxed runtime. Each bar (and, if you request it, each tick inside a bar) the runtime evaluates your code with the data available at that moment. That model is why “repainting” is a first-class risk: if you read future bars, unconfirmed higher-timeframe values, or realtime-only series, the historical plot will not match what you saw live.

TradingView ships Pine with the platform. You can use it on a free plan. Paid TradingView plans raise limits on how many scripts you can add to a chart, how many alerts you can arm, and how far back you can request data. The language itself does not change with your subscription.

Versions you will meet: v4, v5 and v6

Every script starts with a version pragma, for example //@version=6. Older public scripts still sit on v4 or v5. You cannot mix versions in one file. If you copy a snippet from a v5 script into a v6 file, expect compile errors around namespaces, request.security, and strategy properties.

  • v4: still common in old open-source posts. study() instead of indicator(), looser typing, fewer built-ins.
  • v5: namespaces (ta., math., str.), indicator() / strategy() / library(), request.security with lookahead flags made explicit.
  • v6: current compiler. Stricter types, more array and map helpers, updated strategy and request APIs. New public scripts should start here unless you must match a library that has not been ported.

If you buy a compiled or source indicator, ask which version it ships. A v6 source file will not compile on an old editor tab left on v5. Trading involves risk; a script that “looks right” on history can still fire late or not at all in a live session if it depends on unconfirmed data.

Where you write it: editor, chart, and publish flow

  1. Open a chart. Bottom panel: Pine Editor.
  2. New blank indicator starts with //@version=6, indicator("Name", overlay=true) or overlay=false for a pane.
  3. Save. The script lives in your TradingView account, not in a local folder, unless you copy the source out yourself.
  4. Add to chart. Errors show in the console under the editor. Warnings about series vs simple types are not optional; they usually mean your plot will not do what you think on historical bars.
  5. Create alert from the script only after you have confirmed the condition uses confirmed bars if that is what you want.
  6. Optional: Publish script (invite-only or public). Public scripts are visible to anyone; treat source as public the moment you publish it open-source.

Libraries are separate Pine files you import with import User/LibName/1. They do not plot by themselves. Use them to share functions, not to hide a full trading system from the compiler limits.

Hard limits that bite in practice

Pine is not unlimited. Typical constraints you hit on real work:

ConstraintWhat it means on a chart
Security / request callsA small fixed budget of request.security / request.seed calls per script. Nested HTF logic burns this fast.
Plot and line objectsline.new, box.new, label.new have caps. A liquidity map that draws every sweep will hit the object limit on a 10 000-bar load.
Lookbackmax_bars_back and the chart’s loaded history. A 5 000-bar SMA is cheap; a 5 000-bar nested loop is not.
LoopsAllowed, but the runtime will time out on heavy per-bar loops. Prefer built-in ta.* functions.
AlertsAlert count is a TradingView plan limit, not a Pine syntax limit. One script can expose several alertcondition() IDs.
BrokeragePine strategies simulate fills. They do not place live orders unless you use a separate broker bridge outside Pine, which is not part of the language.

Repaint checklist before you trust a plot: no lookahead_on unless you know why; higher-timeframe requests should use lookahead_off and you should accept that the HTF value updates when that HTF bar closes; barstate.isconfirmed if the signal must not fire mid-bar; no request.security_lower_tf if you then treat intra-bar prints as historical truth.

Indicator vs strategy vs library

Use indicator() for decision-support overlays and panes: market structure, FVG boxes, VWAP, session highs, volume. Indicators can raise alerts. They do not keep an equity curve.

Use strategy() only when you want the built-in tester: entry/exit, pyramiding, commission, slippage fields. The tester is a model. It does not prove a live edge. Fill assumptions (order fills at close, or at a stop) will not match a thin crypto book or a fast futures open.

Use library() for shared math. Keep one library per concern (for example ATR helpers) so version bumps do not break every chart at once.

A minimal non-repainting pattern

For a close-confirmed break of a prior swing high you typically: find the swing with a confirmed pivot (left and right bars both in the past), store the price in a var float, and fire only when close crosses that level and barstate.isconfirmed. Plot the level with plot() or line.new on the last confirmed bar, not on barstate.isrealtime sketches that vanish on refresh.

If you need session times, use session strings in the exchange timezone of the symbol, not your laptop clock. New York cash equities, CME futures and forex “New York” are not the same clock. Wrong timezone is a more common bug than a missing ta.crossover.

When to write Pine vs buy a finished script

Write it yourself when the rule is short, you need to read every line, and you will maintain it when TradingView ships a compiler change. Buy or reuse when the work is drawing-heavy (structure, gaps, liquidity pools) and you would otherwise spend weeks on object caps and HTF requests.

ZynIQ sells one-time Pine Script v6 indicators (no subscription), source download after checkout, written to be non-repainting and usable on free TradingView plans as well as paid ones; that is analysis tooling, not a return forecast. Whatever you load, size positions as if the signal can be late or wrong. Trading involves risk of capital loss.

Debugging without folklore

  • plotchar(barstate.isconfirmed, ...) to see which bars your condition actually used.
  • log.info in v6 for values; do not spam it every bar on a 20 000-bar chart.
  • Replay mode to watch realtime vs historical. If the line jumps when you refresh, you have a repaint or a security lookahead issue.
  • Compare overlay=true plots against a pane of the raw series you think you crossed.

Do not treat open-source scripts as audited. Many still use lookahead_on, request.security on the same symbol with a different timeframe and then trade the live print. Read the request calls first, then the entry condition.

Frequently asked questions

Is Pine Script only for paid TradingView plans?

No. The editor and compiler work on the free plan. Paid plans mainly raise how many indicators you can stack, how many alerts you can keep, and how much history you can load. The language version is the same.

Does Pine Script v6 repaint by default?

No. Repaint comes from what you request: future bars, unconfirmed higher-timeframe data, or realtime-only values. v6 still lets you write those patterns. You have to refuse them in the code.

Can Pine Script place live trades at my broker?

Not by itself. strategy() simulates fills inside TradingView. Live routing needs a separate integration outside Pine. Treat the tester as a model with commission and slippage fields you set, not as a live ticket.

Should I convert old v4 scripts or rewrite them?

For anything you still use, rewrite on v6. Automatic converters miss namespace changes and security lookahead. If a library you depend on is stuck on v5, keep that project on v5 until the library moves.

How is Pine Script different from Python backtests?

Pine runs on TradingView’s bar engine with strict I/O and object caps. Python can read any file, any API and any fill model you code. Pine is faster to plot on a chart; it is a weaker place to build a full research stack.

Can I hide my Pine source from users of the script?

Invite-only publication can hide source from other users on the platform. Anyone with source can copy it. If you need others to use the tool without editing it, publish protected or invite-only and keep the master file yourself.