MMTMMT Docs

Technical Analysis

Moving averages, oscillators, volatility, and crossover detection.

Moving Averages

ta.sma

ta.sma(value, period) -> number

Simple moving average — arithmetic mean of the last period values.

ParamTypeDescription
valuenumberInput value (e.g. candles.close())
periodnumberLookback window

ta.ema

ta.ema(value, period) -> number

Exponential moving average — gives more weight to recent values. Returns NaN when insufficient history.

ParamTypeDescription
valuenumberInput value
periodnumberLookback window

ta.rma

ta.rma(value, period) -> number

Wilder's smoothed moving average (used internally by RSI, ATR). Returns NaN when insufficient history.

ParamTypeDescription
valuenumberInput value
periodnumberLookback window

ta.alma

ta.alma(value, length, offset, sigma, floor?) -> number

Arnaud Legoux moving average. Returns the latest cached value when value is NaN.

ParamTypeDefaultDescription
valuenumberInput value
lengthnumberLookback window
offsetnumberCenter offset in the weighting curve
sigmanumberGaussian width parameter
floorbooleanfalseFloors the computed offset before weighting

ta.swma

ta.swma(value) -> number

Symmetrically weighted moving average, using weights: 1/6, 2/6, 2/6, 1/6.

ParamTypeDescription
valuenumberInput value

ta.wma

ta.wma(value, period) -> number

Weighted moving average — linearly weighted, most recent bar has highest weight.

ParamTypeDescription
valuenumberInput value
periodnumberLookback window

ta.vwma

ta.vwma(price, volume, period) -> number

Volume-weighted moving average.

ParamTypeDescription
pricenumberPrice value
volumenumberVolume value
periodnumberLookback window

ta.hma

ta.hma(value, length) -> number

Hull moving average.

ParamTypeDescription
valuenumberInput value
lengthnumberLookback window

ta.linreg

ta.linreg(value, period, offset?) -> number

Linear regression projected value.

ParamTypeDefaultDescription
valuenumberInput value
periodnumberLookback window
offsetnumber0Bars to project forward

Oscillators

ta.rsi

ta.rsi(value, period) -> number

Relative Strength Index (0–100).

ParamTypeDescription
valuenumberInput value
periodnumberLookback window

ta.stoch

ta.stoch(source, high, low, length) -> number

Stochastic oscillator %K: 100 * (source - lowest(low, length)) / (highest(high, length) - lowest(low, length)).

ParamTypeDescription
sourcenumberInput source, typically candles.close()
highnumberHigh series value
lownumberLow series value
lengthnumberLookback window

ta.macd

ta.macd(value, fast?, slow?, signal?) -> { macd: number, signal: number, hist: number }

Moving Average Convergence Divergence. Returns an object with three values. Fields are NaN when insufficient history.

ParamTypeDefaultDescription
valuenumberInput value
fastnumber12Fast EMA period
slownumber26Slow EMA period
signalnumber9Signal EMA period
//@version=2
indicator("MACD Example", false)
const candles = subscribe(data.OHLCV)

function onBar(index) {
  const m = ta.macd(candles.close())
  plot("MACD", m.macd, { color: color.blue })
  plot("Signal", m.signal, { color: color.red })
  plotHistogram("Hist", m.hist, { color: m.hist >= 0 ? color.green : color.red })
}

ta.dmi

ta.dmi(source, diLength, adxSmoothing) -> { plusDI: number, minusDI: number, adx: number }

Directional Movement Index. Requires an OHLCV source accessor returned by subscribe(data.OHLCV). The object shape is stable and its numeric fields are NaN until the indicator is ready.

ParamTypeDescription
sourceOHLCV accessorAccessor returned by subscribe(data.OHLCV)
diLengthnumberDI smoothing length
adxSmoothingnumberADX smoothing length
//@version=2
indicator("DMI Example", false)
const candles = subscribe(data.OHLCV)

