MMTMMT Docs

Scripting v2

Write JavaScript indicators for MMT charts.

MMT scripts are evaluated against historical and realtime market data, then emit plots and entities to the chart.

All v2 scripts must start with the version directive:

//@version=2

Quick Example

//@version=2
indicator("SMA Crossover", true)

const fastLen = input.int("Fast Length", 9, { min: 1 })
const slowLen = input.int("Slow Length", 21, { min: 1 })
const candles = subscribe(data.OHLCV)

function onBar(index) {
    const fast = ta.sma(candles.close(), fastLen)
    const slow = ta.sma(candles.close(), slowLen)

    const a = plot("Fast SMA", fast, { color: color.blue, width: 2 })
    const b = plot("Slow SMA", slow, { color: color.red, width: 2 })
    fill(a, b, { color: color.transp(color.blue, 85) })
}

Script Behavior

  • Top-level code runs once when the script loads or changes
  • onBar(index) runs for history warmup and realtime updates
  • Built-in functions inside ta.*, math.*, str.*, and color.* are available in every script
  • Higher-timeframe access is done with subscribe(..., { timeframe }), and higher-timeframe derived values should use subscription.calc(...)
  • New plot labels may be blocked after history warmup, so declare labels early

Scripts must define onBar(index). Calls like indicator(), subscribe(), and input.* are top-level only.

API Map

Key Limits

  • Inputs: 256
  • Subscriptions: 30
  • Plot series labels: 64
  • Plot commands per bar: 64
  • Fill pairs per bar: 16
  • Alert definitions: 32
  • Alert fields per definition: 32
  • Entities: 2000 each for Line, Box, Label, Marker, Arrow
  • History retention, Free: 10,000 bars for non-BOOK sources, 5,000 for BOOK
  • History retention, Pro: 20,000 bars for non-BOOK sources, 10,000 for BOOK

For LLMs

Fetch docs.mmt.gg/scripting/llms.txt for a page index, then pull individual pages as needed via /llms.mdx/{slug} (for example /llms.mdx/scripting/inputs).

On this page