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
title?stringnot reportedIndicator name reported to the host application (see Declared titles)
shortTitle?stringnot reportedCompact name for legends and pane labels (see Declared titles)

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.

Declared titles ​

title and shortTitle describe the script for the host application; they do not affect calculation.

Each title is reported to the host only when the script declares it, and the two are independent: an omitted shortTitle is never derived from title, nor the other way round. Declaring neither reports nothing, so the host can tell "not named" from any declared value — including an explicitly declared empty string — and apply its own naming.

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"});
}
javascript
// Name the indicator for the host application
indicator({title: "Relative Strength Index", shortTitle: "RSI", overlay: false});

function onTick() {
    spline(ta.rsi(close, 14), {title: "RSI"});
}