FuturaDevelopers
Reference

Technical analysis (ta.*)

Reference for NeuroScript's technical-analysis functions.

The ta.* namespace gathers NeuroScript's technical-analysis functions. They all operate on series (like close) and return the value computed at the current candle.

Functions that return multiple values (a tuple) use destructuring, e.g.: [macd, signal, histogram] = ta.macd(close, 12, 26, 9).

Averages and smoothing

FunctionReturnsDescription
ta.sma(source, length)numberSimple moving average.
ta.ema(source, length)numberExponential moving average (more weight on recent candles).
ta.wma(source, length)numberWeighted moving average (decreasing linear weights).
ta.vwma(source, length)numberVolume-weighted moving average.
ta.rma(source, length)numberWilder's moving average (smoothing used in RSI and ATR).
ta.swma(source)numberSymmetrically weighted average of 4 candles.
ta.alma(source, length, offset, sigma)numberArnaud Legoux Moving Average — smoothing with a Gaussian filter.
ta.hma(source, length)numberHull Moving Average — smooth average with low lag.
ta.linreg(source, length, offset?)numberValue projected by linear regression (least squares).
ta.vwap(source)numberVolume-weighted average price, anchored to the session.

Oscillators and momentum

FunctionReturnsDescription
ta.rsi(source, length)numberRelative Strength Index (0 to 100).
ta.macd(source, fast, slow, signal)tupleMACD — moving average convergence/divergence. Returns [macd, signal, histogram].
ta.stoch(source, high, low, length)numberStochastic Oscillator.
ta.mom(source, length)numberMomentum — price difference from N candles back.
ta.cci(source, length)numberCommodity Channel Index.
ta.mfi(series, length)numberMoney Flow Index — volume-weighted RSI.
ta.roc(source, length)numberRate of Change — percentage change over N candles.
ta.wpr(length)numberWilliams %R.
ta.cmo(source, length)numberChande Momentum Oscillator.
ta.tsi(source, shortLength, longLength)numberTrue Strength Index.
ta.cog(source, length)numberCenter of Gravity.
ta.rci(source, length)numberRank Correlation Index.

Bands, channels and volatility

FunctionReturnsDescription
ta.bb(source, length, mult)tupleBollinger Bands. Returns [basis, upper, lower].
ta.atr(length)numberAverage True Range — average volatility over the period.
ta.stdev(source, length)numberStandard deviation over the period.
ta.variance(source, length)numberVariance over the period.
ta.dmi(diLength, adxSmoothing)tupleDirectional Movement Index. Returns [+DI, -DI, ADX].
ta.tr(handleNa?)numberTrue Range — the candle's real range.
ta.dev(source, length)numberMean absolute deviation from the average.
ta.supertrend(factor, atrPeriod)tupleSuperTrend. Returns [line, direction] (direction < 0 means uptrend).
ta.sar(start, increment, max)numberParabolic SAR — stop and reverse points.
ta.kc(source, length, mult, useTrueRange?)tupleKeltner Channels. Returns [upper, basis, lower].
ta.donchian(length)tupleDonchian Channel. Returns [upper, basis, lower].
ta.bbw(source, length, mult)numberBollinger Bands Width.
ta.kcw(source, length, mult, useTrueRange?)numberKeltner Channels Width.

Crossovers and detection

FunctionReturnsDescription
ta.crossover(a, b)boolTrue when the first series crosses above the second.
ta.crossunder(a, b)boolTrue when the first series crosses below the second.
ta.change(source, length?)numberChange from N candles back.
ta.highest(source, length)numberHighest value of the series over the period.
ta.lowest(source, length)numberLowest value of the series over the period.
ta.valuewhen(condition, source, occurrence)numberValue of the series the Nth time the condition was true.
ta.barssince(condition)numberNumber of candles since the condition was last true.
ta.highestbars(source, length)numberHow many candles back the period's highest value is.
ta.lowestbars(source, length)numberHow many candles back the period's lowest value is.
ta.pivothigh(source, leftBars, rightBars)numberDetects a pivot high with N candles to the left and right.
ta.pivotlow(source, leftBars, rightBars)numberDetects a pivot low with N candles to the left and right.
ta.falling(source, length)boolTrue if the series has fallen for N candles in a row.
ta.rising(source, length)boolTrue if the series has risen for N candles in a row.
ta.cross(a, b)boolTrue when there's a crossover in either direction.

Statistics and ranking

FunctionReturnsDescription
ta.cum(source)numberCumulative sum of the series.
ta.percentrank(source, length)numberPercentile rank of the current value over the period.
ta.correlation(source1, source2, length)numberCorrelation between two series over the period.
ta.median(source, length)numberMedian of the series over the period.
ta.range(source, length)numberRange (high minus low) over the period.
ta.max(source)numberHighest value of the series since the start of the chart.
ta.min(source)numberLowest value of the series since the start of the chart.
ta.mode(source, length)numberMode (most frequent value) of the series over the period.
ta.percentile_linear_interpolation(source, length, percentage)numberPeriod percentile by linear interpolation.
ta.percentile_nearest_rank(source, length, percentage)numberPeriod percentile by the nearest-rank method.

Volume

FunctionReturnsDescription
ta.obv()numberOn-Balance Volume.
ta.accdist()numberAccumulation/Distribution Line.
ta.iii()numberIntraday Intensity Index.
ta.nvi()numberNegative Volume Index.
ta.pvi()numberPositive Volume Index.
ta.pvt()numberPrice Volume Trend.
ta.wad()numberWilliams Accumulation/Distribution.
ta.wvad()numberWilliams Variable Accumulation/Distribution.

Levels

FunctionReturnsDescription
ta.pivot_point_levels(type, anchor, developing?)arrayPivot levels (P, R1, S1, R2, S2, ...). Returns an array.

Examples

RSI with levels

//@version=6
indicator("RSI", overlay=false)

length = input.int(14, "Length", minval=1)
rsi = ta.rsi(close, length)

col = rsi >= 70 ? color.red : rsi <= 30 ? color.green : color.blue
plot(rsi, "RSI", color=col, linewidth=2)
hline(70, "Overbought", color=color.red, linestyle=2)
hline(30, "Oversold", color=color.green, linestyle=2)

Bollinger Bands (tuple)

//@version=6
indicator("Bollinger", overlay=true)

length = input.int(20, "Length")
mult = input.float(2.0, "Deviations")

[avg, upper, lower] = ta.bb(close, length, mult)
plot(avg, "Basis", color=color.orange)
plot(upper, "Upper", color=color.blue)
plot(lower, "Lower", color=color.blue)

SuperTrend with signals

//@version=6
indicator("SuperTrend", overlay=true)

factor = input.float(3.0, "Factor", minval=0.5)
period = input.int(10, "ATR", minval=1)

[st, direction] = ta.supertrend(factor, period)
isUp = direction < 0
plot(st, "SuperTrend", color=isUp ? color.green : color.red, linewidth=3)

buySignal = (direction < 0 and direction[1] > 0) ? low : na
plot(buySignal, "Buy", color=color.green, style="triangleup", linewidth=5)

On this page