All indicators provide the same set of base methods:
reset()
- clears indicator valuesupdate(value or candle)
- updates the current indicator value with a different data pointadd(value or candle)
- adds a new data point/value to the indicatorl()
- returns the number of available indicator valuesv()
- returns the current indicator valueprev(n = 1)
- returns the nth previous indicator value
All indicators have a seed period which should be respected before valid data can be obtained, which can be read via i.getSeedPeriod()
To query which type of data an indicator requires, getDataType()
and getDataKey()
are available. The data type can be either 'trade'
, 'candle'
, or '*'
to signal that both are acceptable. For candle data, the data key will be either 'open
', 'high'
, 'low'
, or 'close'
.
All indicators provide a set of meta values describing how they should be rendered on a chart. Specifically:
Indicator.args
- an array describing the indicator arguments, with objects of the form { label, default }Indicator.ui
- an object describing how to render the indicator, details belowIndicator.id
- the internal unique identifier for the indicatorIndicator.label
- the short, uppercase label for the indicatorIndicator.humanLabel
- the complete descriptive indicator label
As an example, here is the metadata for bollinger bands:
BollingerBands.id = 'bbands'
BollingerBands.label = 'BB'
BollingerBands.humanLabel = 'Bollinger Bands'
BollingerBands.ui = {
position: 'overlay',
type: 'bbands'
}
BollingerBands.args = [{
label: 'Period',
default: 20,
}, {
label: 'Multiplier',
default: 2,
}]
For each indicator, the Indicator.ui
field contains an object describing how it should render on a chart, with position
and type
keys. Two positions are possible, 'external'
to be shown below a chart and 'overlay'
to be shown on top of candle data. Supported types are 'line'
, 'lines'
, 'bbands'
, 'rsi'
, and 'macd'
, with indicators of type 'lines'
having an extra lines: [...]
field naming the indicator values that should be plotted.
For indicators with multiple values on each data point, such as Envelope, the lines
keys should correspond to the keys on the indicator data points:
Envelope.ui = {
position: 'overlay',
type: 'lines',
lines: ['upper', 'basis', 'lower']
}