feature
First study guide
This walkthrough builds a small study that counts definition events and publishes a simple table of results.
Use it after you have Collect data for a definition. Studies answer “what usually happens next?” — they do not mark new setups on the chart.
What you need first
A definition with at least one collected dataset
Steps
Open the definition → create or open a study.
Paste the script below. Change
slugto your definition’s slug.Attach datasets and run on an instrument / range / timeframe.
Open results. For chart pins, see Show studies on charts — that is a separate authoring step.
Full script
meta({ name: "Bull bar count", kind: "study" });
flows.declare({
slug: "bull-bar",
as: "bull",
});
results.declare({
id: "summary",
kind: "metric",
title: "Event count",
});
results.declare({
id: "rows",
kind: "table",
title: "Events",
});
export function onEvent(ctx) {
if (ctx.event.flow !== "bull") return;
ctx.collect("n", 1);
ctx.collect("rows", {
time: ctx.event.time,
range: ctx.event.payload.range,
});
}
export function onFinish(ctx) {
const n = ctx.collected("n").length;
ctx.publish("summary", { value: n, label: "Events" });
ctx.publish("rows", ctx.collected("rows"));
}Important distinctions
Studies consume flow events. They do not call
ctx.emit.ctx.publishbelongs inonFinish(after aggregation). Usectx.collectinsideonEvent.Showing results on the Terminal uses Put on chart (or the pin orchestrator) — not the study authoring agent. See Show studies on charts.
