Skip to content
EliteChart

defineIndicatorPlugin

Documentation


Documentation / @elitechart/core / defineIndicatorPlugin

code
function defineIndicatorPlugin<Params, Output>(spec): IndicatorPlugin<Params, Output>;

Defined in: plugin/helpers.ts:31

Wrap a pure (bars, params) => output function as an IndicatorPlugin. Targets interfaceVersion: '1' automatically.

Type Parameters

Params

Params

Output

Output extends IndicatorOutput

Parameters

spec

compute

(bars, params) => Output

defaultParams

Params

id

string

inputs

readonly IndicatorInputSpec[]

name

string

pane

"price" | "separate"

Returns

IndicatorPlugin<Params, Output>

Example

code
import { defineIndicatorPlugin } from '@elitechart/core';
const sma20 = defineIndicatorPlugin({
  id: 'sma20', name: 'SMA 20', pane: 'price',
  inputs: [{ key: 'period', label: 'Period', type: 'number' }],
  defaultParams: { period: 20 },
  compute: (bars, { period }) => sma(bars, period),
});
chart.registerPlugin(sma20);