Indicators

This section documents the indicator (ta.*) functions.


ta.sma

Simple Moving Average. Calculates the average price over a specified period.

Syntax:

ta.sma(symbol, period)
ta.sma(data_series, period)  // Custom data series

Parameters:

  • symbol or data_series: Input series or symbol (e.g., '$BTC', '$ETH')

  • period: Lookback window length (default 20)

Examples:

// Default SMA
ta.sma($BTC)  // Same as ta.sma($BTC, 20)

// SMA crossover
ta.crossover(ta.sma($BTC, 10), ta.sma($BTC, 50))

// Custom data series SMA
ta.sma($BTC.volume, 10)

// Historical access
ta.sma($BTC, 20)[1]  // Previous SMA value

Returns: Array of SMA values with historical access


ta.ema

Exponential Moving Average. Gives more weight to recent prices.

Syntax:

ta.ema(symbol, period)
ta.ema(data_series, period)  // Custom data series

Parameters:

  • symbol or data_series: Input series or symbol (e.g., '$BTC', '$ETH')

  • period: Lookback window length (default 20)

Examples:

// Default EMA
ta.ema($BTC)  // Same as ta.ema($BTC, 20)

// EMA crossover
ta.crossover(ta.ema($BTC, 10), ta.ema($BTC, 50))

// Custom data series EMA
ta.ema($BTC.volume, 10)

// Historical access
ta.ema($BTC, 20)[1]  // Previous EMA value

Returns: Array of EMA values with historical access


ta.wma

Weighted Moving Average. Linear weighting with recent prices having more weight.

Syntax:

ta.wma(symbol, period)
ta.wma(data_series, period)  // Custom data series

Parameters:

  • symbol or data_series: Input series or symbol (e.g., '$BTC', '$ETH')

  • period: Lookback window length (default 20)

Examples:

// Default WMA
ta.wma($BTC)  // Same as ta.wma($BTC, 20)

// WMA crossover
ta.crossover(ta.wma($BTC, 10), ta.wma($BTC, 50))

// Custom data series WMA
ta.wma($BTC.volume, 10)

// Historical access
ta.wma($BTC, 20)[1]  // Previous WMA value

Returns: Array of WMA values with historical access


ta.wema

Wilder's Smoothed Moving Average. Used in RSI and other Wilder indicators.

Syntax:

ta.wema(symbol, period)
ta.wema(data_series, period)  // Custom data series

Parameters:

  • symbol or data_series: Input series or symbol (e.g., '$BTC', '$ETH')

  • period: Lookback window length (default 20)

Examples:

// Default WEMA
ta.wema($BTC)  // Same as ta.wema($BTC, 20)

// WEMA crossover
ta.crossover(ta.wema($BTC, 10), ta.wema($BTC, 50))

// Custom data series WEMA
ta.wema($BTC.volume, 10)

// Historical access
ta.wema($BTC, 20)[1]  // Previous WEMA value

Returns: Array of WEMA values with historical access


ta.trix

Triple Exponentially Smoothed Moving Average. Provides heavily smoothed trend direction with minimal lag.

Syntax:

ta.trix(symbol, period)
ta.trix(data_series, period)  // Custom data series

Parameters:

  • symbol or data_series: Input series or symbol (e.g., '$BTC', '$ETH')

  • period: Lookback window length (default 20)

Examples:

// Default TRIX
ta.trix($BTC)  // Same as ta.trix($BTC, 20)

// TRIX crossover
ta.crossover(ta.trix($BTC, 10), ta.trix($BTC, 50))

// Custom data series TRIX
ta.trix($BTC.volume, 10)

// Historical access
ta.trix($BTC, 20)[1]  // Previous TRIX value

Returns: Array of TRIX values with historical access


ta.rsi

Relative Strength Index. Measures overbought/oversold conditions.

Syntax:

ta.rsi(symbol, period)

Parameters:

  • symbol: The symbol to analyze (e.g., '$BTC', '$ETH')

  • period: Lookback window length (default 14)

