ta namespace
Overview
Section titled “Overview”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.
Key categories
Section titled “Key categories”| Category | Examples |
|---|---|
| Moving averages | ta.sma, ta.ema, ta.wma, ta.rma, ta.hma |
| Momentum | ta.rsi, ta.macd, ta.stoch, ta.cci, ta.mfi |
| Volatility | ta.atr, ta.tr, ta.supertrend, ta.bb |
| Trends & highs/lows | ta.highest, ta.lowest, ta.change, ta.crossover, ta.crossunder |
| Volume | ta.obv, ta.ad, ta.vwap |
| Statistics | ta.correlation, ta.variance, ta.stdev |
| Transformations | ta.median, ta.percentile_linear_interpolation, ta.normalize |
For the exhaustive list, refer to TradingView’s pine-script-reference by filtering for ta. entries.
Remarks
Section titled “Remarks”- 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 booleanseries bool, making them ideal triggers for strategy entries or plot markers.
Example
Section titled “Example”//@version=5indicator("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)