Market LabDocs
ScriptingData Types

Candles

Normalized candle shape available to Market Lab scripts.

Candles

Read candles through history.source in live runs and backtests:

const candles = history.source('candles@binancef@mmt')
const latest = history.source('candles@binancef@mmt', 0)

Shape

type Candle = {
  t: number
  o: number
  h: number
  l: number
  c: number
  volume: number
  trades: number
  close_time?: number
  vb?: number
  vs?: number
  tb?: number
  ts?: number
}

Fields:

  • t: bucket start in Unix milliseconds.
  • o, h, l, c: open, high, low, and close prices.
  • volume: total volume available for the candle.
  • trades: total trade count.
  • close_time: exclusive bucket end in Unix milliseconds when supplied.
  • vb, vs: buy and sell volume when directional volume is available.
  • tb, ts: buy and sell trade counts when directional counts are available.

Live MMT and BULK candles are derived locally from trades, so all directional fields and close_time are present. Live volume, vb, and vs use the base quantity reported by the raw trade stream.

Backtests read provider-stored candles. MMT historical candles include directional fields. BULK historical candles can omit directional fields because its stored candle response does not provide them.

Example

export function onData(ctx, input, history) {
  const candles = history.source('candles@binancef@mmt')
  const latest = history.source('candles@binancef@mmt', 0)
  if (!latest) return

  const sma = ctx.study.sma(candles, { window: 20 })
  const delta =
    latest.vb !== undefined && latest.vs !== undefined
      ? latest.vb - latest.vs
      : null

  return {
    metrics: {
      candles: candles.length,
      close: latest.c,
      sma: sma.latest,
      delta,
    },
  }
}

See Candles Source for live aggregation, startup alignment, and historical timeframe limits.

On this page