Close

Returns the closing price for a specific bar.

Syntax

Close(shift: number): number

Parameters

  • shift: A number representing the shift from the current bar

Return Value

Returns a number representing the closing price of the specified bar.

Description

The Close method returns the closing price of a bar at the specified shift from the current bar. The shift parameter determines which bar's closing price to return:

  • 0: Current bar

  • 1: Previous bar

  • 2: Two bars ago

  • And so on

Example

// Get current bar's closing price
const currentClose = this.api.Close(0);

// Get previous bar's closing price
const previousClose = this.api.Close(1);

// Calculate price change
const priceChange = this.api.Close(0) - this.api.Close(1);
console.log(`Price changed by ${priceChange} points`);

// Get closing prices for last 3 bars
for (let i = 0; i < 3; i++) {
  const closePrice = this.api.Close(i);
  console.log(`Bar -${i} close price: ${closePrice}`);
}

Last updated