GetBufferCount

Returns the number of values stored in a buffer.

Syntax

GetBufferCount(buffer: number): number

Parameters

  • buffer - A number representing the buffer index.

Return Value

Returns a number representing the count of values stored in the specified buffer.

Description

The GetBufferCount method returns the number of values that have been stored in a specific buffer. This can be useful for determining how many bars have valid indicator values.

Example

// Get the count of values in buffer 0
const count = this.api.GetBufferCount(0);

// Use the count to iterate through all values in the buffer
for (let i = 0; i < count; i++) {
  const value = this.someBuffer.getValue(i);
  // Process the value
}

// Check if there are enough values for calculations
if (this.api.GetBufferCount(0) >= period) {
  // Perform calculations that require at least 'period' values
}

Last updated