Technical Analysis

57+ built-in technical analysis functions in the ta namespace

The ta namespace provides 57+ technical analysis functions covering moving averages, oscillators, volatility, volume, trend detection, and statistics.

Moving Averages

FunctionDescription
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
ta.rma(source, length)Rolling/Running Moving Average (Wilder's smoothing)
ta.hma(source, length)Hull Moving Average
ta.alma(source, length, offset?, sigma?)Arnaud Legoux Moving Average
ta.swma(source)Symmetrically Weighted Moving Average
ta.linreg(source, length, offset?)Linear Regression
ta.vwapVolume Weighted Average Price (variable)
ta.vwap(source)Volume Weighted Average Price (function)
const fast = ta.ema(close, 9);
const slow = ta.ema(close, 21);
plot(fast, 'Fast EMA', { color: '#2962FF' });
plot(slow, 'Slow EMA', { color: '#FF6D00' });

Oscillators & Momentum

FunctionReturnsDescription
ta.rsi(source, length)numberRelative Strength Index
ta.macd(source, fast, slow, signal)[macd, signal, hist]MACD (returns tuple)
ta.stoch(source, high, low, length)numberStochastic Oscillator
ta.cci(source, length)numberCommodity Channel Index
ta.mfi(series, length)numberMoney Flow Index
ta.mom(source, length)numberMomentum
ta.roc(source, length)numberRate of Change
ta.tsi(source, short, long)numberTrue Strength Index
ta.cmo(source, length)numberChande Momentum Oscillator
ta.cog(source, length)numberCenter of Gravity
ta.wpr(length)numberWilliams %R
ta.change(source, length?)numberPrice change over N bars
const rsi = ta.rsi(close, 14);
const [macdLine, signalLine, hist] = ta.macd(close, 12, 26, 9);

Volatility & Range

FunctionReturnsDescription
ta.atr(length)numberAverage True Range
ta.bb(source, length, mult)[middle, upper, lower]Bollinger Bands (tuple)
ta.bbw(source, length, mult)numberBollinger Bands Width
ta.kc(source, length, mult)[middle, upper, lower]Keltner Channels (tuple)
ta.kcw(source, length, mult)numberKeltner Channels Width
ta.stdev(source, length)numberStandard Deviation
ta.dev(source, length)numberMean Absolute Deviation
ta.variance(source, length)numberVariance
ta.range(source, length)numberRange (highest - lowest)
ta.trnumberTrue Range (variable)
ta.tr(handleNa?)numberTrue Range (function)
const [middle, upper, lower] = ta.bb(close, 20, 2);
const atr = ta.atr(14);

Volume Indicators

These are accessed as variables (not function calls):

VariableDescription
ta.obvOn-Balance Volume
ta.accdistAccumulation/Distribution
ta.pvtPrice-Volume Trend
ta.wadWilliams Accumulation/Distribution
ta.wvadWilliams Variable Accumulation/Distribution
ta.nviNegative Volume Index
ta.pviPositive Volume Index
ta.iiiIntraday Intensity Index
plot(ta.obv, 'OBV');
plot(ta.accdist, 'A/D');

Trend Analysis

FunctionReturnsDescription
ta.crossover(a, b)booleanTrue when a crosses above b
ta.crossunder(a, b)booleanTrue when a crosses below b
ta.cross(a, b)booleanTrue when a crosses b in either direction
ta.rising(source, length)booleanTrue when source has been rising for length bars
ta.falling(source, length)booleanTrue when source has been falling for length bars
ta.supertrend(factor, atrLength)[value, direction]SuperTrend (tuple)
ta.sar(start, inc, max)numberParabolic SAR
ta.dmi(diLength, adxSmoothing)[plus, minus, adx]Directional Movement Index (tuple)
if (ta.crossover(fast, slow)) {
  plotshape(close, 'Buy', { style: shape.triangleup, location: location.belowbar });
}

Statistical Functions

FunctionDescription
ta.highest(source, length)Highest value over N bars
ta.lowest(source, length)Lowest value over N bars
ta.highestbars(source, length)Bars since highest value
ta.lowestbars(source, length)Bars since lowest value
ta.median(source, length)Median value
ta.mode(source, length)Mode value
ta.percentile_linear_interpolation(source, length, pct)Percentile (linear)
ta.percentile_nearest_rank(source, length, pct)Percentile (nearest rank)
ta.percentrank(source, length)Percentile rank
ta.correlation(a, b, length)Correlation coefficient
ta.max(a, b)Maximum of two values
ta.min(a, b)Minimum of two values

Utility Functions

FunctionDescription
ta.barssince(condition)Number of bars since condition was true
ta.valuewhen(condition, source, occurrence)Value when condition was true
ta.cum(source)Cumulative sum
ta.rci(source, length)Rank Correlation Index

Support & Resistance

FunctionDescription
ta.pivothigh(source, leftbars, rightbars)Detect pivot highs
ta.pivotlow(source, leftbars, rightbars)Detect pivot lows
ta.pivot_point_levels(type, anchor)Calculate pivot point levels