CreateIndexBuffer

Creates a new buffer for storing indicator values.

Important: This method should only be used inside the Init() method during indicator initialization.

Syntax

CreateIndexBuffer(): TIndexBuffer

Parameters

This method does not take any parameters.

Return Value

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

Description

The CreateIndexBuffer method creates a new buffer for storing indicator values. Buffers are essential for displaying data on charts and must be properly declared, created, and configured during indicator setup.

Buffer Management Rules:

  • Declare all buffers as class-level fields using the ! syntax

  • Create buffers in Init() using CreateIndexBuffer()

  • Register buffer count with IndicatorBuffers()

  • Assign buffers to indexes with SetIndexBuffer()

  • Configure buffer appearance with SetIndexStyle()

See TIndexBuffer for more information about working with indicator buffers.

Proper Buffer Declaration

All buffers must be declared as class-level fields with the non-null assertion operator (!):

Complete Buffer Setup Workflow

Step 1: Declare Buffers (Class Level)

Step 2: Create and Configure in Init()

Step 3: Use Buffers in Calculate()

Buffer Creation Rules

βœ… Must Be Done in Init()

  • Create all buffers with CreateIndexBuffer()

  • Register buffer count with IndicatorBuffers()

  • Assign buffers to indexes with SetIndexBuffer()

  • Configure initial styles with SetIndexStyle()

❌ Cannot Be Done Outside Init()

  • Creating new buffers in Calculate() or other methods

  • Changing buffer count after initialization

  • Reassigning buffer indexes during runtime

Complete Example

Key Rules Summary

  1. Declare buffers as class-level fields with ! syntax

  2. Create buffers only in Init() using CreateIndexBuffer()

  3. Assign buffers to indexes with SetIndexBuffer()

  4. Configure appearance with SetIndexStyle()

  5. Use buffers in Calculate() for data storage and retrieval

  6. Never create buffers outside Init() - this will cause errors

Last updated