feature

Declaring indicator dependencies

Your script can depend on another indicator (for example ATR or VWAP) by declaring it once, then reading its values on ctx.indicators.

Use this whenever one script builds on another’s series. The declare shape is the same for indicators, definitions, and studies — always pin a version when you can.

Declare (same contract)

indicators.declare({
  slug: "atr",
  as: "atr",
  version: 3,
  settings: { /* optional locked settings */ },
});

Field

Role

slug

Indicator slug

as

Local alias on ctx.indicators

version

Pin a version (always preferred; required on indicator/flow contracts)

settings

Optional settings override

Agents should call resolve_dependency_contract / request_add_indicator before inventing shapes.

Read — indicator & definition

function onBar(ctx) {
  const atr = ctx.indicators.atr;
  if (!atr) return;
  const v = atr.value; // or atr.at(0), atr.last()
  if (v == null) return;
  ctx.plot("atr_copy", v);
}

IndicatorView helpers

Method

Role

value

Current value

at(offset)

Offset bars

last() / lastTime()

Last known

history(maxBars?)

Recent history

lifecycle(query?)

Lifecycle query

ranges / hlines / marks / plots / trendlines

Visual accessors

Read — study

export function onEvent(ctx) {
  const atr = ctx.indicators.atr?.atr; // output map + visual accessors
  if (atr == null) return;
  ctx.collect("atr", atr);
}

Studies also declare upstream definitions with flows.declare — that is study-specific. See Study declarations.

Declared vs had-data

Empty values are normal (warmup, purge, MTF gaps). Guard explicitly — Dependency outputs.

Next

  1. Dependency outputs

  2. Drawing on the chart