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
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?
optionalaliases?:string[]
Defined in: packages/core/src/indicators/types.ts:395
Other names search matches, e.g. ['Bollinger Bands'] for "BB".
autoscaleRule?
optionalautoscaleRule?: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?
optionalcategory?: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?
optionalchunkBars?: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?
optionaldescription?:string
Defined in: packages/core/src/indicators/types.ts:387
One-sentence description shown in an indicator picker.
fields?
optionalfields?: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?
optionalfills?:FillDef[]
Defined in: packages/core/src/indicators/types.ts:417
fixedRange?
optionalfixedRange?: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?
optionalprecision?:number
Defined in: packages/core/src/indicators/types.ts:432
Fixed value decimals; defaults to the main series' format on overlays, else 2.
priceScale?
optionalpriceScale?: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?
optionalrefetchOn?: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?
optionalversion?: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
inputs
I
data
bars
Returns
IndicatorOutputs | Promise<IndicatorOutputs>
fetch()?
optionalfetch(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
Returns
Promise<IndicatorRow[]>
intervals()?
optionalintervals(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
lookback()?
optionallookback(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()?
optionalmigrate(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()?
optionalsubscribe(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
onRow
(row) => void
Returns
() => void
supports()?
optionalsupports(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
Returns
string | true
title()?
optionaltitle(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()?
optionalupdate(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
inputs
I
index
number
out
data
bars
Returns
void