MMTMMT Docs

Globals

NA helpers, series storage, logging, bar info, and display utilities.

NA and Series Helpers

na

na -> NaN
na() -> NaN
na(value) -> boolean

na can be used either as a missing-value sentinel or as a function.

When called with no arguments, returns NaN. Bare na and na() are equivalent when you want to represent a missing plotted value.

When called with a value, returns true if the value is missing (undefined, null, NaN, or na).

Numeric TA/math builtins use NaN as their normal missing-value sentinel during warmup or invalid numeric states.

ParamTypeDescription
valueanyValue to check
//@version=2
indicator("na Example", false)
const candles = subscribe(data.OHLCV)

function onBar(index) {
  const val = candles.close() >= candles.open() ? candles.close() : na

  if (na(ta.sma(candles.close(), 50))) return
  plot("Conditional Close", val, { color: color.blue })
}

nz

nz(value, replacement?) -> number

Returns value if it's a valid number, otherwise returns replacement.

ParamTypeDefaultDescription
valueanyValue to check
replacementnumber0Fallback if value is missing
//@version=2
indicator("nz Example", false)
const candles = subscribe(data.OHLCV)

function onBar(index) {
  const safe = nz(ta.ema(candles.close(), 20), 0)
  plot("Safe EMA", safe, { color: color.orange })
}

Series

Series(name) -> number[]

Returns a mutable named series array for storing per-bar values across evaluations.

ParamTypeDescription
namestringUnique series identifier
//@version=2
indicator("Series Example", false)
const candles = subscribe(data.OHLCV)
const myData = Series("custom")

function onBar(index) {
  myData[barIndex()] = candles.close() - candles.open()
  plot("Close - Open", myData[barIndex()], { color: color.teal })
}

Logging

log

log(...args) -> void

Writes arguments to the script log panel. Accepts any number of values.

//@version=2
indicator("log Example", false)
const candles = subscribe(data.OHLCV)

function onBar(index) {
  if (!context.isNew) return
  log("price:", candles.close(), "rsi:", ta.rsi(candles.close(), 14))
}

Bar Info

unix

unix(offset?) -> number

Returns the unix timestamp (seconds) of the bar at offset from the first subscription.

ParamTypeDefaultDescription
offsetnumber00 = current bar, 1 = previous, etc.

barCount

barCount() -> number

Compatibility helper. Returns the number of bars currently available in the first subscription.

barIndex

barIndex() -> number

Returns the absolute index of the current bar within the loaded context (0 = oldest loaded bar).

loadedBarCount

loadedBarCount() -> number

Returns the total number of bars in the loaded context. Unlike barCount(), this is the stable loaded-context size rather than the current first-subscription bar count kept for compatibility.

lastBarIndex

lastBarIndex() -> number

Returns the last absolute bar index in the loaded context. This is typically loadedBarCount() - 1.

isNewBar

isNewBar() -> boolean

Returns true when the current bar's unix timestamp differs from the previous evaluation. Useful for detecting when a new candle has formed.

isRealtimeBar

isRealtimeBar() -> boolean

Returns !isNewBar(). true when the current bar is being updated in-place.

Display

setDisplayName

setDisplayName(name) -> void

Override the indicator title shown in the chart UI.

ParamTypeDescription
namestringNew display name
//@version=2
indicator("RSI Example", false)
const len = input.int("Length", 14, { min: 1 })
const candles = subscribe(data.OHLCV)

setDisplayName("RSI (" + len + ")")

function onBar(index) {
  plot("RSI", ta.rsi(candles.close(), len), { color: color.blue })
}

agg

agg(...exchanges) -> string
agg(exchanges) -> string

Builds a canonical aggregated exchange string from exchange ids.

  • accepts either multiple string arguments or a single string[]
  • splits existing colon-separated aggregate strings
  • sorts exchanges alphabetically
  • removes duplicates
//@version=2
indicator("Aggregation Helper Example", false)
const ex = agg(["bybitf", "binancef"], "okxf:bybitf")
const oi = subscribe(data.OI, { exchange: ex })

function onBar(index) {
  plot("OI Close", oi.close(), { color: color.blue })
}

getExchangeList

getExchangeList() -> string[]

Returns an array of available exchange identifiers.

//@version=2
indicator("Exchange List Example", false)
const exchanges = getExchangeList()

function onBar(index) {
  if (!context.isFirst) return
  log("Available:", exchanges.join(", "))
}

On this page