Skip to content

Functions

Function Args Description
sma 2 Simple moving average of a series over N periods
ema 2 Exponential moving average over N periods
wma 2 Weighted moving average over N periods
rsi 2 Relative Strength Index (0–100) of a series
macd 1–4 MACD line of a series; args: (series, fast=12, slow=26, signal=9)
atr 1 Average True Range over N periods; uses full OHLC
cci 1 Commodity Channel Index over N periods; uses full OHLC
mfi 1 Money Flow Index over N periods; uses OHLCV
obv 0 On-Balance Volume; cumulative
vwap 0 Volume Weighted Average Price; intraday reset
roc 1 Rate of change (%) of close over N periods; uses close
stdev 2 Rolling standard deviation of a series over N periods
highest 2 Highest value of a series over the last N periods
lowest 2 Lowest value of a series over the last N periods
change 1–2 Difference between current value and value N bars ago; default 1
crossover 2 Returns 1 on the bar where series A crosses above series B
crossunder 2 Returns 1 on the bar where series A crosses below series B
abs 1 Absolute value; element-wise
min 2 Element-wise minimum of two series/scalars
max 2 Element-wise maximum of two series/scalars
sqrt 1 Square root; element-wise; negative → NaN
log 1 Natural log; element-wise; x <= 0 → NaN
nz 1–2 nz(x[, y]): replace NaN in x with y; default 0
na 1 na(x): 1 where x is NaN/undefined, else 0
ta.rma 2 Wilder's smoothing, RMA/SMMA, of a series over N periods
ta.hma 2 Hull moving average over N periods
ta.vwma 2 Volume-weighted moving average of a series over N periods; uses candle volume
ta.dev 2 Mean absolute deviation from the SMA over N periods
ta.variance 2 Rolling population variance over N periods
ta.median 2 Rolling median of a series over N periods
ta.sum 2 Rolling sum of a series over N periods
ta.cum 1 Cumulative running sum of a series
ta.linreg 2 Linear-regression value; least-squares line over N periods
ta.percentrank 2 Percent of the prior N values that are <= the current value; 0–100
ta.correlation 3 Pearson correlation of two series over N periods; -1..1
ta.mom 2 Momentum: difference between current value and value N bars ago
ta.tr 0–1 True range per bar; uses full OHLC; optional handle-NaN arg ignored
ta.tsi 2–3 True Strength Index of a series; args: (series, short=25, long=13)
ta.cmo 2 Chande Momentum Oscillator of a series over N periods; -100..100
ta.willr 1 Williams %R over N periods; -100..0; uses full OHLC
ta.wpr 1 Williams %R, alias of willr, over N periods; uses full OHLC
ta.stoch 1–2 Stochastic %K line, primary; args: (kPeriod=14, dPeriod=3); uses full OHLC
ta.bb 1–2 Bollinger Bands basis line, the SMA middle; args: (period=20, stdDev=2); use stdev() for the bands
ta.kc 1–3 Keltner Channel basis line, the EMA middle; args: (period=20, atrPeriod=10, mult=1.5)
ta.supertrend 0–2 Supertrend line; args: (atrPeriod=10, mult=3); uses full OHLC
ta.sar 0–2 Parabolic SAR; args: (start=0.02, max=0.2); uses full OHLC
ta.rising 2 rising(series, len): 1 if the series rose on each of the last len bars
ta.falling 2 falling(series, len): 1 if the series fell on each of the last len bars
ta.cross 2 cross(a, b): 1 on any bar where a and b cross in either direction
ta.barssince 1 barssince(cond): number of bars since cond was last truthy
ta.valuewhen 3 valuewhen(cond, src, occurrence): src value at the Nth-most-recent bar where cond was true; 0 = most recent
ta.pivothigh 3 pivothigh(src, left, right): pivot-high value, plotted right bars after it forms
ta.pivotlow 3 pivotlow(src, left, right): pivot-low value, plotted right bars after it forms
ta.highestbars 2 highestbars(series, len): negative offset to the highest value in the last len bars
ta.lowestbars 2 lowestbars(series, len): negative offset to the lowest value in the last len bars
math.pow 2 pow(x, y): x raised to the power y; element-wise
math.log10 1 Base-10 logarithm; element-wise; x <= 0 → NaN
math.exp 1 e raised to x; element-wise
math.round 1 Round to nearest integer; element-wise
math.floor 1 Round down to integer; element-wise
math.ceil 1 Round up to integer; element-wise
math.sign 1 Sign of x: -1, 0, or 1; element-wise
math.avg 2–8 avg(a, b, …): element-wise mean of 2–8 series/scalars
math.sum 2–8 math.sum(a, b, …): element-wise sum of 2–8 series/scalars