Skip to content
Quantzee
On this page
Glossary Index

Trading Glossary

Pine Script

Reviewed by the Quantzee team.

TL;DR

Pine Script is TradingView’s built-in scripting language — it lets traders write custom indicators and automated strategies that run directly on the world’s most popular charting platform, no server required. Version 6 is the current syntax as of 2026.

What Is Pine Script?

Pine Script is the proprietary programming language created by TradingView for writing custom technical analysis indicators, trading strategies, and alert conditions. It runs server-side on TradingView’s infrastructure, which means any script you write executes automatically on every bar update across any market and timeframe — no local setup, no data feeds to manage, no server to keep running.

The language is purpose-built for trading. Its data model is bar-by-bar: every line of code processes one OHLCV candle at a time, with built-in access to price, volume, time, and hundreds of built-in indicator functions. This makes it dramatically faster to prototype a strategy in Pine Script than in Python — what takes 200 lines in Python (data ingestion, indicator math, a manual backtest loop) often takes 20 in Pine Script, because TradingView’s platform handles charting, historical data, and the simulation engine for you.

Pine Script has gone through six major versions. Version 6, the current syntax, refined the type system (stricter method/type declarations, clearer error messages at compile time), extended the matrix and map data structures introduced in v5, and continued expanding the reusable-library ecosystem — users can publish and import Pine Script libraries, enabling a collaborative open-source layer on top of TradingView’s platform. Scripts written in v5 still run and are not force-migrated, but new indicators and strategies should target v6 for the improved compiler diagnostics and the newest built-ins. For any trader serious about systematic trading on TradingView, Pine Script literacy is non-negotiable.

Key Formula / Numbers

//@version=6
indicator("My Custom Indicator", overlay=true)

// Simple moving average example
length = input.int(14, "Length")
src = input.source(close, "Source")
ma = ta.sma(src, length)

plot(ma, color=color.blue, linewidth=2)

Key Pine Script concepts:

  • indicator() — declares a script as a visual overlay or panel indicator
  • strategy() — enables backtesting with order simulation
  • ta.* — built-in technical analysis library (SMA, EMA, RSI, ATR, etc.)
  • input.* — creates user-configurable settings in the indicator panel
  • alertcondition() / alert() — defines conditions that push real-time notifications

A Basic Strategy Script (v6 Syntax)

Indicators only plot visuals; a strategy() script additionally simulates order entries and exits so TradingView’s Strategy Tester can report win rate, drawdown, and net profit. Here is a minimal moving-average crossover strategy written in current v6 syntax:

//@version=6
strategy("MA Crossover Strategy", overlay=true, initial_capital=100000,
     default_qty_type=strategy.percent_of_equity, default_qty_value=10)

fastLen = input.int(9, "Fast MA Length")
slowLen = input.int(21, "Slow MA Length")

fastMA = ta.sma(close, fastLen)
slowMA = ta.sma(close, slowLen)

longCondition = ta.crossover(fastMA, slowMA)
shortCondition = ta.crossunder(fastMA, slowMA)

if longCondition
    strategy.entry("Long", strategy.long)
if shortCondition
    strategy.close("Long")

plot(fastMA, color=color.aqua)
plot(slowMA, color=color.orange)

strategy.entry() opens a position, strategy.close() exits it, and the Strategy Tester tab automatically tabulates every simulated trade — no manual bookkeeping required. This is the core loop every Pine Script strategy is built from; everything else (stop-loss placement, position sizing, multi-timeframe confirmation) layers on top of entry/close/exit calls like these.

Writing Your First Pine Script Indicator, Step by Step

