Array#

An array can be thought of as a container that stores multiple values of the same Type. Each value is called an element. From the first element to the last element, each is given an index in order, starting from 0 and incrementing.

Index012N-1
Array1st element2nd element3rd elementNth element

Arrays, like Variables, are divided into declaration and use phases.

Arrays are divided into static arrays (Static Array) and dynamic arrays (Dynamic Array):

Static ArrayDynamic Array
DeclarationSpecify dimensions, e.g., [8], [5, 6]Do not specify dimensions, e.g., []
SizeCannot be changed after declarationCan be changed via Array_SetMaxIndex
DimensionsCan be one-dimensional or multi-dimensionalCan only be one-dimensional
Initial SizeSpecified at declaration1 (index only has 0)

Declaration#

Declare the name, size, and dimensions of the array, and assign an initial value to all elements. The initial value determines the Type.

Syntax#

1
2
3
Array: [IntraBarPersist] ArrayName1[D1, D2, D3, ...](InitialValue1 [,DataN])
     , [IntraBarPersist] ArrayName2[D1, D2, D3, ...](InitialValue2 [,DataN])
     , ...;
Syntax ElementOptionalDescription
ArrayRequiredDeclares an array. Synonym: Arrays
IntraBarPersistOptionalRecalculates the element value on every tick (update by tick). By default, recalculates only at the end of each bar (update by bar)
ArrayNameRequiredThe name of the array. Can consist of letters, underscores, numbers, and periods (.). Not case-sensitive. Cannot start with a number or period (.)
DOptionalDimension, specifies the size of a static array. Index starts from 0. Specifying multiple dimensions (D1, D2, D3…) represents a multi-dimensional static array. If no dimension is specified, declares a dynamic array
InitialValueRequiredThe initial value of all elements. The initial value determines the Type, which can be Numerical, String, or TrueFalse
DataNOptionalSpecifies the Data the array is bound to. By default, binds to the default Data

Use#

Use ArrayName[I1, I2, I3] to specify which element of the array to use.

1
ArrayName[I1, I2, I3];
Syntax ElementDescription
ArrayNameThe name of the array
IIndex. I1 is the first dimension index, I2 is the second dimension index, I3 is the third dimension index, and so on

Example#

One-Dimensional Static Array#

Declare Factor as a static array with a size of 9 (index 0~8) and an initial value of 0. Use a for loop to set each element’s value to its index.

1
2
3
4
5
6
Array: Factor[8](0);
Variables: index(0);

For index = 0 To 8 Begin
  Factor[index] = index;
End;

Two-Dimensional Static Array#

Declare Level as a two-dimensional static array with a size of 6×7 (index 0~5 × 0~6) and an initial value of 0. Use a for loop to set each element’s value to the sum of its two dimension indices.

1
2
3
4
5
6
7
8
Array: Level[5, 6](0);
Variables: d1_index(0), d2_index(0);

For d1_index = 0 To 5 Begin
  For d2_index = 0 To 6 Begin
    Level[d1_index, d2_index] = d1_index + d2_index;
  End;
End;

Dynamic Array#

Declare Alpha as a dynamic array with an initial value of 0 (initial size is 1). Use Array_SetMaxIndex to change the size to 9 (index 0~8), then use a for loop to set each element’s value to its index.

1
2
3
4
5
6
7
8
Array: Alpha[](0);
Variables: index(0);

Array_SetMaxIndex(Alpha, 8);

For index = 0 To 8 Begin
  Alpha[index] = index;
End;

Common Error: Array Bounds. Wrong Index Value#

When the index used does not exist in the array, the error Array bounds. Wrong index value: x is generated, where x is the index value where the error occurred.

Example: Index Out of Range#

Declare Factor as a static array with a size of 9 (index 0~8). Use a for loop to access indices 0 to 10. When execution reaches index 9, it exceeds the range (0~8), generating Array bounds. Wrong index value: 9.

1
2
3
4
5
6
Array: Factor[8](0);
Variables: index(0);

For index = 0 To 10 Begin
  Factor[index] = index;
End;

Example: Dynamic Array Size Not Set#

Declare Alpha as a dynamic array with an initial value of 0 (initial size is 1, index only has 0). Without using Array_SetMaxIndex to set the size, when the for loop executes to index 1, it exceeds the range (0), generating Array bounds. Wrong index value: 1.

1
2
3
4
5
6
7
Array: Alpha[](0);
Variables: index(0);

// Did not use Array_SetMaxIndex to set the dynamic array size
For index = 0 To 8 Begin
  Alpha[index] = index;
End;

Reference#

https://www.multicharts.com/trading-software/index.php?title=Array

https://www.multicharts.com/trading-software/index.php?title=Array_SetMaxIndex

© 2026 CodeReindeer. All rights reserved.