Examples:

// Default RSI
ta.rsi($BTC)  // Same as ta.rsi($BTC, 14)

// Overbought/oversold
ta.rsi($BTC, 14) > 70  // Overbought
ta.rsi($BTC, 14) < 30  // Oversold

// RSI divergence
ta.rsi($BTC, 14) > ta.rsi($BTC, 14)[1] and $BTC.close < $BTC.close[1]

// Historical access
ta.rsi($BTC, 14)[1]  // Previous RSI value

Returns: Array of RSI values (0-100) with historical access


ta.macd

Moving Average Convergence Divergence. Shows relationship between two moving averages.

Syntax:

ta.macd(symbol, fast, slow, signal)           // Returns MACD line by default
ta.macd(symbol, fast, slow, signal).MACD      // MACD line (uppercase)
ta.macd(symbol, fast, slow, signal).signal    // Signal line
ta.macd(symbol, fast, slow, signal).histogram // MACD histogram

Parameters:

  • symbol: The symbol to analyze (e.g., '$BTC', '$ETH')

  • fast: Fast EMA period (default 12)

  • slow: Slow EMA period (default 26)

  • signal: Signal line EMA period (default 9)

Examples:

// Default MACD (returns MACD line)
ta.macd($BTC)  // Same as ta.macd($BTC, 12, 26, 9).MACD

// MACD line above zero
ta.macd($BTC) > 0  // Using default (MACD line)
ta.macd($BTC, 12, 26, 9).MACD > 0  // Explicit MACD line

// MACD histogram
ta.macd($BTC, 12, 26, 9).histogram > 0

// Signal line crossover
ta.macd($BTC, 12, 26, 9).MACD > ta.macd($BTC, 12, 26, 9).signal

// Using default for crossover
ta.macd($BTC) > ta.macd($BTC).signal

Returns: MACD line value by default, or object with MACD, signal, and histogram properties when accessing subproperties


ta.stoch

Stochastic Oscillator. Compares closing price to price range over time.

Syntax:

ta.stoch(symbol, kPeriod, dPeriod)     // Returns %K line by default
ta.stoch(symbol, kPeriod, dPeriod).k   // %K line (fast stochastic)
ta.stoch(symbol, kPeriod, dPeriod).d   // %D line (slow stochastic)

Parameters:

  • symbol: The symbol to analyze (e.g., '$BTC', '$ETH')

  • kPeriod: %K period (default 14)

  • dPeriod: %D smoothing period (default 3)

Examples:

// Default Stochastic (returns %K line)
ta.stoch($BTC)  // Same as ta.stoch($BTC, 14, 3).k

// %K and %D lines
ta.stoch($BTC) > 80  // Overbought (using default %K)
ta.stoch($BTC, 14, 3).k > 80  // Explicit %K overbought
ta.stoch($BTC, 14, 3).d < 20  // %D oversold

// Stochastic crossover
ta.stoch($BTC, 14, 3).k > ta.stoch($BTC, 14, 3).d

// Using default for crossover
ta.stoch($BTC) > ta.stoch($BTC).d

Returns: %K line value by default, or object with k and d properties when accessing subproperties


ta.stochrsi

Stochastic RSI. Applies Stochastic oscillator to RSI values.

Syntax:

ta.stochrsi(symbol, kPeriod, dPeriod, rsiPeriod, stochPeriod)              // Returns stochRSI value by default
ta.stochrsi(symbol, kPeriod, dPeriod, rsiPeriod, stochPeriod).stochRSI     // StochRSI value
ta.stochrsi(symbol, kPeriod, dPeriod, rsiPeriod, stochPeriod).k            // %K line
ta.stochrsi(symbol, kPeriod, dPeriod, rsiPeriod, stochPeriod).d            // %D line

