Skip to content

ta namespace

The ta namespace houses Pine Script’s technical analysis building blocks: moving averages, momentum oscillators, volatility bands, volume indicators, and pattern detectors. Functions return series values you can plot, feed into conditions, or combine with custom logic.

Many `ta.*` helpers require a warm-up period and output na until enough bars accumulate. Guard your logic with if not na(value) or wrap the result in nz() before plotting.

CategoryExamples
Moving averagesta.sma, ta.ema, ta.wma, ta.rma, ta.hma
Momentumta.rsi, ta.macd, ta.stoch, ta.cci, ta.mfi
Volatilityta.atr, ta.tr, ta.supertrend, ta.bb
Trends & highs/lowsta.highest, ta.lowest, ta.change, ta.crossover, ta.crossunder
Volumeta.obv, ta.ad, ta.vwap
Statisticsta.correlation, ta.variance, ta.stdev
Transformationsta.median, ta.percentile_linear_interpolation, ta.normalize

For the exhaustive list, refer to TradingView’s pine-script-reference by filtering for ta. entries.

  • Functions expect series inputs. Passing literal constants works, but expressions like ta.sma(close, 14) are the norm.
  • Many functions support optional arguments (e.g., ta.rsi(source, length) allows custom sources and lengths). Consult their individual docs for defaults.
  • Detection helpers such as ta.crossover() return boolean series bool, making them ideal triggers for strategy entries or plot markers.
//@version=5
indicator("ta namespace example", overlay=false)
fastLen = input.int(12, "Fast EMA")
slowLen = input.int(26, "Slow EMA")
rsiLen = input.int(14, "RSI length")
emaFast = ta.ema(close, fastLen)
emaSlow = ta.ema(close, slowLen)
rsiVal = ta.rsi(close, rsiLen)
atrVal = ta.atr(14)
plot(emaFast - emaSlow, "EMA spread", color=color.teal)
plot(ta.sma(emaFast - emaSlow, 10), "Spread SMA", color=color.orange)
plot(rsiVal, "RSI", color=color.blue, offset=1)
hline(70, "RSI Overbought", color=color.red)
hline(30, "RSI Oversold", color=color.green)
bgcolor(ta.crossover(emaFast, emaSlow) ? color.new(color.green, 85) :
ta.crossunder(emaFast, emaSlow) ? color.new(color.red, 85) : na,
title="EMA cross highlight")
plot(atrVal, "ATR", color=color.purple)