Skip to content

charton API


charton API / @chart-on/core / index / IndicatorDef

Interface: IndicatorDef<I> ​

Defined in: packages/core/src/indicators/types.ts:366

Definition of an indicator type: its id and name, inputs, plots and fills, where it draws, and the compute (and optional update) that produce its values. Once registered, the indicator can be added by its id.

Example ​

ts
const range: IndicatorDef<{ color: string }> = {
  id: 'range',
  name: 'Bar range',
  placement: 'pane',
  inputs: [{ id: 'color', type: 'color', default: '#2a9d8f' }],
  plots: [{ id: 'range', type: 'line', colorInput: 'color' }],
  compute: (src) => ({ range: src.high.map((h, i) => h - src.low[i]!) }),
};
chart.indicators.register(range);
chart.indicators.add('range');

Type Parameters ​

I ​

I extends Record<string, InputValue> = Record<string, InputValue>

Properties ​

aliases? ​

optional aliases?: string[]

Defined in: packages/core/src/indicators/types.ts:395

Other names search matches, e.g. ['Bollinger Bands'] for "BB".


autoscaleRule? ​

optional autoscaleRule?: AutoscaleRule

Defined in: packages/core/src/indicators/types.ts:430

How the indicator's own pane fits its values, e.g. { centerOn: 0 } for a histogram around zero. The chart sets it as the pane scale's autoscaleRule when it adds the indicator. Only for placement: 'pane'.


category? ​

optional category?: string

Defined in: packages/core/src/indicators/types.ts:393

Picker category. The well-known ids are 'trend', 'momentum', 'volatility', 'volume' and 'profiles'; any other string is a custom category. Indicators without one are listed under "Other".


chunkBars? ​

optional chunkBars?: number

Defined in: packages/core/src/indicators/types.ts:496

Most bars one fetch covers. Longer ranges are split into chunks that are fetched in parallel and merged. Default: one call per range.


description? ​

optional description?: string

Defined in: packages/core/src/indicators/types.ts:387

One-sentence description shown in an indicator picker.


fields? ​

optional fields?: string[]

Defined in: packages/core/src/indicators/types.ts:476

Names of the values in each external row, in row order: ['oi'] reads rows [time, oi] and gives compute data.oi. Required with fetch or subscribe, and only allowed with one of them.


fills? ​

optional fills?: FillDef[]

Defined in: packages/core/src/indicators/types.ts:417


fixedRange? ​

optional fixedRange?: object

Defined in: packages/core/src/indicators/types.ts:424

Range the indicator's own pane shows whatever the values, e.g. { min: 0, max: 100 } for an oscillator. The chart sets it as the pane scale's fixedRange when it adds the indicator, so the price range API can still change it. Only for placement: 'pane'.

max ​

max: number

min ​

min: number


id ​

id: string

Defined in: packages/core/src/indicators/types.ts:373

Stable type id used when saving and restoring (e.g. 'sma'). Indicators shipped in a third-party package prefix it with the package name: 'my-lib/vwap-bands'. The first-party built-ins use bare ids. No .: it is part of message keys such as indicator.<id>.


inputs ​

inputs: InputDef[]

Defined in: packages/core/src/indicators/types.ts:415


name ​

name: string

Defined in: packages/core/src/indicators/types.ts:385

Indicator name, e.g. for a picker; the legend title starts with it by default.


placement ​

placement: "overlay" | "pane" | "either"

Defined in: packages/core/src/indicators/types.ts:406

overlay draws on the price pane; pane gets its own pane. either lets whoever adds it choose (the placement add option), and draws on the price pane by default.


plots ​

plots: PlotDef[]

Defined in: packages/core/src/indicators/types.ts:416


precision? ​

optional precision?: number

Defined in: packages/core/src/indicators/types.ts:432

Fixed value decimals; defaults to the main series' format on overlays, else 2.


priceScale? ​

optional priceScale?: string

Defined in: packages/core/src/indicators/types.ts:414

Price scale id the plots draw on, in the indicator's pane (default 'right', the main series' scale). 'left' shows a left axis while the indicator is visible; any other id is a scale of its own with no axis, e.g. for an overlay in other units than price. chart.indicators.add can override it per indicator.


refetchOn? ​

optional refetchOn?: IndicatorRefetchOn

Defined in: packages/core/src/indicators/types.ts:498

Which context changes drop the fetched rows and fetch again (default symbol and interval).