The fastest way to get comfortable with Pine Script is to build a working indicator in stages rather than copying a finished script. Here’s the sequence every new Pine Script author goes through:

  1. Declare the script type and version. Every script opens with a version comment (//@version=6) followed by either indicator(...) for a visual-only script or strategy(...) for one that simulates trades. Getting this line right — and matching it with the correct closing call later — is the single most common source of “why won’t this compile” confusion for beginners.
  2. Expose the settings a trader will actually want to change. input.int(), input.float(), input.source(), and input.bool() each create a control in the indicator’s settings panel. A length input (input.int(14, "Length")) is the most common first input any indicator needs, because almost every technical calculation — a moving average, an RSI, an ATR — depends on a lookback period.
  3. Do the calculation using the ta.* namespace. Pine Script ships dozens of built-in functions (ta.sma, ta.ema, ta.rsi, ta.atr, ta.crossover) so that common technical-analysis math never has to be hand-written. Reaching for a built-in before writing custom math is almost always the right call — it’s faster, and it’s been tested against millions of chart-hours already.
  4. Plot or signal the result. plot() draws a line on the chart; plotshape() and plotchar() mark specific bars (e.g. a crossover event); bgcolor() shades the background under a condition. A script isn’t useful until something about its calculation is visible or actionable.
  5. Wire up alerts. alertcondition() defines a condition a trader can subscribe to from the chart’s Alert dialog, independent of whether the script is currently open. This is the step that turns a chart indicator into something that can notify you (or trigger downstream automation) while you’re away from the screen — and it’s the mechanism every Quantzee indicator’s real-time signal delivery is built on.

Each of these five steps maps to a real block of code in the strategy example above: the //@version=6 and strategy(...) declaration (step 1), the input.int() calls for fastLen/slowLen (step 2), the ta.sma() and ta.crossover() calls (step 3), the plot() calls (step 4), and — in a full production script — an alertcondition() tied to longCondition/shortCondition (step 5, omitted above for brevity but standard practice on any script meant for live use).

Pine Script vs. Python for Backtesting

Traders researching a systematic idea often ask whether to prototype it in Pine Script or in a Python framework like Backtrader or Vectorbt. The honest answer is that they serve different stages of the same workflow:

Pine ScriptPython (Backtrader / Vectorbt)
Where it runsTradingView’s servers — no local setupYour own machine or a research server
Data accessBuilt-in, any TradingView-listed market/timeframeYou must source and clean your own historical data
Speed to first resultMinutes — write, click “Add to Chart”Hours — data pipeline before the first backtest runs
Statistical depthStrategy Tester gives trade list, drawdown, net profitFull control — Monte Carlo, walk-forward, custom metrics
Live executionNative TradingView alerts → webhook to a brokerRequires your own broker-API integration code
Best forFast iteration, visual confirmation, live alertingDeep statistical validation, large parameter sweeps

The practical takeaway: many systematic traders use both — a Python tool for the wide parameter search across thousands of variants, then Pine Script to implement the finalist as a live, alert-driven strategy directly on the chart traders actually watch. Neither replaces the other; Pine Script’s advantage is proximity to live execution, not raw statistical horsepower.

How Quantzee Uses This

All six Quantzee indicators are written in Pine Script v6 — and since 8 October 2026 we hand you the source. Buy the suite once and the six .pine files are emailed to you as plain, unprotected text: you paste each one into TradingView’s Pine Editor, save it to your own account, and add it to a chart. There is no invite to wait for and nothing anyone can revoke.

That makes this page unusually practical if you own the suite. Every convention described below — the //@version=6 header, indicator() versus strategy(), request.security() discipline, barstate.isconfirmed gating — is visible in the files on your machine. The AI Adaptive Quant Toolkit, for instance, combines machine-learning signal logic with Pine Script’s native alert system, so when a signal fires TradingView pushes a notification to your phone, email, or webhook. You can read exactly how that is wired rather than taking our word for it.

The non-repainting claim in particular stops being a claim. Our code is engineered so signals confirm only at bar close and never retroactively change on historical bars — calc_on_every_tick and the bar-confirmation logic are set accordingly — and because you hold the source, you can verify that line by line instead of inferring it from behaviour. That is the gold standard for Pine Script indicator quality, and it is the same discipline every worked example on this page follows.

The licence lets you modify the files for your own trading. What it does not allow is sharing, selling or republishing them — see Terms Section 5.

Common Mistakes

  • Repainting signals. Using request.security() calls without lookahead=barmerge.lookahead_off, or referencing the current unconfirmed bar (close instead of close[1] inside certain contexts), causes look-ahead bias — the indicator appears to predict the future in backtests but fails live. Always verify a non-repainting claim before trusting any indicator’s backtest.
  • Strategy vs. indicator confusion. Scripts declared as strategy() generate backtest results with simulated fills; scripts declared as indicator() only plot visuals and never place orders. Confusing the two — or assuming an indicator() script has been “backtested” — is the most common beginner error.
  • Overcomplicating inputs. Adding too many user-configurable inputs creates curve-fitting risk. A strategy with 15 optimizable parameters will overfit to any historical dataset; the Strategy Tester will show a beautiful equity curve that reflects fitting the past, not a genuine edge.
  • Ignoring default Strategy Tester assumptions. TradingView’s default backtest settings assume zero commission and instant fills at the exact signal price. Real slippage and commission can turn a “profitable” default-settings backtest into a losing live strategy — always set commission_value and slippage explicitly in the strategy() declaration before trusting the numbers.
  • Mixing timeframes without request.security() discipline. Pulling a higher-timeframe value into a lower-timeframe script without the correct lookahead and gaps parameters is one of the most common sources of subtle repainting bugs, because the higher-timeframe bar can appear “final” on the lower timeframe before it has actually closed.
  • Publishing without testing across multiple instruments. A script tuned and tested only on one symbol (e.g., NIFTY futures) can behave very differently on a lower-liquidity or higher-volatility instrument — always sanity-check a strategy’s logic on at least two or three different markets before relying on it.

FAQ

What is Pine Script used for?

Pine Script is used to write custom technical indicators, automated trading strategies, and price alerts on TradingView — all running directly in the browser without any external setup or data feed.

Is Pine Script hard to learn?

Pine Script is beginner-friendly for basic indicators — a moving-average plot is a handful of lines — but has a learning curve for strategy logic, request.security() calls, and array/matrix manipulation. Most traders reach a working level within a few weeks of practice, faster if they already know another programming language.

What’s the difference between Pine Script v5 and v6?

Pine Script v6 refines the type system with stricter compile-time checks (catching more errors before you run the script), extends the matrix and map data structures for more advanced state management, and adds new built-ins. Existing v5 scripts are not force-migrated and continue to run, but new development should target v6.

Can Pine Script execute real trades?

Pine Script itself cannot place live orders directly with a broker. TradingView alerts triggered by alertcondition() or a strategy’s entry/exit logic can be configured to send a webhook, which a third-party automation service or broker-API bridge can then use to place the actual order.

Does Pine Script backtesting account for slippage and commission?

Only if you set it explicitly. The strategy() declaration accepts commission_type, commission_value, and slippage parameters — left at their defaults, the Strategy Tester assumes frictionless, instant fills, which overstates real-world performance. Always configure these before trusting a backtest’s net profit figure.

Is Pine Script better than Python for building a trading strategy?

They solve different problems. Pine Script wins on speed-to-live-alert and zero infrastructure since it runs on TradingView’s own servers against TradingView’s own data. Python (via Backtrader or Vectorbt) wins on statistical depth — Monte Carlo simulation, large parameter sweeps, custom performance metrics — because you have full control of the research environment. Many systematic traders use Python for the initial research and Pine Script for the live, alert-driven implementation.

Can I import someone else’s Pine Script code and modify it?

It depends how the script was published, and how you got it.

Published open-source scripts (marked “Open-source” rather than “Protected” or “Invite-only” in TradingView’s publishing settings) can be viewed, copied and modified freely — though republishing one without meaningful changes or attribution breaks TradingView’s house rules. Protected and invite-only scripts hide their source entirely and cannot be copied at all.

Scripts you have been given the source files for are a third case, and it is governed by the seller’s licence rather than by TradingView. All six Quantzee indicators work this way: buy the suite and the .pine files are emailed to you, unprotected, so you can read and edit the code for your own trading. You may not share, sell, redistribute or republish them — including on TradingView. The full licence is at Terms Section 5, and a copy ships in the zip as LICENCE.txt.

How do I test a Pine Script strategy before using it live?

Add the script to a chart with strategy() declared, open the “Strategy Tester” tab at the bottom of the TradingView interface, and review the Overview, Performance Summary, List of Trades, and Properties sub-tabs. Set realistic commission_value and slippage in the strategy() declaration first — the default settings assume frictionless fills, which will always overstate real performance. Paper trade the strategy’s live alerts for a stretch before committing real capital, regardless of how strong the backtest looks.

Why does my Pine Script indicator repaint on historical bars but look fine live?

This almost always traces back to a request.security() call pulling a higher-timeframe or different-symbol value without lookahead=barmerge.lookahead_off, or to referencing the current bar’s still-forming value instead of a confirmed prior bar. The fix is to explicitly set the lookahead parameter and, where the logic allows it, calculate off [1]-indexed (previous, confirmed) bar values rather than the live bar. Always test a suspect script by comparing its bar-replay behavior against its live behavior before trusting any of its historical signals.

Related Terms

FAQ

Frequently Asked Questions

Put It Into Practice

See how Quantzee applies Pine Script

AI Adaptive Quant Toolkit uses these concepts in live, non-repainting signals on TradingView.

Explore AI Adaptive Quant Toolkit