Parameters:

  • symbol: The symbol to analyze (e.g., '$BTC', '$ETH')

  • kPeriod: %K period (default 3)

  • dPeriod: %D smoothing period (default 3)

  • rsiPeriod: Underlying RSI period (default 14)

  • stochPeriod: Stochastic lookback for RSI (default 14)

Examples:

// Default StochRSI (returns stochRSI value)
ta.stochrsi($BTC)  // Same as ta.stochrsi($BTC, 3, 3, 14, 14).stochRSI

// Extreme levels
ta.stochrsi($BTC) > 0.8  // Overbought (using default stochRSI)
ta.stochrsi($BTC, 3, 3, 14, 14).k > 0.8  // Explicit %K overbought
ta.stochrsi($BTC, 3, 3, 14, 14).k < 0.2  // %K oversold

// StochRSI crossover
ta.stochrsi($BTC, 3, 3, 14, 14).k > ta.stochrsi($BTC, 3, 3, 14, 14).d

Returns: StochRSI value by default, or object with stochRSI, k and d properties (0-1 range) when accessing subproperties


ta.cci

Commodity Channel Index. Measures deviation from statistical mean.

Syntax:

ta.cci(symbol, period)

Parameters:

  • symbol: The symbol to analyze (e.g., '$BTC', '$ETH')

  • period: Lookback window length (default 20)

Examples:

// Default CCI
ta.cci($BTC)  // Same as ta.cci($BTC, 20)

// Extreme readings
ta.cci($BTC, 20) > 100  // Overbought
ta.cci($BTC, 20) < -100  // Oversold

// Zero line cross
ta.cci($BTC, 20) > 0 and ta.cci($BTC, 20)[1] < 0

// Historical access
ta.cci($BTC, 20)[1]  // Previous CCI value

Returns: Array of CCI values with historical access


ta.adx

Average Directional Index. Measures trend strength.

Syntax:

ta.adx(symbol, period)        // Returns ADX value by default
ta.adx(symbol, period).adx    // ADX value (trend strength)
ta.adx(symbol, period).pdi    // Positive Directional Indicator
ta.adx(symbol, period).mdi    // Negative Directional Indicator

Parameters:

  • symbol: The symbol to analyze (e.g., '$BTC', '$ETH')

  • period: Lookback window length (default 14)

Examples:

// Default ADX (returns ADX value)
ta.adx($BTC)  // Same as ta.adx($BTC, 14).adx

// Strong trend
ta.adx($BTC) > 25  // Using default ADX value

// Trend strength comparison
ta.adx($BTC) > ta.adx($ETH)

// Directional movement
ta.adx($BTC, 14).pdi > ta.adx($BTC, 14).mdi  // Bullish direction
ta.adx($BTC, 14).mdi > ta.adx($BTC, 14).pdi  // Bearish direction

// Trending market filter with direction
ta.adx($BTC) > 20 and ta.adx($BTC).pdi > ta.adx($BTC).mdi

// Historical access
ta.adx($BTC)[1]  // Previous ADX value

Returns: ADX value by default, or object with adx, pdi, and mdi properties when accessing subproperties


ta.psar

Parabolic SAR. Trend-following indicator that provides stop and reverse points.

Syntax:

ta.psar(symbol, step, max)

Parameters:

  • symbol: The symbol to analyze (e.g., '$BTC', '$ETH')

  • step: Acceleration factor increment per new extreme point (e.g., 0.02)

  • max: Maximum acceleration factor cap (e.g., 0.2)

Examples:

// Basic PSAR
ta.psar($BTC, 0.02, 0.2)

// Trend direction
$BTC.close > ta.psar($BTC, 0.02, 0.2)  // Uptrend

// Trend reversal
ta.psar($BTC, 0.02, 0.2) != ta.psar($BTC, 0.02, 0.2)[1]

// Stop loss level
ta.psar($BTC, 0.02, 0.2)

Returns: Array of PSAR values with historical access


ta.atr

Average True Range. Measures market volatility.

Syntax:

ta.atr(symbol, period)