version? ​

optional version?: number

Defined in: packages/core/src/indicators/types.ts:378

Version of the inputs, a positive integer (default 1). Raise it when inputs are renamed or change meaning, and add migrate for older saved state.

Methods ​

compute() ​

compute(src, inputs, data, bars): IndicatorOutputs | Promise<IndicatorOutputs>

Defined in: packages/core/src/indicators/types.ts:441

Full compute over every bar. Return one array of src.length per plot id (NaN = no value). Extra arrays, also src.length long, are kept and may hold state for update. May return a promise, e.g. when the work runs in a Web Worker. data holds the fetched fields, aligned with the bars; bars holds the bars of the declared intervals (see alignSteps and formingSteps).

Parameters ​

src ​

BarArrays

inputs ​

I

data ​

IndicatorData

bars ​

IntervalBars

Returns ​

IndicatorOutputs | Promise<IndicatorOutputs>


fetch()? ​

optional fetch(request): Promise<IndicatorRow[]>

Defined in: packages/core/src/indicators/types.ts:484

Load rows for bars in [from, to). The chart calls it for the loaded range, again as older history pages in, for bars appended live when there is no subscribe, and after a refetch or a data reset; it aborts calls whose answer is no longer needed and ignores late answers. Rows outside the range are dropped; a later row with the same time wins.

Parameters ​

request ​

IndicatorFetchRequest<I>

Returns ​

Promise<IndicatorRow[]>


intervals()? ​

optional intervals(inputs): IndicatorInterval[]

Defined in: packages/core/src/indicators/types.ts:469

Other intervals whose bars compute and update read as bars[interval], e.g. [{ interval: '1d', lookback: 14 }] for an RSI on daily bars. The chart loads them for its symbol (or an entry's symbol) through its data source, caches them per symbol and interval, loads older ones as history pages in, and builds the newest higher bar of its own symbol from its own bars, so it updates live without refetching. While the chart interval is equal to or longer than one of them, the indicator draws nothing and says why in its pane. May be combined with fetch or subscribe: compute then gets both the rows and the bars.

Parameters ​

inputs ​

I

Returns ​

IndicatorInterval[]


lookback()? ​

optional lookback(inputs): number

Defined in: packages/core/src/indicators/types.ts:454

Bars needed before the first valid value, e.g. length - 1 for an SMA. The chart loads that much more history, so the warm-up stays off screen.

Parameters ​

inputs ​

I

Returns ​

number


migrate()? ​

optional migrate(inputs, fromVersion): Record<string, InputValue>

Defined in: packages/core/src/indicators/types.ts:383

Upgrade inputs saved at fromVersion (lower than version) to the current ones. The result is validated; values that still don't fit take their defaults.

Parameters ​

inputs ​

Record<string, InputValue>

fromVersion ​

number

Returns ​

Record<string, InputValue>


subscribe()? ​

optional subscribe(request, onRow): () => void

Defined in: packages/core/src/indicators/types.ts:491

Stream live rows. A row replaces the one with the same time or adds a new one. The chart re-subscribes when the symbol or interval changes, even when refetchOn keeps the rows, and calls the returned function to unsubscribe.

Parameters ​

request ​

IndicatorContext<I>

onRow ​

(row) => void

Returns ​

() => void


supports()? ​

optional supports(context): string | true

Defined in: packages/core/src/indicators/types.ts:503

Whether the indicator works in this context: true, or a reason shown in its pane instead of fetching (e.g. "Funding rates are for perpetuals only").

Parameters ​

context ​

IndicatorContext<I>

Returns ​

string | true


title()? ​

optional title(inputs): string

Defined in: packages/core/src/indicators/types.ts:400

Legend title built from the inputs, e.g. "RSI 14" for an RSI with guide levels. Defaults to name followed by every number and source input ("SMA 20 close").

Parameters ​

inputs ​

I

Returns ​

string


update()? ​

optional update(src, inputs, index, out, data, bars): void

Defined in: packages/core/src/indicators/types.ts:449

Optional incremental path for live data: write the values for bar index (always the last bar) into out, reading only out[...][< index]. Called repeatedly while the last bar forms, and when a live row lands in it. Without it every tick, appended bar and live row reruns compute over all bars.

Parameters ​

src ​

BarArrays

inputs ​

I

index ​

number

out ​

IndicatorOutputs

data ​

IndicatorData

bars ​

IntervalBars

Returns ​

void