function onBar(index) {
  const d = ta.dmi(candles, 14, 14)
  plot("+DI", d.plusDI, { color: color.green })
  plot("-DI", d.minusDI, { color: color.red })
  plot("ADX", d.adx, { color: color.blue })
}

Volume-based

ta.accdist

ta.accdist(source) -> number

Accumulation/Distribution line (ADL). This is a cumulative series:

adl = previous_adl + (((close - low) - (high - close)) / (high - low)) * volume

When high === low, the multiplier is treated as 0 for that bar. If any input is NaN, the previous ADL value is returned.

Requires an OHLCV subscription accessor returned by subscribe(data.OHLCV).

ParamTypeDescription
sourceOHLCV accessorAccessor returned by subscribe(data.OHLCV)
//@version=2
indicator("Chaikin Oscillator", false)
const candles = subscribe(data.OHLCV)

function onBar(index) {
  const ad = ta.accdist(candles)
  const fast = ta.ema(ad, 3)
  const slow = ta.ema(ad, 10)
  plot("Chaikin", fast - slow)
}

ta.mfi

ta.mfi(source, volume, length) -> number

Money Flow Index. This runtime takes source and volume explicitly.

ParamTypeDescription
sourcenumberPrice source, typically hlc3 or candles.close()
volumenumberVolume value
lengthnumberLookback window

ta.vwap

ta.vwap(source, volume, anchor?, stdevMult?) -> number
ta.vwap(source, volume, anchor, stdevMult) -> { vwap: number, upper: number, lower: number }

Anchored volume-weighted average price. Set anchor to true on the bar where accumulation should reset. When stdevMult is provided, the function returns VWAP plus upper/lower deviation bands as an object. Numeric missing states use NaN. When stdevMult is provided, the returned object keeps a stable shape and uses NaN fields when unavailable.

ParamTypeDefaultDescription
sourcenumberPrice source
volumenumberVolume value
anchorbooleanfalseReset accumulation on this bar
stdevMultnumberBand multiplier
//@version=2
indicator("VWAP Example", true)
const candles = subscribe(data.OHLCV)

function onBar(index) {
  const isNewSession = context.isNew && unix() % 86400 === 0
  const pv = ta.vwap(candles.close(), candles.volume())
  const bands = ta.vwap(candles.close(), candles.volume(), isNewSession, 2)

  plot("VWAP", pv, { color: color.blue })
  plot("Upper", bands.upper, { color: color.red })
  plot("Lower", bands.lower, { color: color.green })
}

Volatility

ta.atr

ta.atr(high, low, close, period) -> number

Average True Range — measures volatility. Returns NaN when insufficient history.

ParamTypeDescription
highnumberHigh price
lownumberLow price
closenumberClose price
periodnumberLookback window

ta.stdev

ta.stdev(value, period) -> number

Standard deviation over a rolling window.

ParamTypeDescription
valuenumberInput value
periodnumberLookback window

ta.bb

ta.bb(value, length, mult) -> { basis: number, upper: number, lower: number }

Bollinger Bands. Returns a stable object with three values. Fields are NaN until enough history exists.

ParamTypeDescription
valuenumberInput value
lengthnumberSMA period
multnumberStandard deviation multiplier
//@version=2
indicator("Bollinger Bands Example", false)
const candles = subscribe(data.OHLCV)

function onBar(index) {
  const bb = ta.bb(candles.close(), 20, 2)
  plot("Upper", bb.upper, { color: color.red })
  plot("Basis", bb.basis, { color: color.gray })
  plot("Lower", bb.lower, { color: color.green })
}

Aggregation

ta.highest

ta.highest(value, period) -> number

Highest value over the last period bars.

ParamTypeDescription
valuenumberInput value
periodnumberLookback window

ta.max

ta.max(value) -> number

All-time maximum for the series so far.

ParamTypeDescription
valuenumberInput value

ta.lowest

ta.lowest(value, period) -> number

Lowest value over the last period bars.

ParamTypeDescription
valuenumberInput value
periodnumberLookback window

ta.pivothigh

