Documentation

3. Writing Custom Indicators

Created
Jun 5, 2026
Updated
Jun 5, 2026

A custom indicator is authored code that plots one or more values on the chart, configured by inputs and styled like any built-in study. Write one in the custom-indicator editor, opened from the indicator picker.

The shape of an indicator

An indicator is the same export default module as everything else, plus a declaration of its plots and inputs. The simplest one is a moving average:

export default {
  name: "Moving Average",
  next(ctx) {
    ctx.plot("value", ctx.ta.sma(ctx.input("length", 20)).push(ctx.source("source", "close")));
  }
};

next runs once per bar. ctx.ta.sma(length) is a stateful streaming average — call it once per bar with .push(value) and it returns this bar's value (or null during warmup). ctx.plot("value", …) emits the plotted value; the plot id must match a declared plot.

Inputs, plots, and styles

The editor pairs your code with declarative metadata (a spec):

  • Inputs (Settings → Inputs) are your editable parameters — numbers with defaults and min/max/step, selects, and price sources. Read them with ctx.input(key, fallback).
  • Plots / visuals are the rendered outputs — lines, histograms, and horizontal guide lines — each with its own title and style. Emit a value to one with ctx.plot(id, value, { color? }).
  • Styles (Settings → Style) let you and your users restyle each plot, exactly like a built-in study.

A multi-plot example (Bollinger Bands) declares three line visuals — upper, basis, lower — and plots each per bar.

Keeping state

For incremental calculations, keep state on this (initialized in init(ctx)), or use ctx.var(key, () => initial) for a persistent scalar and ctx.series(key) for a history buffer. The full surface is in the Custom Indicator API Reference.

Templates

The editor ships ready-to-edit templates so you do not start from a blank page:

  • Moving Average — a one-line SMA.
  • ATR — average true range via ctx.ta.atr.
  • Bollinger Bands — a three-plot basis-and-bands study.
  • MACD — a multi-line momentum study.
  • Composition — an indicator that consumes another indicator.

Saving and using

Saved custom indicators are stored locally and appear in the picker alongside the built-ins, with the same inputs/style/visibility controls described in Configuring Indicator Settings. They can also be consumed by strategies and other indicators — see Composing Indicators & Patterns.

Legacy note: older indicators used a whole-array body (return { values: { … } }). Those still work, but new indicators use the per-bar next(ctx) form shown here.

Next steps

See every method available inside ctx.

Next: Custom Indicator API Reference