Interface IndicatorAttachContext

What an indicator's attach lifecycle can reach.

interface IndicatorAttachContext {
    signal?: AbortSignal;
    store: IndicatorStore;
    addPrimitive(p: IPrimitive): void;
    bars(): readonly Bar[];
    dataContext(): undefined | Readonly<ChartDataContext>;
    emit(event: string, payload: unknown): void;
    interval(): undefined | string;
    now(): number;
    paneIndex(): number;
    removePrimitive(p: IPrimitive): void;
    requestBars(request: IndicatorBarsRequest): Promise<readonly Bar[]>;
    requestRecompute(): void;
    requestSnapshot(
        request: IndicatorSnapshotRequest,
    ): Promise<RequestedBarsSnapshot>;
    requestState(): Readonly<IndicatorRequestState>;
    setDataRetry(retry: null | () => void): void;
    setDataStatus(status: IndicatorDataStatus): void;
    settings(): Readonly<IndicatorSettings>;
    subscribeDataChanges(
        listener: (change: IndicatorDataChange) => void,
    ): () => void;
    subscribeRequestChanges(listener: () => void): () => void;
    symbol(): undefined | string;
    timezone(): string;
}

Properties

signal?: AbortSignal

Instance lifetime. Aborted on removal, preserved across style changes.

Scratch this instance owns; the same object calc receives.

Methods

  • The bars the study computes on now: the chart's, or the underlying bars for a study set to them (IndicatorApi.setBarSource).

    Returns readonly Bar[]

  • Emit on the chart's own event bus, the one chart.on(name, cb) listens to.

    The declarative alerts slot covers a condition read off the bars; this is the imperative half, for an indicator whose signal arrives from outside the calculation entirely (a subscription its attach opened).

    Parameters

    • event: string
    • payload: unknown

    Returns void

  • Ask the host for another instrument's (or interval's) bars. Always present under chart.addIndicator; it rejects when the host has registered no provider (chart.setBarsProvider), so a study can treat the rejection as "unsupported here" and say so through setDataStatus.

    Parameters

    Returns Promise<readonly Bar[]>

  • Includes source revisions, provider changes and within-bar replay clock movement.

    Parameters

    • listener: () => void

    Returns () => void

  • The instrument the chart is showing, when the host knows it.

    Hosts can supply this through IndicatorHost or Chart's explicit data context. Without a configured identity it stays undefined. External studies read dataContext to include the exchange as well.

    Returns undefined | string