Skip to main content

chart.timeframe#

Chart interval in seconds (e.g.

SYNTAX#

ctx.timeframe: number

RETURNS#

number — bar duration in seconds.

REMARKS#

Useful for converting bar counts to wall-clock durations or for adapting lookback windows to the active timeframe (e.g. Math.max(20, Math.round(86400 / ctx.timeframe)) for one-day-equivalent lookback).

EXAMPLE#

function onBar(i, ctx) {
  // Adapt EMA length to roughly 24 hours of bars.
  const length = Math.max(20, Math.round(86400 / ctx.timeframe));
  closes[i] = candles[i].close;
  const v = ta.ema(closes, length, i);
  if (v !== null) plot('ema-1d', v);
}

SEE ALSO#

chart.symbol, chart.exchange