ta: technical analysis
Averages, oscillators, bands, trend studies, crosses, pivots and lookbacks. Each returns a series and handles its own warm-up.
67 names from PineTS 0.11.1 · 53 with full entries
ta.sma
Verifiedta.sma(source, length)
Simple moving average: the mean of the last length values.
| Argument | Type | Meaning |
|---|---|---|
| source | series float | The series to read, usually close. |
| length | series int | How many bars to look back. |
Returns series float
//@version=6indicator("ta.sma", overlay = true)plot(ta.sma(close, 50), "SMA 50", color = color.orange, linewidth = 2)ta.ema
Verifiedta.ema(source, length)
Exponential moving average; recent bars weigh more.
| Argument | Type | Meaning |
|---|---|---|
| source | series float | The series to read, usually close. |
| length | series int | How many bars to look back. |
Returns series float
//@version=6indicator("ta.ema", overlay = true)plot(ta.ema(close, 21), "EMA 21", color = color.teal, linewidth = 2)ta.wma
Verifiedta.wma(source, length)
Weighted moving average with linearly decreasing weights.
| Argument | Type | Meaning |
|---|---|---|
| source | series float | The series to read, usually close. |
| length | series int | How many bars to look back. |
Returns series float
ta.hma
Verifiedta.hma(source, length)
Hull moving average: smooth with little lag.
| Argument | Type | Meaning |
|---|---|---|
| source | series float | The series to read, usually close. |
| length | series int | How many bars to look back. |
Returns series float
ta.rma
Verifiedta.rma(source, length)
Wilder's moving average, the smoothing used inside RSI and ATR.
| Argument | Type | Meaning |
|---|---|---|
| source | series float | The series to read, usually close. |
| length | series int | How many bars to look back. |
Returns series float
ta.vwma
Verifiedta.vwma(source, length)
Volume-weighted moving average. Volume on this feed is a tick count.
| Argument | Type | Meaning |
|---|---|---|
| source | series float | The series to read, usually close. |
| length | series int | How many bars to look back. |
Returns series float
ta.alma
Verifiedta.alma(series, length, offset, sigma, floor)
Arnaud Legoux moving average: a Gaussian-weighted average.
| Argument | Type | Meaning |
|---|---|---|
| series | series float | The series to read, usually close. |
| length | series int | How many bars to look back. |
| offset | simple float | 0 to 1; higher reacts faster. 0.85 is usual. |
| sigma | simple float | Smoothness; 6 is usual. |
Returns series float
ta.swma
Supportedta.swma(source)
Symmetrically weighted average over a fixed 4 bars.
Returns series float
ta.linreg
Verifiedta.linreg(source, length, offset)
Linear regression line's value, offset bars from the end.
| Argument | Type | Meaning |
|---|---|---|
| source | series float | The series to read, usually close. |
| length | series int | How many bars to look back. |
| offset | simple int | 0 for the current bar. |
Returns series float
ta.rsi
Verifiedta.rsi(source, length)
Relative Strength Index, 0 to 100.
| Argument | Type | Meaning |
|---|---|---|
| source | series float | The series to read, usually close. |
| length | series int | Usually 14. |
Returns series float
//@version=6indicator("ta.rsi")r = ta.rsi(close, 14)plot(r, "RSI", color = color.purple)hline(70)hline(30)ta.stoch
Verifiedta.stoch(source, high, low, length)
Stochastic %K, unsmoothed. Smooth it with ta.sma for the classic %K and %D.
| Argument | Type | Meaning |
|---|---|---|
| source | series float | The series to read, usually close. |
| high | series float | Usually high. |
| low | series float | Usually low. |
| length | series int | How many bars to look back. |
Returns series float
//@version=6indicator("ta.stoch")k = ta.sma(ta.stoch(close, high, low, 14), 3)plot(k, "%K")plot(ta.sma(k, 3), "%D", color = color.orange)ta.cci
Verifiedta.cci(source, length)
Commodity Channel Index.
| Argument | Type | Meaning |
|---|---|---|
| source | series float | Usually hlc3. |
| length | series int | How many bars to look back. |
Returns series float
ta.mfi
Verifiedta.mfi(series, length)
Money Flow Index, RSI weighted by volume (tick count here).
| Argument | Type | Meaning |
|---|---|---|
| series | series float | Usually hlc3. |
| length | series int | How many bars to look back. |
Returns series float
ta.mom
Verifiedta.mom(source, length)
Momentum: source minus source length bars ago.
| Argument | Type | Meaning |
|---|---|---|
| source | series float | The series to read, usually close. |
| length | series int | How many bars to look back. |
Returns series float
ta.roc
Verifiedta.roc(source, length)
Rate of change, in percent.
| Argument | Type | Meaning |
|---|---|---|
| source | series float | The series to read, usually close. |
| length | series int | How many bars to look back. |
Returns series float
ta.tsi
Verifiedta.tsi(source, short_length, long_length)
True Strength Index, -1 to 1.
Returns series float
ta.wpr
Verifiedta.wpr(length)
Williams %R, -100 to 0.
| Argument | Type | Meaning |
|---|---|---|
| length | series int | How many bars to look back. |
Returns series float
ta.cmo
Verifiedta.cmo(series, length)
Chande Momentum Oscillator.
Returns series float
ta.atr
Verifiedta.atr(length)
Average True Range: the typical bar range, smoothed with RMA.
| Argument | Type | Meaning |
|---|---|---|
| length | series int | Usually 14. |
Returns series float
//@version=6indicator("ta.atr")plot(ta.atr(14), "ATR 14", color = color.orange)See alsota.tr
ta.tr
Verifiedta.tr · ta.tr(handle_na)
True range of the current bar.
Returns series float
ta.stdev
Verifiedta.stdev(source, length, biased)
Standard deviation over length bars.
Returns series float
ta.dev
Supportedta.dev(source, length)
Mean absolute deviation from the SMA.
Returns series float
ta.variance
Supportedta.variance(source, length, biased)
Variance over length bars.
Returns series float
ta.bb
Verifiedta.bb(series, length, mult)
Bollinger Bands.
| Argument | Type | Meaning |
|---|---|---|
| series | series float | The series to read, usually close. |
| length | series int | How many bars to look back. |
| mult | simple float | Standard deviations; 2 is usual. |
Returns [middle, upper, lower]
//@version=6indicator("ta.bb", overlay = true)[m, u, l] = ta.bb(close, 20, 2)plot(m, "Basis", color = color.orange)plot(u, "Upper")plot(l, "Lower")ta.bbw
Supportedta.bbw(series, length, mult)
Bollinger Band width as a fraction of the basis.
Returns series float
ta.kc
Verifiedta.kc(series, length, mult, useTrueRange)
Keltner Channels around an EMA.
Returns [middle, upper, lower]
ta.kcw
Supportedta.kcw(series, length, mult, useTrueRange)
Keltner Channel width.
Returns series float
ta.macd
Verifiedta.macd(source, fastlen, slowlen, siglen)
MACD line, signal line and histogram.
Returns [macdLine, signalLine, histLine]
//@version=6indicator("ta.macd")[m, s, h] = ta.macd(close, 12, 26, 9)plot(h, "Hist", style = plot.style_columns, color = h >= 0 ? color.teal : color.red)plot(m, "MACD")plot(s, "Signal", color = color.orange)ta.dmi
Verifiedta.dmi(diLength, adxSmoothing)
Directional Movement: +DI, -DI and ADX.
Returns [plus, minus, adx]
//@version=6indicator("ta.dmi")[p, m, adx] = ta.dmi(14, 14)plot(p, "+DI", color = color.teal)plot(m, "-DI", color = color.red)plot(adx, "ADX", color = color.orange)ta.supertrend
Verifiedta.supertrend(factor, atrPeriod)
Supertrend line and direction. A negative direction is an up trend.
Returns [supertrend, direction]
//@version=6indicator("ta.supertrend", overlay = true)[st, dir] = ta.supertrend(3, 10)plot(st, "Supertrend", color = dir < 0 ? color.teal : color.red)ta.sar
Verifiedta.sar(start, inc, max)
Parabolic SAR.
| Argument | Type | Meaning |
|---|---|---|
| start | simple float | 0.02 is usual. |
| inc | simple float | 0.02 is usual. |
| max | simple float | 0.2 is usual. |
Returns series float
//@version=6indicator("ta.sar", overlay = true)plot(ta.sar(0.02, 0.02, 0.2), "SAR", style = plot.style_cross, color = color.orange)ta.crossover
Verifiedta.crossover(source1, source2)
true on the bar source1 moves from below source2 to above it.
Returns series bool
//@version=6indicator("ta.crossover", overlay = true)f = ta.ema(close, 9)s = ta.ema(close, 21)plotshape(ta.crossover(f, s), style = shape.triangleup, location = location.belowbar, color = color.teal)See alsota.crossunderta.cross
ta.crossunder
Verifiedta.crossunder(source1, source2)
true on the bar source1 moves from above source2 to below it.
Returns series bool
ta.cross
Verifiedta.cross(source1, source2)
true on any cross, either direction.
Returns series bool
ta.highest
Verifiedta.highest(source, length)
Highest value over the last length bars, including this one.
Returns series float
//@version=6indicator("ta.highest", overlay = true)plot(ta.highest(high, 20), "20-bar high", color = color.teal)plot(ta.lowest(low, 20), "20-bar low", color = color.red)See alsota.lowestta.highestbars
ta.lowest
Verifiedta.lowest(source, length)
Lowest value over the last length bars.
Returns series float
ta.highestbars
Verifiedta.highestbars(source, length)
Offset (0 or negative) to the highest bar in the window.
Returns series int
ta.lowestbars
Verifiedta.lowestbars(source, length)
Offset (0 or negative) to the lowest bar in the window.
Returns series int
ta.pivothigh
Verifiedta.pivothigh(source, leftbars, rightbars) · ta.pivothigh(leftbars, rightbars)
The pivot's price, reported rightbars after it; na elsewhere.
Returns series float
Shift markers back with offset = -rightbars to draw them on the pivot bar.
//@version=6indicator("ta.pivothigh", overlay = true)ph = ta.pivothigh(high, 5, 5)plotshape(not na(ph), style = shape.triangledown, location = location.abovebar, color = color.red, offset = -5)See alsota.pivotlow
ta.pivotlow
Verifiedta.pivotlow(source, leftbars, rightbars) · ta.pivotlow(leftbars, rightbars)
The pivot low's price, reported rightbars after it; na elsewhere.
Returns series float
ta.valuewhen
Verifiedta.valuewhen(condition, source, occurrence)
source's value on the occurrence-th most recent bar where condition was true (0 is the latest).
Returns series
//@version=6indicator("ta.valuewhen", overlay = true)up = ta.crossover(close, ta.sma(close, 20))plot(ta.valuewhen(up, close, 0), "Close at last cross", style = plot.style_stepline)ta.barssince
Supportedta.barssince(condition)
Bars since condition was last true; na before it ever was.
Returns series int
ta.change
Verifiedta.change(source, length)
source minus source length bars ago (length defaults to 1). For bools, true when the value changed.
Returns series
ta.rising
Supportedta.rising(source, length)
true when source has risen on each of the last length bars.
Returns series bool
ta.falling
Supportedta.falling(source, length)
true when source has fallen on each of the last length bars.
Returns series bool
ta.cum
Supportedta.cum(source)
Running total of source since the first bar.
Returns series float
ta.correlation
Supportedta.correlation(source1, source2, length)
Pearson correlation of two series, -1 to 1.
Returns series float
ta.percentrank
Supportedta.percentrank(source, length)
Percent of the last length values below the current one.
Returns series float
ta.median
Supportedta.median(source, length)
Median over length bars.
Returns series float
ta.range
Supportedta.range(source, length)
Highest minus lowest over length bars.
Returns series float
ta.obv
Verifiedta.obvOn Balance Volume. Meaningful on tick-count volume.
Returns series float
ta.accdist
Verifiedta.accdistAccumulation/Distribution. Treats volume as size, so it is approximate here.
Returns series float
ta.vwap
Verifiedta.vwap(source) · ta.vwap(source, anchor, stdev_mult)
Volume-weighted average price. Volume is a tick count on this feed, so treat it as approximate.
Returns series float · [vwap, upper, lower]
Everything else in ta
Also implemented. These follow TradingView’s Pine v6 reference for their arguments.
- ta.cogSupportedCenter of Gravity (COG) The cog (center of gravity) is an indicator based on statistics and the Fibonacci golden ratio.
- ta.iiiSupportedIntraday Intensity Index (III) Formula (as TradingView computes it; its reference manual shows a division by volume): (2 * close - high - low) / (high - low) * volume
- ta.maxSupportedTrailing Maximum (ta.max) Returns the all-time high value of `source` from the first bar of the chart up to the current bar.
- ta.minSupportedTrailing Minimum (ta.min) Returns the all-time low value of `source` from the first bar of the chart up to the current bar.
- ta.modeSupportedMode Returns the mode of the series.
- ta.nviSupportedNegative Volume Index (NVI) Formula: If close or close[1] is 0, nvi = nvi[1] Else if volume < volume[1], nvi = nvi[1] + ((close - close[1]) / close[1]) * nvi[1] Else nvi = nvi[1] Initial value is 1.0
- ta.percentile_linear_interpolationSupportedPercentile Linear Interpolation Calculates percentile using method of linear interpolation between the two nearest ranks.
- ta.percentile_nearest_rankSupportedPercentile Nearest Rank Calculates percentile using method of Nearest Rank.
- ta.pivot_point_levelsSupportedta.pivot_point_levels(type, anchor, developing) → array<float> of 11 levels [P, R1, S1, …, R5, S5].
- ta.pviSupportedPositive Volume Index (PVI) Formula: If close or close[1] is 0, pvi = pvi[1] Else if volume > volume[1], pvi = pvi[1] + ((close - close[1]) / close[1]) * pvi[1] Else pvi = pvi[1] Initial value is 1.0
- ta.pvtVerifiedPrice-Volume Trend (PVT) The PVT function calculates the Price-Volume Trend, which is a cumulative total of volume adjusted by the percentage change in price.
- ta.rciSupportedRank Correlation Index: Spearman's rank correlation between the last `length` values of `source` and their bar order, scaled to -100..100 (100 = rose on every bar).
- ta.wadSupportedWilliams Accumulation/Distribution (WAD) Formula: trueHigh = math.max(high, close[1]) trueLow = math.min(low, close[1]) mom = ta.change(close) gain = (mom > 0) ?
- ta.wvadSupportedWilliams Variable Accumulation/Distribution (WVAD) Formula: (close - open) / (high - low) * volume