Pine ScriptJun 2, 202611 min read33 views

Pine Script v6 Function Reference: ta.*, strategy.*, input.*, request.*

A practical reference for the most important Pine Script v6 functions — correct signatures, common mistakes, and working examples for ta.*, strategy.entry/exit, input.int/float, and request.security.

ta.* — technical analysis functions

All built-in technical analysis functions in Pine Script v6 are accessed through the ta.* namespace. Here are the most commonly used ones with correct signatures.

// Moving averages
ta.sma(source, length)          // simple moving average
ta.ema(source, length)          // exponential moving average
ta.wma(source, length)          // weighted moving average
ta.vwma(source, length)         // volume-weighted moving average

// Momentum
ta.rsi(source, length)          // returns float 0-100
ta.macd(source, fastLen, slowLen, signalLen)  // returns [macd, signal, hist]
ta.stoch(source, high, low, length)           // returns float

// Volatility
ta.atr(length)                  // average true range
ta.bb(source, length, mult)     // returns [upper, mid, lower]

// Trend
ta.supertrend(factor, atrPeriod) // returns [supertrend, direction]
ta.adx(diLen, adxSmoothing)      // returns [adxValue, diPlus, diMinus]

// Crossovers
ta.crossover(series1, series2)   // returns bool: series1 crossed above series2
ta.crossunder(series1, series2)  // returns bool: series1 crossed below series2

// Extremes
ta.highest(source, length)       // highest value in length bars
ta.lowest(source, length)        // lowest value in length bars
ta.highestbars(source, length)   // bars since highest value
ta.pivothigh(source, leftLen, rightLen) // confirmed pivot high or na

strategy.entry() and strategy.exit()

The two most important strategy functions. entry() opens a position, exit() closes it with optional stop and take-profit levels.

// strategy.entry — opens a position
strategy.entry(
  id        = "Long",           // string label, must match exit from_entry
  direction = strategy.long,    // strategy.long or strategy.short
  qty       = na,               // optional: shares/contracts (na = use strategy default)
  comment   = "Entry signal"    // optional: shows in Strategy Tester
)

// strategy.exit — closes with SL/TP
strategy.exit(
  id         = "Exit Long",
  from_entry = "Long",          // MUST match the entry id exactly
  stop       = close * 0.985,   // stop loss price level (not percentage)
  limit      = close * 1.030,   // take profit price level (not percentage)
  comment    = "SL/TP"
)

// strategy.close — close position by entry id without SL/TP
strategy.close("Long", comment="Exit signal")

Tip

The id in strategy.exit(from_entry=) must exactly match the id in strategy.entry(). A mismatch causes the exit to never trigger — one of the most common silent bugs in Pine Script strategies.

input.int(), input.float(), input.bool(), input.string()

Input functions create configurable parameters that appear in TradingView's settings panel. Always use named parameters — positional arguments do not work in v6.

// Correct v6 input syntax
int    fastLen  = input.int(defval=9,    title="Fast EMA",    minval=1,    group="Settings")
int    slowLen  = input.int(defval=21,   title="Slow EMA",    minval=1,    group="Settings")
float  stopPct  = input.float(defval=1.5, title="Stop Loss %", minval=0.1, step=0.1, group="Risk")
bool   useShort = input.bool(defval=false, title="Enable Shorts", group="Settings")
string maType   = input.string(defval="EMA", title="MA Type", options=["EMA","SMA","WMA"], group="Settings")

// WRONG — do not use label= (does not exist in v6)
int x = input.int(defval=9, label="Fast EMA")  // compile error

request.security() — multi-timeframe

Used to access data from a different timeframe or symbol. Must always be called with lookahead=barmerge.lookahead_off to avoid future data in backtests.

// Correct multi-timeframe pattern
float dailyClose = request.security(
  symbol    = syminfo.tickerid,
  timeframe = "D",
  expression = close[1],           // [1] = confirmed close, not current bar
  gaps      = barmerge.gaps_off,
  lookahead = barmerge.lookahead_off
)

// Access daily RSI for a higher-timeframe filter
float dailyRsi = request.security(syminfo.tickerid, "D", ta.rsi(close, 14)[1],
    gaps=barmerge.gaps_off, lookahead=barmerge.lookahead_off)

alertcondition() and alert()

Two different alert mechanisms in Pine Script v6. alertcondition() registers a condition for manual alert setup in TradingView's Alerts dialog. alert() fires automatically when the condition is met.

// alertcondition — registers for manual setup in TradingView Alerts
alertcondition(longCondition,  title="Long Entry",  message="Long signal on {{ticker}}")
alertcondition(shortCondition, title="Short Entry", message="Short signal on {{ticker}}")

// alert() — can be inside if blocks, fires automatically
if longCondition
    alert("Long entry — " + syminfo.ticker + " @ " + str.tostring(close), alert.freq_once_per_bar)

Tip

alertcondition() must be at global scope. alert() can be inside if blocks. Use alertcondition() for standard TradingView alert setup. Use alert() if you need programmatic webhook firing.

TP

TradePilot Team

Traders and engineers building the fastest way to go from idea to live Pine Script strategy, right inside TradingView.

More articles

Comparison

Free vs Paid Pine Script AI: Is It Worth Paying?

Read
Guide

Pine Script Generator vs Writing It By Hand: Which Is Faster?

Read
Guide

Why AI Gets Pine Script Wrong (And How to Fix It)

Read
Guide

The Best Pine Script AI for Beginners in 2026

Read
Comparison

Can ChatGPT Write Pine Script v6? We Tested It Properly

Read
Pine Script

Pine Script Compile Errors: The Most Common Causes and Exact Fixes

Read
Education

TradingView Pine Script Generator: How AI Writes Your Strategy Code

Read
Strategy

Pine Script Strategy Optimizer: How to Find the Best Parameters for Your Strategy

Read
Tutorial

How to Create a Pine Script Strategy with AI: Complete 2026 Guide

Read
Tutorial

How to Install TradePilot in TradingView (Step-by-Step Guide)

Read
Comparison

Best Free AI Tools for Pine Script in 2026 (Honest Comparison)

Read
Pine Script

Pine Script v6 Syntax Changes: Everything That Breaks Coming from v5

Read
Education

The Best TradingView Indicators and Strategy Types in 2025 (And How to Build Them with AI)

Read
Education

How to Backtest a Trading Strategy in TradingView (The Right Way)

Read
Education

Pine Script v6 Complete Guide: Strategies, Indicators, and Alerts That Actually Work

Read
Comparison

TradePilot vs ChatGPT for Pine Script: Why a Specialist Wins Every Time

Read
Product

Edit Any Pine Script Strategy with Plain English — No Coding Required

Read
Product

One Click to Fix Any Pine Script Error Inside TradingView

Read
Product

Stop Guessing Parameters. TradePilot's Strategy Optimizer Tests Them All.

Read
Product

We Built the Fastest AI Pine Script Generator Inside TradingView

Read
Pine Script

EMA Crossover Strategy in Pine Script v6: Full Code with RSI Filter, Stop Loss & Alerts

Read
Backtesting

TradingView Backtesting Guide 2025: How to Test Any Strategy with Pine Script

Read
AI Trading

AI Pine Script Generator: How to Create TradingView Strategies Without Coding in 2025

Read
Pine Script

Pine Script Strategy: The Complete 2025 Guide to Writing TradingView Strategies

Read

Ready to elevate your trading?

Join thousands of traders using TradePilot.co.in to generate profitable Pine Script strategies.

No credit card required1,000 free credits / monthWorks inside TradingViewCancel anytime