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).
Function Returns Description ta.sma(source, length)number Simple moving average. ta.ema(source, length)number Exponential moving average (more weight on recent candles). ta.wma(source, length)number Weighted moving average (decreasing linear weights). ta.vwma(source, length)number Volume-weighted moving average. ta.rma(source, length)number Wilder's moving average (smoothing used in RSI and ATR). ta.swma(source)number Symmetrically weighted average of 4 candles. ta.alma(source, length, offset, sigma)number Arnaud Legoux Moving Average — smoothing with a Gaussian filter. ta.hma(source, length)number Hull Moving Average — smooth average with low lag. ta.linreg(source, length, offset?)number Value projected by linear regression (least squares). ta.vwap(source)number Volume-weighted average price, anchored to the session.
Function Returns Description ta.rsi(source, length)number Relative Strength Index (0 to 100). ta.macd(source, fast, slow, signal)tuple MACD — moving average convergence/divergence. Returns [macd, signal, histogram]. ta.stoch(source, high, low, length)number Stochastic Oscillator. ta.mom(source, length)number Momentum — price difference from N candles back. ta.cci(source, length)number Commodity Channel Index. ta.mfi(series, length)number Money Flow Index — volume-weighted RSI. ta.roc(source, length)number Rate of Change — percentage change over N candles. ta.wpr(length)number Williams %R. ta.cmo(source, length)number Chande Momentum Oscillator. ta.tsi(source, shortLength, longLength)number True Strength Index. ta.cog(source, length)number Center of Gravity. ta.rci(source, length)number Rank Correlation Index.
Function Returns Description ta.bb(source, length, mult)tuple Bollinger Bands. Returns [basis, upper, lower]. ta.atr(length)number Average True Range — average volatility over the period. ta.stdev(source, length)number Standard deviation over the period. ta.variance(source, length)number Variance over the period. ta.dmi(diLength, adxSmoothing)tuple Directional Movement Index. Returns [+DI, -DI, ADX]. ta.tr(handleNa?)number True Range — the candle's real range. ta.dev(source, length)number Mean absolute deviation from the average. ta.supertrend(factor, atrPeriod)tuple SuperTrend. Returns [line, direction] (direction < 0 means uptrend). ta.sar(start, increment, max)number Parabolic SAR — stop and reverse points. ta.kc(source, length, mult, useTrueRange?)tuple Keltner Channels. Returns [upper, basis, lower]. ta.donchian(length)tuple Donchian Channel. Returns [upper, basis, lower]. ta.bbw(source, length, mult)number Bollinger Bands Width. ta.kcw(source, length, mult, useTrueRange?)number Keltner Channels Width.
Function Returns Description ta.crossover(a, b)bool True when the first series crosses above the second. ta.crossunder(a, b)bool True when the first series crosses below the second. ta.change(source, length?)number Change from N candles back. ta.highest(source, length)number Highest value of the series over the period. ta.lowest(source, length)number Lowest value of the series over the period. ta.valuewhen(condition, source, occurrence)number Value of the series the Nth time the condition was true. ta.barssince(condition)number Number of candles since the condition was last true. ta.highestbars(source, length)number How many candles back the period's highest value is. ta.lowestbars(source, length)number How many candles back the period's lowest value is. ta.pivothigh(source, leftBars, rightBars)number Detects a pivot high with N candles to the left and right. ta.pivotlow(source, leftBars, rightBars)number Detects a pivot low with N candles to the left and right. ta.falling(source, length)bool True if the series has fallen for N candles in a row. ta.rising(source, length)bool True if the series has risen for N candles in a row. ta.cross(a, b)bool True when there's a crossover in either direction.
Function Returns Description ta.cum(source)number Cumulative sum of the series. ta.percentrank(source, length)number Percentile rank of the current value over the period. ta.correlation(source1, source2, length)number Correlation between two series over the period. ta.median(source, length)number Median of the series over the period. ta.range(source, length)number Range (high minus low) over the period. ta.max(source)number Highest value of the series since the start of the chart. ta.min(source)number Lowest value of the series since the start of the chart. ta.mode(source, length)number Mode (most frequent value) of the series over the period. ta.percentile_linear_interpolation(source, length, percentage)number Period percentile by linear interpolation. ta.percentile_nearest_rank(source, length, percentage)number Period percentile by the nearest-rank method.
Function Returns Description ta.obv()number On-Balance Volume. ta.accdist()number Accumulation/Distribution Line. ta.iii()number Intraday Intensity Index. ta.nvi()number Negative Volume Index. ta.pvi()number Positive Volume Index. ta.pvt()number Price Volume Trend. ta.wad()number Williams Accumulation/Distribution. ta.wvad()number Williams Variable Accumulation/Distribution.
Function Returns Description ta.pivot_point_levels(type, anchor, developing?)array Pivot levels (P, R1, S1, R2, S2, ...). Returns an array.
//@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 )
//@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)
//@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 )