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.

Covered in Shared runtime
Topic | Page |
|---|---|
| |
| |
| |
| |
| |
|
Unique to definitions
Page | Covers |
|---|---|
| |
| |
| |
How | |
Relative ESM, entry rules, | |
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.
