Skip to content

ta ​

Technical analysis functions. Each takes and returns series and is declared once at the top level; the runtime advances it on every bar.

NameDescription
ta.sma()Simple moving average: the mean of the last length values.
ta.ema()Exponential moving average with alpha 2 / (length + 1), seeded with the SMA of the first length values.
ta.rma()Wilder's moving average (RMA, used by RSI and ATR): alpha 1 / length, seeded with the SMA of the first length values.
ta.wma()Weighted moving average: the newest value weighs length, the oldest 1.
ta.vwma()Volume-weighted moving average over the last length bars, weighted by candle volume (alpha).
ta.rsi()Relative Strength Index, 0..100, from Wilder-smoothed gains and losses of src.
ta.macd()MACD: macd = EMA(fast) − EMA(slow), signal = EMA(macd, signal), hist = macd − signal.
ta.bbands()Bollinger Bands: middle = SMA(length), upper/lower = middle ± mult × standard deviation.
ta.atr()Average True Range: the RMA of ta.tr() over length bars.
ta.tr()True range: the largest of high − low, |high − previous close| and |low − previous close|.
ta.stdev()Standard deviation of the last length values (population form, dividing by length).
ta.variance()Variance of the last length values: the square of ta.stdev().
ta.highest()Highest value of the last length values.
ta.lowest()Lowest value of the last length values.
ta.change()Difference between the current value and the value length steps ago (default 1).
ta.roc()Rate of change in percent: 100 × (value − value length ago) / value length ago.
ta.mom()Momentum: the current value minus the value length steps ago (the same as ta.change()).
ta.crossover()1 on the bar where a crosses above b (a > b now, a <= b one step ago), else 0.
ta.crossunder()1 on the bar where a crosses below b (a < b now, a >= b one step ago), else 0.
ta.cross()1 on the bar where a crosses b in either direction, else 0.
ta.rising()1 when src rose on each of the last length steps, else 0.
ta.falling()1 when src fell on each of the last length steps, else 0.
ta.barssince()Steps since cond was last 1 (0 on the step it is 1).
ta.valuewhen()Value of src when cond was 1, occurrence times back (0 = the latest; at most 3).
ta.cum()Running total of src since the first bar; NaN values are skipped.
ta.sum()Sum of the last length values.
ta.vwap()Volume-weighted average price of the typical price (hlc3), restarting at 00:00 UTC every day.
ta.supertrend()TradingView definition.
ta.adx()Average Directional Index (trend strength, 0..100) from directional movement over diLength, smoothed over adxSmoothing.
ta.stoch()Stochastic oscillator: k = SMA(kSmooth) of the close's position in the kLength-bar range (0..100), d = SMA(dSmooth) of k.
ta.obv()On-balance volume: a running total that adds the bar's volume when the close rises and subtracts it when it falls.
ta.pivothigh()The high right bars ago when it is strictly above the left highs before it and the right highs after it, else NaN.
ta.pivotlow()The low right bars ago when it is strictly below the left lows before it and the right lows after it, else NaN.
ta.na()1 where src is NaN (no value yet), else 0.
ta.nz()src with NaN replaced by replacement (default 0).
ta.calc()Derived series from the current values of its inputs, e.g.
ta.recur()A series that carries state from bar to bar (Pine's var and x[1] recursions), e.g.
ta.dev()Mean absolute deviation from the SMA (TradingView ta.dev).
ta.cci()Commodity Channel Index (TradingView ta.cci).
ta.mfi()Money Flow Index over src (usually hlc3) and candle volume (TradingView ta.mfi).
ta.wpr()Williams %R (TradingView ta.wpr), -100..0.
ta.hma()Hull moving average: WMA(2 × WMA(length / 2) − WMA(length), √length) (TradingView ta.hma).
ta.alma()Arnaud Legoux moving average: a Gaussian-weighted window centred at offset (0..1) with width length / sigma (TradingView ta.alma).
ta.linreg()Least-squares line through the last length values, evaluated offset bars back (TradingView ta.linreg).
ta.sar()Parabolic SAR with acceleration start, step inc and cap max (TradingView ta.sar).
ta.dmi()Directional movement: plus (+DI), minus (−DI) and adx, each 0..100 (TradingView ta.dmi).
ta.cmo()Chande momentum oscillator, -100..100: rises minus falls over their sum across length values (TradingView ta.cmo).
ta.tsi()True strength index, -1..1: the change double-smoothed by EMA(long) then EMA(short), over its absolute value smoothed the same way (TradingView ta.tsi).
ta.correlation()Pearson correlation of a and b over the last length values, -1..1.
ta.percentrank()Percent of the previous length values that are at or below the current one (TradingView ta.percentrank).
ta.highestbars()Offset to the highest of the last length values: 0 for the current bar, -k for k bars ago (TradingView ta.highestbars).
ta.lowestbars()Offset to the lowest of the last length values: 0 for the current bar, -k for k bars ago (TradingView ta.lowestbars).
ta.accdist()Accumulation/distribution: a running total of volume weighted by where the close sits in the bar's range (TradingView ta.accdist).

Moving averages ​

ta.sma() ​

ts
ta.sma(src: Series, length: number): Series

Simple moving average: the mean of the last length values. NaN until length values exist.

Types: Series

ta.ema() ​

ts
ta.ema(src: Series, length: number): Series

Exponential moving average with alpha 2 / (length + 1), seeded with the SMA of the first length values.

Types: Series

ta.rma() ​

ts
ta.rma(src: Series, length: number): Series

Wilder's moving average (RMA, used by RSI and ATR): alpha 1 / length, seeded with the SMA of the first length values.

Types: Series

ta.wma() ​

ts
ta.wma(src: Series, length: number): Series

Weighted moving average: the newest value weighs length, the oldest 1.

Types: Series

ta.vwma() ​

ts
ta.vwma(src: Series, length: number): Series

Volume-weighted moving average over the last length bars, weighted by candle volume (alpha).

Types: Series

ta.hma() ​

ts
ta.hma(src: Series, length: number): Series

Hull moving average: WMA(2 × WMA(length / 2) − WMA(length), √length) (TradingView ta.hma).

Types: Series

ta.alma() ​

ts
ta.alma(src: Series, length: number, offset?: number, sigma?: number, floor?: boolean): Series

Arnaud Legoux moving average: a Gaussian-weighted window centred at offset (0..1) with width length / sigma (TradingView ta.alma).

Types: Series

ta.linreg() ​

ts
ta.linreg(src: Series, length: number, offset?: number): Series

Least-squares line through the last length values, evaluated offset bars back (TradingView ta.linreg).

Types: Series

ta.vwap() ​

ts
ta.vwap(): Series

Volume-weighted average price of the typical price (hlc3), restarting at 00:00 UTC every day.

Types: Series

Oscillators and momentum ​

ta.rsi() ​

ts
ta.rsi(src: Series, length: number): Series

Relative Strength Index, 0..100, from Wilder-smoothed gains and losses of src.

Types: Series

ta.macd() ​

ts
ta.macd(src: Series, fast: number, slow: number, signal: number): { macd: Series; signal: Series; hist: Series }

MACD: macd = EMA(fast) − EMA(slow), signal = EMA(macd, signal), hist = macd − signal.

Types: Series

ta.stoch() ​

ts
ta.stoch(kLength: number, kSmooth: number, dSmooth: number): { k: Series; d: Series }

Stochastic oscillator: k = SMA(kSmooth) of the close's position in the kLength-bar range (0..100), d = SMA(dSmooth) of k.

Types: Series

ta.cci() ​

ts
ta.cci(src: Series, length: number): Series

Commodity Channel Index (TradingView ta.cci).

Types: Series

ta.mfi() ​

ts
ta.mfi(src: Series, length: number): Series

Money Flow Index over src (usually hlc3) and candle volume (TradingView ta.mfi).

Types: Series

ta.wpr() ​

ts
ta.wpr(length: number): Series

Williams %R (TradingView ta.wpr), -100..0.

Types: Series

ta.adx() ​

ts
ta.adx(diLength: number, adxSmoothing: number): Series

Average Directional Index (trend strength, 0..100) from directional movement over diLength, smoothed over adxSmoothing.

Types: Series

ta.dmi() ​

ts
ta.dmi(diLength: number, adxSmoothing: number): { plus: Series; minus: Series; adx: Series }

Directional movement: plus (+DI), minus (−DI) and adx, each 0..100 (TradingView ta.dmi).

Types: Series

ta.cmo() ​

ts
ta.cmo(src: Series, length: number): Series

Chande momentum oscillator, -100..100: rises minus falls over their sum across length values (TradingView ta.cmo).

Types: Series

ta.tsi() ​

ts
ta.tsi(src: Series, shortLength: number, longLength: number): Series

True strength index, -1..1: the change double-smoothed by EMA(long) then EMA(short), over its absolute value smoothed the same way (TradingView ta.tsi).

Types: Series

ta.roc() ​

ts
ta.roc(src: Series, length: number): Series

Rate of change in percent: 100 × (value − value length ago) / value length ago.

Types: Series

ta.mom() ​

ts
ta.mom(src: Series, length: number): Series

Momentum: the current value minus the value length steps ago (the same as ta.change()).

Types: Series

ta.change() ​

ts
ta.change(src: Series, length?: number): Series

Difference between the current value and the value length steps ago (default 1).

Types: Series

Volatility and bands ​

ta.bbands() ​

ts
ta.bbands(src: Series, length: number, mult: number): { upper: Series; middle: Series; lower: Series }

Bollinger Bands: middle = SMA(length), upper/lower = middle ± mult × standard deviation.

Types: Series

ta.atr() ​

ts
ta.atr(length: number): Series

Average True Range: the RMA of ta.tr() over length bars.

Types: Series

ta.tr() ​

ts
ta.tr(): Series

True range: the largest of high − low, |high − previous close| and |low − previous close|.

Types: Series

ta.stdev() ​

ts
ta.stdev(src: Series, length: number): Series

Standard deviation of the last length values (population form, dividing by length).

Types: Series

ta.variance() ​

ts
ta.variance(src: Series, length: number): Series

Variance of the last length values: the square of ta.stdev().

Types: Series

ta.dev() ​

ts
ta.dev(src: Series, length: number): Series

Mean absolute deviation from the SMA (TradingView ta.dev).

Types: Series

ta.supertrend() ​

ts
ta.supertrend(factor: number, atrLength: number): { line: Series; direction: Series }

TradingView definition. direction is -1 in an uptrend (line below price) and 1 in a downtrend.

Types: Series

ta.sar() ​

ts
ta.sar(start: number, inc: number, max: number): Series

Parabolic SAR with acceleration start, step inc and cap max (TradingView ta.sar).

Types: Series

Volume ​

ta.obv() ​

ts
ta.obv(): Series

On-balance volume: a running total that adds the bar's volume when the close rises and subtracts it when it falls.

Types: Series

ta.accdist() ​

ts
ta.accdist(): Series

Accumulation/distribution: a running total of volume weighted by where the close sits in the bar's range (TradingView ta.accdist).

Types: Series

Ranges and pivots ​

ta.highest() ​

ts
ta.highest(src: Series, length: number): Series

Highest value of the last length values. NaN if any of them is NaN.

Types: Series

ta.lowest() ​

ts
ta.lowest(src: Series, length: number): Series

Lowest value of the last length values. NaN if any of them is NaN.

Types: Series

ta.highestbars() ​

ts
ta.highestbars(src: Series, length: number): Series

Offset to the highest of the last length values: 0 for the current bar, -k for k bars ago (TradingView ta.highestbars).

Types: Series

ta.lowestbars() ​

ts
ta.lowestbars(src: Series, length: number): Series

Offset to the lowest of the last length values: 0 for the current bar, -k for k bars ago (TradingView ta.lowestbars).

Types: Series

ta.pivothigh() ​

ts
ta.pivothigh(left: number, right: number): Series

The high right bars ago when it is strictly above the left highs before it and the right highs after it, else NaN. Confirmed right bars late.

Types: Series

ta.pivotlow() ​

ts
ta.pivotlow(left: number, right: number): Series

The low right bars ago when it is strictly below the left lows before it and the right lows after it, else NaN. Confirmed right bars late.

Types: Series

Conditions ​

ta.crossover() ​

ts
ta.crossover(a: SeriesLike, b: SeriesLike): BoolSeries

1 on the bar where a crosses above b (a > b now, a <= b one step ago), else 0.

Types: SeriesLike, BoolSeries

ta.crossunder() ​

ts
ta.crossunder(a: SeriesLike, b: SeriesLike): BoolSeries

1 on the bar where a crosses below b (a < b now, a >= b one step ago), else 0.

Types: SeriesLike, BoolSeries

ta.cross() ​

ts
ta.cross(a: SeriesLike, b: SeriesLike): BoolSeries

1 on the bar where a crosses b in either direction, else 0.

Types: SeriesLike, BoolSeries

ta.rising() ​

ts
ta.rising(src: Series, length: number): BoolSeries

1 when src rose on each of the last length steps, else 0.

Types: Series, BoolSeries

ta.falling() ​

ts
ta.falling(src: Series, length: number): BoolSeries

1 when src fell on each of the last length steps, else 0.

Types: Series, BoolSeries

ta.barssince() ​

ts
ta.barssince(cond: BoolSeries): Series

Steps since cond was last 1 (0 on the step it is 1). NaN until it has been 1 once.

Types: BoolSeries, Series

ta.valuewhen() ​

ts
ta.valuewhen(cond: BoolSeries, src: Series, occurrence: number): Series

Value of src when cond was 1, occurrence times back (0 = the latest; at most 3).

Types: BoolSeries, Series

Statistics ​

ta.correlation() ​

ts
ta.correlation(a: Series, b: Series, length: number): Series

Pearson correlation of a and b over the last length values, -1..1.

Types: Series

ta.percentrank() ​

ts
ta.percentrank(src: Series, length: number): Series

Percent of the previous length values that are at or below the current one (TradingView ta.percentrank).

Types: Series

Utilities ​

ta.cum() ​

ts
ta.cum(src: Series): Series

Running total of src since the first bar; NaN values are skipped.

Types: Series

ta.sum() ​

ts
ta.sum(src: Series, length: number): Series

Sum of the last length values.

Types: Series

ta.na() ​

ts
ta.na(src: Series): BoolSeries

1 where src is NaN (no value yet), else 0.

Types: Series, BoolSeries

ta.nz() ​

ts
ta.nz(src: Series, replacement?: number): Series

src with NaN replaced by replacement (default 0).

Types: Series

ta.calc() ​

ts
ta.calc(inputs: readonly Series[], fn: (...values: number[]) => number): Series

Derived series from the current values of its inputs, e.g. ta.calc([basis, atr], (b, a) => b + 2 * a). The function must be pure; it runs once per bar (or block) and again on every update of the open bar. NaN in = NaN out unless you handle it.

Types: Series

Other ​

ta.recur() ​

ts
ta.recur<S extends Record<string, number>>(inputs: readonly Series[], init: S, fn: (state: S, ...values: number[]) => number): Series

A series that carries state from bar to bar (Pine's var and x[1] recursions), e.g. a running maximum: ta.recur([candle.high], { max: -Infinity }, (s, h) => (s.max = math.max(s.max, h))). state holds numbers only; it is saved per bar, so updates of the forming bar start again from the previous bar's state.

Types: Series

AlphaScript language v0.1 · runtime 0.2.0