Parameters:

  • symbol: The symbol to analyze (e.g., '$BTC', '$ETH')

  • period: Lookback window length (default 14)

Examples:

// Default ATR
ta.atr($BTC)  // Same as ta.atr($BTC, 14)

// Volatility-based stops
$BTC.close - ta.atr($BTC, 14) * 2  // Stop loss

// High volatility filter
ta.atr($BTC, 14) > ta.sma(ta.atr($BTC, 14), 10)

// Position sizing
ta.atr($BTC, 14) / $BTC.close < 0.02  // Low volatility

// Historical access
ta.atr($BTC, 14)[1]  // Previous ATR value

Returns: Array of ATR values with historical access


ta.bb

Bollinger Bands. Shows dynamic support and resistance levels.

Syntax:

ta.bb(symbol, period, stdDev)         // Returns middle band by default
ta.bb(symbol, period, stdDev).upper   // Upper Bollinger Band
ta.bb(symbol, period, stdDev).middle  // Middle Bollinger Band (SMA)
ta.bb(symbol, period, stdDev).lower   // Lower Bollinger Band
ta.bb(symbol, period, stdDev).pb      // Percent B (position within bands)

Parameters:

  • symbol: The symbol to analyze (e.g., '$BTC', '$ETH')

  • period: SMA period for middle band (default 20)

  • stdDev: Standard deviation multiplier (default 2)

Examples:

// Default Bollinger Bands (returns middle band)
ta.bb($BTC)  // Same as ta.bb($BTC, 20, 2).middle

// Band touches
$BTC.close > ta.bb($BTC, 20, 2).upper  // Upper band break
$BTC.close < ta.bb($BTC, 20, 2).lower  // Lower band break

// Squeeze detection
ta.bb($BTC, 20, 2).upper - ta.bb($BTC, 20, 2).lower < ta.atr($BTC, 14) * 3

// Mean reversion
$BTC.close > ta.bb($BTC)  // Above middle band (using default)
$BTC.close > ta.bb($BTC, 20, 2).middle  // Explicit middle band

// Percent B analysis
ta.bb($BTC, 20, 2).pb > 0.8  // Near upper band
ta.bb($BTC, 20, 2).pb < 0.2  // Near lower band

// Band width calculation
(ta.bb($BTC, 20, 2).upper - ta.bb($BTC, 20, 2).lower) / ta.bb($BTC)

// Historical access
ta.bb($BTC)[1]  // Previous middle band value
ta.bb($BTC, 20, 2).upper[1]  // Previous upper band

Returns: Middle band value by default, or object with upper, middle, lower, and pb properties when accessing subproperties


ta.vwap

Volume Weighted Average Price. Average price weighted by volume.

Syntax:

ta.vwap(symbol)

Parameters:

  • symbol: The symbol to analyze (e.g., '$BTC', '$ETH')

Examples:

// Basic VWAP
ta.vwap($BTC)

// Price vs VWAP
$BTC.close > ta.vwap($BTC)  // Above VWAP

// VWAP as support/resistance
$BTC.low > ta.vwap($BTC)  // VWAP acting as support

// Institutional levels
math.abs($BTC.close - ta.vwap($BTC)) / $BTC.close < 0.01

Returns: Array of VWAP values with historical access


ta.obv

On-Balance Volume. Relates volume to price change.

Syntax:

ta.obv(symbol)

Parameters:

  • symbol: The symbol to analyze (e.g., '$BTC', '$ETH')

Examples:

// Basic OBV
ta.obv($BTC)

// OBV trend
ta.obv($BTC) > ta.obv($BTC)[10]  // Rising OBV

// Volume-price divergence
$BTC.close > $BTC.close[10] and ta.obv($BTC) < ta.obv($BTC)[10]

// Volume confirmation
ta.obv($BTC) > ta.sma(ta.obv($BTC), 20)

Returns: Array of OBV values with historical access


ta.mfi

Money Flow Index. Volume-weighted RSI.

Syntax:

ta.mfi(symbol, period)

Parameters:

  • symbol: The symbol to analyze (e.g., '$BTC', '$ETH')

  • period: Lookback window length (default 14)

Examples:

// Default MFI
ta.mfi($BTC)  // Same as ta.mfi($BTC, 14)

// Overbought/oversold with volume
ta.mfi($BTC, 14) > 80  // Overbought
ta.mfi($BTC, 14) < 20  // Oversold

// MFI vs RSI divergence
ta.mfi($BTC, 14) > 50 and ta.rsi($BTC, 14) < 50

// Volume momentum
ta.mfi($BTC, 14) > ta.mfi($BTC, 14)[1]

// Historical access
ta.mfi($BTC, 14)[1]  // Previous MFI value

Returns: Array of MFI values (0-100) with historical access


ta.adl

Accumulation Distribution Line. Measures volume flow.

Syntax:

ta.adl(symbol)

Parameters:

  • symbol: The symbol to analyze (e.g., '$BTC', '$ETH')

Examples:

// Basic ADL
ta.adl($BTC)

// Accumulation/Distribution trend
ta.adl($BTC) > ta.adl($BTC)[5]  // Accumulation

// Price-volume divergence
$BTC.close < $BTC.close[5] and ta.adl($BTC) > ta.adl($BTC)[5]

// Volume flow confirmation
ta.adl($BTC) > ta.sma(ta.adl($BTC), 10)

Returns: Array of ADL values with historical access


ta.fi

Force Index. Combines price and volume to assess buying/selling pressure.

Syntax:

ta.fi(symbol, period)

Parameters:

  • symbol: The symbol to analyze (e.g., '$BTC', '$ETH')

  • period: Lookback window length (default 1)

Examples:

// Default Force Index
ta.fi($BTC)  // Same as ta.fi($BTC, 1)

// Force Index trend
ta.fi($BTC, 13) > 0  // Bullish force

// Short-term vs long-term
ta.fi($BTC, 1) > 0 and ta.fi($BTC, 13) > 0

// Force reversal
ta.fi($BTC, 1) > 0 and ta.fi($BTC, 1)[1] < 0

// Historical access
ta.fi($BTC, 1)[1]  // Previous FI value

Returns: Array of Force Index values with historical access


ta.roc

Rate of Change. Measures percentage change over time.

Syntax:

ta.roc(symbol, period)

Parameters:

  • symbol: The symbol to analyze (e.g., '$BTC', '$ETH')

  • period: Lookback window length (default 12)

Examples:

// Default ROC
ta.roc($BTC)  // Same as ta.roc($BTC, 12)

// Momentum analysis
ta.roc($BTC, 12) > 5  // Strong upward momentum

// Multi-timeframe momentum
ta.roc($BTC, 5) > ta.roc($BTC, 20)  // Short-term stronger

// Zero line cross
ta.roc($BTC, 10) > 0 and ta.roc($BTC, 10)[1] < 0

// Historical access
ta.roc($BTC, 12)[1]  // Previous ROC value

Returns: Array of ROC values (percentage) with historical access


ta.ao

Awesome Oscillator. Momentum indicator comparing recent momentum to longer-term momentum.

Syntax:

ta.ao(symbol)

Parameters:

  • symbol: The symbol to analyze (e.g., '$BTC', '$ETH')

Examples:

// Basic AO
ta.ao($BTC)

// Zero line cross
ta.ao($BTC) > 0 and ta.ao($BTC)[1] < 0

// Momentum direction
ta.ao($BTC) > ta.ao($BTC)[1]  // Increasing momentum

// Twin peaks setup
ta.ao($BTC) < 0 and ta.ao($BTC) > ta.ao($BTC)[1]

Returns: Array of Awesome Oscillator values with historical access


ta.williamsr

Williams %R. Momentum oscillator measuring overbought/oversold levels.

Syntax:

ta.williamsr(symbol, period)

