Interface IndicatorCalcContext

The fourth, optional argument to calc (and the sixth to calcTail): what the calculation cannot read off the bars themselves.

It is optional so that every descriptor written against calc(bars, settings, store) keeps its exact signature and its exact behaviour, which is the whole point: a calculation that ignores the context computes what it always did.

interface IndicatorCalcContext {
    barState: {
        isConfirmed: boolean;
        isNew: boolean;
        isRealtime: boolean;
        lastIndex: number;
    };
    interval?: string;
    symbol?: string;
    tickSize?: number;
    timezone: string;
    now(): number;
}

Properties

barState: {
    isConfirmed: boolean;
    isNew: boolean;
    isRealtime: boolean;
    lastIndex: number;
}

Where the last bar stands, so a study can act once per bar rather than once per tick, or refuse to signal off a bar that is still moving.

Type declaration

  • isConfirmed: boolean

    The last bar has closed: its interval has elapsed on the chart clock.

  • isNew: boolean

    The most recent update appended a bar rather than replacing one.

  • isRealtime: boolean

    A live feed is driving updates, rather than a one-off history load.

  • lastIndex: number

    Index of the last bar, bars.length - 1 (-1 when there are none).

interval?: string

The timeframe ('5m', '1d'), on the same terms as symbol.

symbol?: string

The instrument, when the host knows one. See IndicatorAttachContext.

tickSize?: number

The instrument's tick size, from the price pane's minMove.

The price pane and not the indicator's own, because calc runs on the instrument's bars whichever pane the plot lands in, and a study pane is not quoted in the instrument's tick: an RSI is a dimensionless 0..100 band, so its scale carries no tick at all to read.

undefined when the host has not told the chart what it is, which is the honest answer rather than a guessed 0.01: an indicator sizing a range in ticks has to tell "one paisa" apart from "nobody said".

timezone: string

The chart's IANA zone, the calendar its axis is labelled in.

Methods