ChartnautDocs

Overview

A definition is a script that marks every bar where a setup appears. Run it over history and each mark becomes an event you can browse and study.

In the app the noun is always definition. In code the API word is flow: meta({ kind: "flow" }), FlowCtx, and tool names such as lint_flow. A definition runs through the same runtime as an indicator, so bars, inputs, drawing, dependencies and timeframes all work the same way. This section covers what only definitions have: events, ctx.emit, and multi-file packages.

Definitions library
Tools → Definitions: named setups ready to run over history and study.

Covered in Shared runtime

Topic

Page

outputs.declare with ctx.plot, mark, hline, range, note, trendline

Drawing on the chart

indicators.declare

Declaring indicator dependencies

input.*, dialog, layout

Settings inputs and dialog

ctx.accum and warmup

Remembering values across bars

ctx.session(opts)

Sessions

timeframe(...) handles and runOn

Timeframe handles and runOn

Unique to definitions

Page

Covers

Meta

kind: "flow", slug, window, settings and profiles

Events and snapshots

events.declare, payload schema, paint, oncePer, snapshots.declare

Emit and labels

ctx.emit and its options, the required label

onBar

How onBar runs on the chart and over history

Multi-file packages and imports

Relative ESM, entry rules, imports.use

Examples

Bull bar, EMA cross, OR break

Minimal definition

meta({ name: "Tick Signal", kind: "flow", slug: "tick-signal" });

events.declare({
  id: "tick",
  intent: "alert",
  payload: { reason: { type: "string", description: "Why this fired" } },
  paint: "pin",
});

outputs.declare({ id: "close_line", kind: "line", name: "Close" });

export function onBar(ctx) {
  ctx.plot("close_line", ctx.close);
  if (ctx.close > ctx.open) {
    ctx.emit("tick", { reason: "bullish_bar" }, {
      label: "Bull bar",
      price: ctx.close,
    });
  }
}

Three parts make an event: the id is declared with events.declare, onBar calls ctx.emit with that id, and the call carries a label. Miss any one and the event is dropped.