Skip to main content

data.candles#

The chart's candle array, injected as a global into every script.

SYNTAX#

candles: ChartCandle[]

RETURNS#

ChartCandle[] — array of OHLCV objects.

REMARKS#

Inside onBar(i, ctx), read candles[i] for the current bar, candles[i-1] for the previous bar, and so on. Avoid mutating candles — the runtime does not copy and other passes may see your changes.

EXAMPLE#

function onBar(i, ctx) {
  const c = candles[i];
  // Common pattern: typical price
  const hlc3 = (c.high + c.low + c.close) / 3;
  plot('hlc3', hlc3, { color: '#fbbf24' });
 
  // Look back two bars
  if (i >= 2) {
    const range = candles[i].high - candles[i-2].low;
    plot('range', range);
  }
}

SEE ALSO#

data.source, types.ChartCandle