TIndexBuffer

A type that represents a buffer for storing indicator values. Index buffers are used to store and display series of values on the chart.

Description

The TIndexBuffer type is an array-like object that stores numerical values for an indicator. Each value in the buffer corresponds to a bar on the chart. Buffers can be used to:

  • Store calculated indicator values

  • Display lines, histograms, or other visual elements on the chart

  • Perform calculations that require historical values

Example Usage

// Create a new buffer
const buffer = this.api.CreateIndexBuffer();

// Assign the buffer to an index
this.api.SetIndexBuffer(0, buffer);

// Store values in the buffer
for (let i = 0; i < this.api.Bars(); i++) {
  buffer[i] = calculateValue(i);
}

// Access values from the buffer
const currentValue = buffer[0];
const previousValue = buffer[1];

// Use buffer values in calculations
const difference = buffer[0] - buffer[1];

Last updated