Array

From MultiCharts
(Redirected from Arrays)
Jump to: navigation, search

Declares one or more names as arrays, containing multiple variable data elements; specifies the array structure, data elements type and initial value, update basis, and data number, for each of the arrays. Data elements type can be numerical, string, or true/false.

The number of elements in an array can be fixed or dynamic (unlimited).

In arrays with a fixed number of elements, the elements can be arranged in single or multiple dimensions. A one-dimensional 10-element array contains 10 elements, a two-dimensional 10-element by 10-element array contains 100 elements, a three-dimensional 10 by 10 by 10 element array contains 1000 elements, a four-dimensional 10 by 10 by 10 by 10 element array contains 10000 elements, etc. The maximum number of array dimensions in PowerLanguage is 9.

Each element in an array is referenced by one or more index numbers, one for each of the dimensions. Indexing starts at 0 for each of the dimensions.

Dynamic arrays (arrays with an unlimited number of elements) are one-dimensional, and are initialized at declaration as having only one element. Declared dynamic arrays can be resized using Array_SetMaxIndex.

Elements can be manipulated individually or as a group, in all or part of an array.

Usage

Array:<IntraBarPersist>ArrayName1
[D1,D2,D3,etc.]
(InitialValue1<,DataN>), 
<IntraBarPersist>ArrayName2
[D1,D2,D3,etc.]
(InitialValue2<,DataN>),etc.

Parameters inside the angled brackets are optional

Parameters

IntraBarPersist - an optional parameter; specifies that the value of the array elements is to be updated on every tick. If this parameter is not specified, the value will be updated at the close of each bar.
ArrayName - an expression specifying the array name. The name can consist of letters, underscore characters, numbers, and periods. The name cannot begin with a number or a period and is not case-sensitive.
D - a numerical expression specifying the array size in elements, starting at 0, for each of the dimensions; a single expression specifies a one-dimensional array, two expressions specify a two-dimensional (D1 by D2) array, three expressions specify a three-dimensional (D1 by D2 by D3) array, etc. A dynamic array, with an unlimited number of elements, is specified by the empty square brackets: [ & ] and will be a one-dimensional array.
InitialValue - an expression, specifying the initial value and defining the data type for all of the elements in the array. The value can be a numerical, string, or true/false expression; the type of the expression defines the data type.
DataN - an optional parameter; specifies the Data Number of the data series the array is to be tied to. If this parameter is not specified, the array will be tied to the default data series.

Notes

  • The reserved word Array is equivalent to the PowerLanguage reserved word Arrays.

Example

Declare Length and SFactor as 9-element one-dimensional numerical arrays with data elements' initial values of 0:

Array: Length[8](0),SFactor[8](0);

Declare Max_Price as a 24-element by 60-element two-dimensional numerical array, updated on every tick, tied to the series with Data #2, and with data elements' initial values equal to the value of Close function:

Array: IntraBarPersist Max_Price[23,59](Close, Data2);

Declare Highs2 as a dynamic numerical array with data elements' initial values of 0:

Array: Highs2[](0);