ta.pivothigh(source, leftbars, rightbars) -> number

Confirmed pivot high. Returns the pivot price from rightbars bars ago only after the bars to the right have closed and confirmed it as a strict local maximum over the full window.

Use a negative plot offset to draw the confirmed value on the pivot bar:

//@version=2
indicator("Pivot High Example", true)
const candles = subscribe(data.OHLCV)

function onBar(index) {
  const ph = ta.pivothigh(candles.high(), 2, 2)
  plot("Pivot High", na(ph) ? NaN : ph, { color: color.red, offset: -2 })
}
ParamTypeDescription
sourcenumberInput series, typically candles.high()
leftbarsnumberBars to inspect on the left side
rightbarsnumberBars required on the right side before confirmation

ta.pivotlow

ta.pivotlow(source, leftbars, rightbars) -> number

Confirmed pivot low. Returns the pivot price from rightbars bars ago only after the bars to the right have closed and confirmed it as a strict local minimum over the full window.

//@version=2
indicator("Pivot Low Example", true)
const candles = subscribe(data.OHLCV)

function onBar(index) {
  const pl = ta.pivotlow(candles.low(), 2, 2)
  plot("Pivot Low", na(pl) ? NaN : pl, { color: color.green, offset: -2 })
}
ParamTypeDescription
sourcenumberInput series, typically candles.low()
leftbarsnumberBars to inspect on the left side
rightbarsnumberBars required on the right side before confirmation

ta.median

ta.median(value, length) -> number

Rolling median over the last length values.

ParamTypeDescription
valuenumberInput value
lengthnumberLookback window

ta.mode

ta.mode(value, length) -> number

Most frequent value in the rolling window.

ParamTypeDescription
valuenumberInput value
lengthnumberLookback window

ta.dev

ta.dev(value, length) -> number

Mean absolute deviation from the rolling average.

ParamTypeDescription
valuenumberInput value
lengthnumberLookback window

Change Detection

ta.change

ta.change(value, period?) -> number

Difference between current value and value period bars ago.

ParamTypeDefaultDescription
valuenumberInput value
periodnumber1Bars to look back

ta.barssince

ta.barssince(condition) -> number

Number of bars since condition was last true. Returns 0 on the triggering bar.

ParamTypeDescription
conditionbooleanCondition to track

ta.cum

ta.cum(value) -> number

Cumulative sum of the input series.

ParamTypeDescription
valuenumberInput value

ta.roc

ta.roc(value, period) -> number

Rate of change as a percentage: (current - previous) / previous * 100.

ParamTypeDescription
valuenumberInput value
periodnumberBars to look back

ta.rising

ta.rising(value, length) -> boolean

Returns true when value has risen for length consecutive bars.

ParamTypeDescription
valuenumberInput value
lengthnumberConsecutive-bar count

ta.falling

ta.falling(value, length) -> boolean

Returns true when value has fallen for length consecutive bars.

ParamTypeDescription
valuenumberInput value
lengthnumberConsecutive-bar count

Crossovers

ta.cross

ta.cross(a, b) -> boolean

Returns true when a crosses b in either direction.

ParamTypeDescription
anumberFirst series value
bnumberSecond series value

ta.crossover

ta.crossover(a, b) -> boolean

Returns true when a crosses above b (previous bar: a <= b, current bar: a > b).

ParamTypeDescription
anumberFirst series value
bnumberSecond series value

ta.crossunder

ta.crossunder(a, b) -> boolean

Returns true when a crosses below b (previous bar: a >= b, current bar: a < b).

ParamTypeDescription
anumberFirst series value
bnumberSecond series value
//@version=2
indicator("Crossover Example", true)
const candles = subscribe(data.OHLCV)

function onBar(index) {
  const fast = ta.ema(candles.close(), 9)
  const slow = ta.ema(candles.close(), 21)
  if (ta.crossover(fast, slow)) {
    plotMarker("Buy", candles.low(), { marker: shape.up, color: color.green })
  }
}

On this page