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.
TradePilot Team
Traders and engineers building the fastest way to go from idea to live Pine Script strategy, right inside TradingView.
More articles
Free vs Paid Pine Script AI: Is It Worth Paying?
ReadGuidePine Script Generator vs Writing It By Hand: Which Is Faster?
ReadGuideWhy AI Gets Pine Script Wrong (And How to Fix It)
ReadGuideThe Best Pine Script AI for Beginners in 2026
ReadComparisonCan ChatGPT Write Pine Script v6? We Tested It Properly
ReadPine ScriptPine Script Compile Errors: The Most Common Causes and Exact Fixes
ReadEducationTradingView Pine Script Generator: How AI Writes Your Strategy Code
ReadStrategyPine Script Strategy Optimizer: How to Find the Best Parameters for Your Strategy
ReadTutorialHow to Create a Pine Script Strategy with AI: Complete 2026 Guide
ReadTutorialHow to Install TradePilot in TradingView (Step-by-Step Guide)
ReadComparisonBest Free AI Tools for Pine Script in 2026 (Honest Comparison)
ReadPine ScriptPine Script v6 Syntax Changes: Everything That Breaks Coming from v5
ReadEducationThe Best TradingView Indicators and Strategy Types in 2025 (And How to Build Them with AI)
ReadEducationHow to Backtest a Trading Strategy in TradingView (The Right Way)
ReadEducationPine Script v6 Complete Guide: Strategies, Indicators, and Alerts That Actually Work
ReadComparisonTradePilot vs ChatGPT for Pine Script: Why a Specialist Wins Every Time
ReadProductEdit Any Pine Script Strategy with Plain English — No Coding Required
ReadProductOne Click to Fix Any Pine Script Error Inside TradingView
ReadProductStop Guessing Parameters. TradePilot's Strategy Optimizer Tests Them All.
ReadProductWe Built the Fastest AI Pine Script Generator Inside TradingView
ReadPine ScriptEMA Crossover Strategy in Pine Script v6: Full Code with RSI Filter, Stop Loss & Alerts
ReadBacktestingTradingView Backtesting Guide 2025: How to Test Any Strategy with Pine Script
ReadAI TradingAI Pine Script Generator: How to Create TradingView Strategies Without Coding in 2025
ReadPine ScriptPine Script Strategy: The Complete 2025 Guide to Writing TradingView Strategies
Read