MQL4 Reference

MQL4 Array functions (3)

A group of functions to work with arrays.

Arrays are allowed to be maximum four-dimensional. Each dimension is indexed from 0 to dimension size-1. In a particular case of a one-dimensional array of 50 elements, calling of the first element will appear as array[0], of the last one – as array[49].

Using these functions (except for those which change quantitative and qualitative characteristics of the array) one can process predefined time series Time[], Open[], High[], Low[], Close[], Volume[]



int ArrayDimension(object array[], int range_index)

Returns the count of elements in the given dimension of the array. Since indexes are zero-based, the size of dimension is 1 greater than the largest index.


array[]     - Array to check 
range_index - Dimension index. 


int    dim_size;
double num_array[10,10,10];
dim_size=ArrayRange(num_array, 1);


int ArrayResize(object &array[], int new_size)

Sets a new size for the first dimension. If executed successfully, it returns count of all elements contained in the array after resizing, otherwise, returns -1, and array is not resized.

Note: Array declared at a local level in a function and resized will remain unchanged after the function has completed its operation. After the function has been recalled, such array will have a size differing from the declared one.


array[]  - Array to resize
new_size - New size for the first dimension. 


double array1[][4];
int    element_count=ArrayResize(array1, 20);
// new size - 80 elements


bool ArraySetAsSeries(double &array[], bool set)

Sets indexing direction of the array. If the set parameter has the TRUE value, the array will be indexed in a reversed order, i.e., the last element has a zero index. The FALSE value sets a standard indexing order. The function returns the previous status.


array[] - The numeric array to set
set     - Array indexing order. 


double macd_buffer[300];
double signal_buffer[300];
int    i,limit=ArraySize(macd_buffer);
for(i=0; i<limit; i++)
for(i=0; i<limit; i++)


int ArraySize(object array[])

Returns the count of elements contained in the array. For a one-dimensional array, the value to be returned by the ArraySize function is equal to that of ArrayRange(array,0).


array[]  - Array of any type. 


int count=ArraySize(array1);
for(int i=0; i<count; i++)
   // some calculations.


int ArraySort(double &array[], int count=WHOLE_ARRAY, 
              int start=0, int sort_dir=MODE_ASCEND)

Sorts numeric arrays by first dimension. Series arrays cannot be sorted by ArraySort().


array[]  - The numeric array to be sorted. 
count    - Count of elements to be sorted. 
start    - Starting index. 
sort_dir - Array sorting direction. It can be any of the following values:
           MODE_ASCEND  - sort ascending,
           MODE_DESCEND - sort descending. 


double num_array[5]={4,1,6,3,9};
  // now array contains values 4,1,6,3,9
  // now array is sorted 1,3,4,6,9
  // now array is sorted 9,6,4,3,1
This article url:

Please login to post comment, if you haven't account you can register free