Skip to main content

types.OnBarCtx#

Per-bar context passed as the second argument to onBar(i, ctx).

SYNTAX#

interface OnBarCtx { state: object; settings: object; isFirst: boolean; isLast: boolean; isHistory: boolean; isRealtime: boolean; symbol: string; exchange: string; timeframe: number; tickSize: number | null; stepSize: number | null; }

ARGUMENTS#

  • state (object) — Persistent per-script storage. Survives between onBar calls within the same script run; reset on warmup.
  • settings (object) — User's current setting values, keyed by the key field of each getSettings() entry.
  • isFirst (boolean) — True on the first bar of the warmup loop (i === 0).
  • isLast (boolean) — True on the last bar of the current call.
  • isHistory (boolean) — True during warmup (historical replay).
  • isRealtime (boolean) — True during tick mode (live bar).
  • symbol (string) — Active chart symbol; empty string when unset.
  • exchange (string) — Active exchange; empty string when unset.
  • timeframe (number) — Bar duration in seconds. 0 if unparseable.
  • tickSize (number | null) — Minimum price increment; null on cache miss / unknown symbol / anon user.
  • stepSize (number | null) — Minimum size increment; same null semantics as tickSize.

RETURNS#

Type definition.

EXAMPLE#

function onBar(i, ctx) {
  if (ctx.isFirst) ctx.state.runMax = -Infinity;
  ctx.state.runMax = Math.max(ctx.state.runMax, candles[i].high);
  if (ctx.isLast) plot('runMax', ctx.state.runMax);
}

SEE ALSO#

indicator.onBar, chart.symbol, chart.tickSize