MMTMMT Docs

v1 to v2 Migration

Migrating scripts from Scripting v1 to v2.

Legacy Scripting v2

These docs remain available while the v2 engine is supported. For new scripts, use Scripting v3.

Version Directive

All v2 scripts must include the version directive as the first line:

//@version=2

Scripts without this directive will be treated as v1.

Entity Keys

In //@version=2, entities (Line, Box, Label, Marker, Arrow) require a key string as the first argument. The key must be unique per entity type per bar — only one entity with a given key exists per bar.

// v1
const ln = Line({ x1: unix(10), y1: 100, x2: unix(0), y2: 120 })

// v2
const ln = Line("trend", { x1: unix(10), y1: 100, x2: unix(0), y2: 120 })

Entities without a key will not be plotted.

Arrow APIs

plotArrow() and Arrow() are v2-only APIs.

  • plotArrow(label, value, options?) requires //@version=2
  • Arrow(key, options?) requires //@version=2 and a non-empty key

BOOK .data() Migration

In the current BOOK API, .data() and .dataView() are gone. Calling them now throws a migration error that points you back to the docs.

Use the scalar accessors and helpers directly on the subscription instead:

// old
const book = subscribe(data.BOOK)
const snapshot = book.data()
const bestAsk = snapshot ? snapshot.askPrices[0] : na
const bestBid = snapshot ? snapshot.bidPrices[0] : na
// new
const book = subscribe(data.BOOK)
const bestAsk = book.bestAsk()
const bestBid = book.bestBid()

Common replacements:

  • book.data()?.askPrices[i] -> book.askPrice(i)
  • book.data()?.bidPrices[i] -> book.bidPrice(i)
  • book.data()?.askSizes[i] -> book.askSize(i)
  • book.data()?.bidSizes[i] -> book.bidSize(i)
  • manual depth scans -> book.depth(...) or book.imbalance(...)

See BOOK Data Source for the full replacement API.

For more advanced migrations:

  • use book.numLevels(), book.numBids(), and book.numAsks() for availability and side-wise counts
  • use per-level accessors when you still need custom scan logic
  • use book.depthMany(...) and book.imbalanceMany(...) when you need multiple depth windows from one reference price

Missing Values

In v2, numeric TA/math helpers use NaN for missing or not-ready values instead of undefined.

Common updates:

  • x !== undefined -> !na(x)
  • x === undefined -> na(x)
  • object presence checks like if (bb) -> field checks like if (!na(bb.basis))
  • subscription.calc(...) object callbacks must return numeric fields; use NaN for missing fields instead of undefined

Migration

Most migrations are:

  • add //@version=2 as the first line
  • add stable keys to entity constructors
  • use plotArrow() and Arrow() only in v2 scripts
  • replace BOOK .data() / .dataView() usage with BOOK accessors and helpers
  • replace undefined checks on numeric TA/math outputs with na(...) or nz(...)

On this page