CreateIndexBufferWithArgs

Creates a new buffer with specified display properties.

Syntax

CreateIndexBufferWithArgs(
    index: number,
    aLabel: string,
    drawStyle: TDrawStyle,
    style: TPenStyle,
    width: number,
    color: string
): TIndexBuffer

Parameters

  • index - A number representing the buffer index.

  • aLabel - A string containing the label for the buffer.

  • drawStyle - A value from the TDrawStyle enum specifying how to draw the buffer.

  • style - A value from the TPenStyle enum specifying the line style.

  • width - A number representing the line width in pixels.

  • color - A string hex color value for the buffer.

Return Value

Returns a TIndexBuffer object that can be used to store indicator values.

Description

The CreateIndexBufferWithArgs method creates a new buffer with specified display properties and assigns it to the given index. This is a convenient way to create and configure a buffer in a single call.

Example

// Create a buffer for a moving average with display properties
const maBuffer = this.api.CreateIndexBufferWithArgs(
  0, // Index
  "Moving Average", // Label
  TDrawStyle.LINE, // Draw as a line
  TPenStyle.SOLID, // Solid line
  2, // Width of 2 pixels
  "#0000ff" // Blue color
);

// Calculate and store values in the buffer
for (let i = period; i < this.api.Bars(); i++) {
  maBuffer[i] = calculateMA(i, period);
}

Last updated