MarketLab Docs
ScriptingData Types

Candles

Candle data shapes for Market Lab scripts.

Candles

Candle studies use onData(ctx, input).

Input

Window mode:

type CandleWindowInput = {
  mode: "window";
  candles: Candle[];
}

Stream mode:

type CandleStreamInput = {
  mode: "stream";
  candle: Candle;
}

Use input.mode when a script supports both modes.

Candle

type Candle = {
  t: number;
  o: number;
  h: number;
  l: number;
  c: number;
  vb: number;
  vs: number;
  tb: number;
  ts: number;
}

Fields:

  • t: candle timestamp in Unix seconds
  • o: open price
  • h: high price
  • l: low price
  • c: close price
  • vb: buy volume in quote/USD terms from the provider
  • vs: sell volume in quote/USD terms from the provider
  • tb: buy trade count
  • ts: sell trade count

Window Example

export function onData(ctx, input) {
  const latest = input.candles[input.candles.length - 1]

  return {
    metrics: {
      candles: input.candles.length,
      latest_close: latest.c,
      latest_delta: latest.vb - latest.vs
    }
  }
}

Stream Example

export function onData(ctx, input) {
  return {
    metrics: {
      close: input.candle.c,
      delta: input.candle.vb - input.candle.vs
    }
  }
}

On this page