GetCurrentWindowIndex

Returns the index of the current chart window.

Syntax

GetCurrentWindowIndex(): number

Return Value

Returns a number:

  • 0 β€” MainChart (price chart)

  • 1 or higher β€” OscWin (indicator window; index corresponds to OscWins[returnValue - 1])

Description

The GetCurrentWindowIndex method returns the index of the window where the strategy is currently executing. Use this together with the window parameter of GetObjectName, GetObjectCount, RemoveAllObjects, and RemoveAllObjectsByPrefix to scope operations to the current window.

Example

// Check if running in MainChart or indicator window
const windowIndex = this.api.GetCurrentWindowIndex();
if (windowIndex === 0) {
  console.log("Running in MainChart");
} else {
  console.log(`Running in indicator window ${windowIndex}`);
}

// Count objects in current window only
const count = this.api.GetObjectCount(false, this.api.GetCurrentWindowIndex());

Last updated