indicator.compute#
Legacy entry point for custom indicators.
SYNTAX#
function compute(candles: ChartCandle[], settings: object, data?: IndicatorDataChannels): RuntimeOutputARGUMENTS#
candles(ChartCandle[]) — Array of OHLCV candle objects sorted oldest-first. Each candle is{time, open, high, low, close, volume}withtimein unix seconds.settings(object) — User-configurable parameters. Keys match thekeyfield of each entry returned bygetSettings(); values are the user's current choices.data(IndicatorDataChannels | undefined) — Optional pre-aligned data channels for funding rate, open interest, liquidations, or order-book snapshot. Each field is undefined when the channel was not requested.
RETURNS#
RuntimeOutput — { name, pane, lines, fills?, histograms?, markerSeries?, candleSeries?, tables?, entities? }. The lines[i].values array length must equal candles.length; use NaN for warmup bars.
REMARKS#
Runs full-series on every call — there is no incremental tick mode for compute() indicators. For real-time efficiency on long histories, migrate to onBar(i, ctx) which the host can invoke in tick mode.
EXAMPLE#
// @indicator { name: "Simple MA", overlay: true }
function compute(candles, settings) {
var period = settings.period || 20;
var values = new Array(candles.length).fill(NaN);
var sum = 0;
for (var i = 0; i < candles.length; i++) {
sum += candles[i].close;
if (i >= period) sum -= candles[i - period].close;
if (i >= period - 1) values[i] = sum / period;
}
return { name: 'Simple MA', pane: 'overlay', lines: [{ name: 'SMA', values: values, color: '#00ff88' }] };
}