Skip to content

indicator()

Kind: func

Initializes the indicator context. Call once in the init section to configure how the indicator is displayed on the chart.

Calling indicator() is optional. When omitted, all settings use their default values.

Syntax

indicator(options?) → void

Arguments

NameTypeDescription
optionsobjectPartial configuration object (see Options)

Options

NameTypeDefaultDescription
overlay?booltrueWhen true, plots are drawn on the main price chart. When false, a separate pane is used
lookback?numberplatform defaultNumber of historical bars the indicator can access. Must be at least 1

Returns

void

Caveats

  • Must be called in the init section, not inside onTick().
  • Should be called at most once per script.
  • lookback must be at least 1; otherwise an error is thrown.

Example

javascript
// Overlay indicator — drawn on the main price chart
indicator({overlay: true});

const length = input.double("length", 20);

function onTick() {
    spline(ta.sma(close, length), {title: "SMA"});
}
javascript
// Separate pane indicator (default behavior)
indicator({overlay: false});

function onTick() {
    const rsi = ta.rsi(close, 14);
    spline(rsi, {title: "RSI"});
}
javascript
// Limit history access to 50 bars
indicator({lookback: 50});

function onTick() {
    spline(ta.sma(close, 50), {title: "SMA 50"});
}