Parameters:

  • symbol: The symbol to analyze (e.g., '$BTC', '$ETH')

  • period: Lookback window length (default 14)

Examples:

// Default Williams %R
ta.williamsr($BTC)  // Same as ta.williamsr($BTC, 14)

// Overbought/oversold
ta.williamsr($BTC, 14) > -20  // Overbought
ta.williamsr($BTC, 14) < -80  // Oversold

// Momentum reversal
ta.williamsr($BTC, 14) > -50 and ta.williamsr($BTC, 14)[1] < -50

// Failure swings
ta.williamsr($BTC, 14) < -80 and ta.williamsr($BTC, 14) > ta.williamsr($BTC, 14)[1]

// Historical access
ta.williamsr($BTC, 14)[1]  // Previous Williams %R value

Returns: Array of Williams %R values (-100 to 0) with historical access


ta.pivothigh

Identifies pivot high points where price is higher than surrounding bars on both sides.

Syntax:

ta.pivothigh(symbol, leftbars, rightbars)
ta.pivothigh(data_series, leftbars, rightbars) // Custom data series

Parameters:

  • symbol or data_series: Input series or symbol (e.g., '$BTC', '$ETH')

  • leftbars: Number of bars to the left that must be lower than the pivot bar

  • rightbars: Number of bars to the right that must be lower than the pivot bar

Examples:

// Basic pivot high detection (5 bars on each side)
ta.pivothigh($BTC, 5, 5)

// Resistance level (last pivot high price)
ta.valuewhen(ta.pivothigh($BTC, 5, 5) != null, $BTC[5].high, 0)

// Bars since resistance level (last pivot high)
ta.barssince(ta.pivothigh($BTC, 5, 5) != null, 0) + 5

// Stronger pivot high (more confirmation bars)
ta.pivothigh($BTC, 10, 10)

// Asymmetric pivot detection for faster confirmation
ta.pivothigh($BTC, 10, 2)

// Historical pivot highs
ta.pivothigh($BTC, 5, 5)[1]  // Value on previous bar

// Breakout detection (pivot high breakout)
ta.crossover($BTC.close, ta.valuewhen(ta.pivothigh($BTC, 5, 5) != null, $BTC[5].high, 0))

// RSI pivot high detection (custom data series)
ta.pivothigh(ta.rsi($BTC), 5, 5)

Returns: Array of confirmed pivot high values with historical access; null otherwise.


ta.pivotlow

Identifies pivot low points where price is lower than surrounding bars on both sides.

Syntax:

ta.pivotlow(symbol, leftbars, rightbars)
ta.pivotlow(data_series, leftbars, rightbars) // Custom data series

Parameters:

  • symbol or data_series: Input series or symbol (e.g., '$BTC', '$ETH')

  • leftbars: Number of bars to the left that must be higher than the pivot bar

  • rightbars: Number of bars to the right that must be higher than the pivot bar

Examples:

// Basic pivot low detection (5 bars on each side)
ta.pivotlow($BTC, 5, 5)

// Support level (last pivot low price)
ta.valuewhen(ta.pivotlow($BTC, 5, 5) != null, $BTC[5].low, 0)

// Bars since support level (last pivot low)
ta.barssince(ta.pivotlow($BTC, 5, 5) != null, 0) + 5

// Stronger pivot low (more confirmation bars)
ta.pivotlow($BTC, 10, 10)

// Asymmetric pivot detection for faster confirmation
ta.pivotlow($BTC, 10, 2)

// Historical pivot lows
ta.pivotlow($BTC, 5, 5)[1]  // Value on previous bar

// Breakdown detection (pivot low breakdown)
ta.crossunder($BTC.close, ta.valuewhen(ta.pivotlow($BTC, 5, 5) != null, $BTC[5].low, 0))

// RSI pivot low detection (custom data series)
ta.pivotlow(ta.rsi($BTC), 5, 5)

Returns: Array of confirmed pivot low values with historical access; null otherwise.

Last updated

Was this helpful?