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 secondso: open priceh: high pricel: low pricec: close pricevb: buy volume in quote/USD terms from the providervs: sell volume in quote/USD terms from the providertb: buy trade countts: 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
}
}
}