Pine Script v6 Function Reference: Every ta., math., strategy., request. Function (2026)
The complete, accurate Pine Script v6 function reference — ta.*, math.*, strategy.*, request.*, input.* — with correct signatures, common phantom-function mistakes (math.clamp, ta.rma2, dema2), and working code examples.
Quick answer
Pine Script v6 organizes built-ins into namespaces: ta.* (technical analysis), math.* (math + bitwise), strategy.* (orders), request.* (multi-timeframe/symbol data), and input.* (settings). Some commonly searched names — math.clamp, ta.rma2, ta.adx, dema2 — are not real functions; see the sections below for the correct equivalent.
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.
math.clamp() — constrain a value to a range
math.clamp(value, min, max) is not actually a Pine Script v6 built-in. It doesn't exist in the math.* namespace and calling it produces "could not find function or function reference 'math.clamp'". If you want a value constrained to a range, write it with math.min and math.max instead.
// math.clamp does NOT exist — this fails to compile: // float x = math.clamp(rsiValue, 0, 100) // Correct v6 equivalent: clampedValue(val, minVal, maxVal) => math.max(minVal, math.min(maxVal, val)) float x = clampedValue(rsiValue, 0, 100)
Tip
This is one of the most common false-memory errors in Pine Script — clamp() exists in many other languages (GLSL, C++, JS) but was never added to Pine's math.* namespace. Don't guess it exists; check the reference.
ta.rma() — Wilder's moving average (there is no ta.rma2)
ta.rma(source, length) computes Wilder's smoothed moving average — the same smoothing RSI and ATR use internally. It takes exactly two arguments: source and length. There is no ta.rma2 function; that name doesn't exist in any Pine Script version, v5 or v6. If you've seen it referenced, it's a mix-up with a different indicator or a typo.
// ta.rma — Wilder's smoothing (2 args only) float rmaValue = ta.rma(close, 14) // what RSI uses internally, for reference: // rsi = 100 - (100 / (1 + ta.rma(up, len) / ta.rma(down, len)))
ta.dmi() — directional movement index, exact signature
ta.dmi(diLength, adxSmoothing) returns a tuple of three values: [diPlus, diMinus, adx]. Both arguments are required. A very common mistake is assigning the tuple to a single variable, or reversing the return order (adx is last, not first).
// Correct: destructure into three named variables [diPlus, diMinus, adxValue] = ta.dmi(14, 14) // If you need the previous bar's ADX: [_, _, adxSeries] = ta.dmi(14, 14) float prevAdx = adxSeries[1] // WRONG — indexing before destructuring is a compile error: // float x = ta.dmi(14, 14)[1]
Tip
ta.dmi(14,14)[1] — indexing the tuple call directly with [1] before destructuring is a frequent compile error. Destructure first, then index each series if you need a prior bar's value.
math.bitwise_and() and the bitwise namespace
Pine Script v6's math.* namespace includes bitwise operations for working with int values at the bit level: math.bitwise_and, math.bitwise_or, math.bitwise_xor, math.bitwise_not, math.bitwise_left_shift, math.bitwise_right_shift. All take int arguments and return an int.
// Bitwise operations (int only) int a = math.bitwise_and(12, 10) // 8 int b = math.bitwise_or(12, 10) // 14 int c = math.bitwise_xor(12, 10) // 6 int d = math.bitwise_left_shift(1, 4) // 16
ta.sum(), ta.tr, ta.adx — quick reference
Three more functions that show up often in search but aren't always covered in tutorials. ta.sum(source, length) is a rolling sum over the last N bars. ta.tr is true range (as a series, not a function call — no parentheses). ta.adx is not a real v6 built-in on its own; ADX comes back as the third value from ta.dmi(), shown above.
float rollingVolume = ta.sum(volume, 20) float trueRange = ta.tr float trueRangeHandled = ta.tr(true)
- ta.sum(source, length) — rolling sum of source over length bars
- ta.tr — true range series (property, not a function — use ta.tr, never ta.tr())
- ta.tr(handle_na) — optional form that controls na handling on the first bar
- "ta.adx" as a standalone function does not exist — use the third return value of ta.dmi()
Functions that sound real but aren't: dema2, tema2, and other phantom names
A cluster of searches look for functions like dema2 or tema2 — these aren't Pine Script built-ins in v5 or v6. Pine has ta.ema (single exponential) but no built-in double/triple EMA function under any name. If you want a DEMA or TEMA, you compute it from ta.ema calls yourself; it isn't a one-line built-in.
// DEMA (double EMA) — built from two ta.ema calls, not a built-in
dema(source, length) =>
e1 = ta.ema(source, length)
e2 = ta.ema(e1, length)
2 * e1 - e2
float demaValue = dema(close, 20)Frequently asked questions
Does Pine Script have a math.clamp function?+
No. math.clamp does not exist in Pine Script v5 or v6. Use math.max(minVal, math.min(maxVal, value)) to constrain a value to a range instead.
What is ta.rma2 in Pine Script?+
ta.rma2 is not a real function in any Pine Script version — it doesn't exist. The correct function is ta.rma(source, length), Wilder's smoothed moving average, which takes exactly two arguments.
What does ta.dmi() return in Pine Script v6?+
ta.dmi(diLength, adxSmoothing) returns a tuple of three values in this order: [diPlus, diMinus, adx]. You must destructure all three with square brackets — assigning the call to a single variable is a compile error.
Does Pine Script v6 have bitwise functions?+
Yes. The math.* namespace includes math.bitwise_and, math.bitwise_or, math.bitwise_xor, math.bitwise_not, math.bitwise_left_shift, and math.bitwise_right_shift, all operating on int values.
Is there a dema2 or tema2 function in Pine Script?+
No. Pine Script has no built-in double or triple EMA function under any name. You build a DEMA or TEMA yourself by chaining ta.ema() calls.
TradePilot Team
Traders and engineers building the fastest way to go from idea to live Pine Script strategy, right inside TradingView.
More articles
How Advanced Traders Stress-Test a Strategy Before They Trust It
ReadAdvancedHow Advanced Traders Use TradePilot as a Pine Co-Pilot, Not a Replacement
ReadIntermediateHow Intermediate Traders Use TradePilot to Go From Idea to Tested Strategy Fast
ReadIntermediateHow Intermediate Traders Use the Strategy Optimizer Instead of Hand-Tuning Settings
ReadBeginnerThe Beginner Trading Mistakes TradePilot Catches Before You Make Them
ReadBeginnerHow Beginner Traders Use TradePilot Instead of Trading on Gut Feel
ReadGuideFix All Your Pine Script Errors at Once — or Just the One (2026)
ReadProductVerified Pine Script: Why 'It Compiles' Should Be the Bar (2026)
ReadGuideOne AI, Two Modes: TradingView Copilot vs Pine Studio (2026)
ReadProductTalk to Your TradingView Chart: Voice Input for the AI Copilot (2026)
ReadTechnicalPine Script v6 vs v5: Why It Matters for AI-Generated Code
ReadTutorialAutomatically Sweep Strategy Parameters on TradingView
ReadTutorialMulti-Timeframe Chart Analysis With an AI Copilot
ReadProductTry an AI Copilot for TradingView Free for 7 Days
ReadBeginnerPine Script AI for People Who Don't Code
ReadTutorialBacktest a Pine Script Strategy and Get Results Without Leaving Chat
ReadTutorialGenerate a TradingView Indicator From a Screenshot or Description
ReadProductAn AI That Fixes Pine Script Errors Automatically (No Manual Debugging)
ReadComparisonTradePilot vs TradingView Remix-Style Copilots: What's Actually Different
ReadGuideIs an AI Copilot for TradingView Safe to Use? What It Can and Can't Access
ReadGuideHow to Install an AI Copilot Inside TradingView (2-Minute Setup)
ReadComparisonTradePilot vs ChatGPT for TradingView: What Actually Changes When the AI Is Inside Your Chart
ReadGuideScan Your TradingView Watchlist With AI — No More Checking Every Symbol by Hand
ReadGuideControl Your TradingView Chart by Chat: The 2026 Copilot Workflow
ReadGuideCreate TradingView Alerts From Chat — No Dialog Boxes
ReadGuideHow to Backtest a TradingView Strategy From Chat (No Menus)
ReadProductThe Best AI for Pine Script on TradingView in 2026
ReadProductWhat Is an AI Copilot for TradingView? (And Why It Beats a Chatbot in 2026)
ReadProductWhat Makes TradePilot Different From Every Other Pine Script AI (2026)
ReadEducationHow Reliable Pine Script AI Saves Traders Hours Every Week (2026)
ReadComparisonAn AI Pine Script Generator With No Compile Errors (2026)
ReadEducationCan You Trust AI to Write Your TradingView Strategies? (2026)
ReadTutorialHow to Get Pine Script That Compiles First Try (2026)
ReadComparisonAI Pine Script Compile Rates Compared (2026)
ReadGuideStop Debugging AI-Generated Pine Script in 2026
ReadComparisonThe Best Pine Script AI That Actually Works in 2026
ReadGuideWhy AI-Generated Pine Script Doesn't Compile (And How We Fixed It)
ReadComparisonThe Only AI That Guarantees Your Pine Script Compiles (2026)
ReadEducation7 Trading Strategy Mistakes That Ruin Your Backtest (And How to Fix Them in 2026)
ReadPine ScriptBuild a Multi-Symbol Screener Dashboard in Pine Script (2026)
ReadStrategyBuilding a Scalping Strategy in Pine Script for 2026
ReadEducationHow to Automate a TradingView Strategy in 2026 (Alerts to Execution)
ReadPine ScriptVWAP Trading Strategy in Pine Script: Full Guide and Code (2026)
ReadStrategyForex Pine Script Strategies: Session-Based Trading in 2026
ReadStrategyCrypto Trading Strategies in Pine Script: What Works in 2026
ReadPine ScriptThe Supertrend Indicator in Pine Script v6: Full Guide and Code (2026)
ReadStrategyUsing Pine Script for Prop Firm Challenges in 2026
ReadEducationAlgorithmic Trading for Beginners: How to Start in 2026 (No CS Degree)
ReadStrategyTradingView Strategy Optimization: The Complete 2026 Guide to Finding the Best Parameters
ReadTutorialPine Script Stop Loss and Take Profit: The Complete 2026 Guide
ReadEducationHow AI Writes Pine Script: The Complete 2026 Guide to AI Code Generation
ReadStrategyThe Pine Script Strategy Template Every Trader Should Use in 2026
ReadEducationTradingView Pine Script: The Complete 2026 Beginner's Guide
ReadGuideHow to Code a Trading Strategy: The Complete 2026 Guide (No Experience Needed)
ReadPine ScriptPine Script Functions: The Complete 2026 Reference Guide (ta, strategy, request, input)
ReadBacktestingBacktesting in TradingView: The Complete 2026 Guide to Testing Any Strategy
ReadEducationTradingView Alerts: The Complete 2026 Guide (Pine Script, Webhooks, and Setup)
ReadPine ScriptPine Script Indicators: The Complete 2026 Guide to Writing TradingView Indicators
ReadComparisonBest Pine Script AI in 2026: The Complete Buyer's Guide
ReadTutorialHow to Fix Pine Script Errors with AI in 2026 (Fast)
ReadGuideNo-Code Trading Strategy Builder: Create TradingView Strategies Without Programming (2026)
ReadStrategy10 Pine Script Strategy Examples You Can Copy in 2026 (With Full Code)
ReadProductThe Best TradingView AI Copilot in 2026: Generate, Fix, and Optimize Inside the Chart
ReadTutorialAI Trading Indicator Generator: Build Custom TradingView Indicators in 2026
ReadTutorialHow to Generate Pine Script from Plain English (2026 Guide)
ReadComparisonChatGPT vs Claude for Pine Script in 2026: Which Writes Better TradingView Code?
ReadComparisonFree Pine Script Generator: The Best Free Way to Write TradingView Code in 2026
ReadComparisonThe Best AI Pine Script Generator in 2026 (Tested and Ranked)
ReadPine ScriptTradingView Alerts Not Firing? The Pine Script Reasons and Fixes
ReadGuidePine Script for Beginners: Where to Start in 2026
ReadEducationCan AI Write Profitable Trading Strategies? An Honest Answer
ReadTutorialThe EMA Crossover Strategy in Pine Script v6 (Complete Guide + Code)
ReadComparisonPine Script vs MQL vs thinkScript: Which Trading Language Should You Learn?
ReadPine ScriptMulti-Timeframe Pine Script: Using request.security Without Repainting
ReadEducationTradingView Strategy Tester Explained: Reading Your Backtest Like a Pro
ReadTutorialHow to Add a Stop Loss and Take Profit in Pine Script v6
ReadPine ScriptPine Script 'Could Not Find Function' Error: Why It Happens and How to Fix It
ReadStrategy10 Pine Script Indicators Worth Building in 2026 (And How)
ReadPine ScriptPine Script Alerts: alert() vs alertcondition() and When to Use Each
ReadTutorialHow to Write an RSI Strategy in Pine Script v6 (With Working Code)
ReadComparisonFree 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