ChartnautDocs

Overview

An indicator is a script that draws on Charts: moving averages, oscillators, bands, markers, custom overlays. This section covers what indicators add on top of the shared runtime: where outputs draw, which series types exist, and how onBar ties them together.

Indicators library and community list
Tools → Indicators: your library plus community installs

The minimal indicator

meta({ shortName: "EMA", kind: "overlay" });
dialog({ title: "EMA" });
const length = input.number({ id: "length", label: "Length", default: 20, min: 1 });
warmup((w) => w.ema(length));
output.line({ id: "ema", color: "#2196f3" });
layout(tab({ id: "main", title: "Main" }, section({ id: "p", title: "Parameters" }, length)));

export function onBar(ctx) {
  const k = 2 / (ctx.params.length + 1);
  const ema = ctx.accum("ema", () => ({ t: 0, prev: null, cur: null }), (s) => {
    if (s.t !== ctx.time) { s.prev = s.cur; s.t = ctx.time; } // a new bar: commit the last one
    s.cur = s.prev == null ? ctx.close : s.prev + k * (ctx.close - s.prev);
    return s;
  });
  ctx.plot("ema", ema.cur);
}

Every piece is required for a reason:

Call

Why

meta({ shortName, kind })

Legend label and where it draws. Call it once.

dialog({ title })

The settings window. The script does not build without it.

input.*

Settings, read in onBar as ctx.params.<id>.

warmup(...)

Any script that keeps state in ctx.accum must declare how far back that state reaches, or lint refuses it (window/warmup-required).

output.*

Every series the script may emit, by id.

onBar(ctx)

Runs once per bar, and again for the forming bar on every tick. The EMA above is written so a repeated tick replaces the tip instead of stacking on it. See onBar.

Write indicators in Tools → Indicators, in the code editor or with the indicator authoring agent.

In this section

Page

Covers

Overlay vs pane

Every meta field: kind, window, dataSource, runOn, mode

Panes & scales

Routing outputs to subpanes, price scales, checking the layout

Series types

Every output.* kind, its ctx verb and its options

onBar

The per-bar function, the forming bar, state that survives ticks

Layers

output.layer: scripted chart primitives, drawing tools, chart types

Painting a layer

Canvas2D and WebGL painting, layout, hit testing, gestures

Examples

Ten public library indicators, simple to complex

Covered in Shared runtime

Topic

Page

Bar fields, ctx.instrument, ctx.chart

Price and bar data

ctx.accum

Remembering values across bars

input.*, dialog, layout

Settings inputs and dialog

ctx.plot, ctx.mark, ctx.hline, ctx.range lifecycles

Drawing on the chart

indicators.declare

Declaring indicator dependencies

timeframe(...) handles, warmup, retain

Timeframe handles and runOn

ctx.summary

Summaries and long windows