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[]
- ArrayBsearch()
- ArrayCopy()
- ArrayCopyRates()
- ArrayCopySeries()
- ArrayDimension()
- ArrayGetAsSeries()
- ArrayInitialize()
- ArrayIsSeries()
- ArrayMaximum()
- ArrayMinimum()
- ArrayRange()
- ArrayResize()
- ArraySetAsSeries()
- ArraySize()
- ArraySort()
ArrayRange()
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.
Parameters:
array[] - Array to check range_index - Dimension index.
Sample:
int dim_size; double num_array[10,10,10]; dim_size=ArrayRange(num_array, 1);
ArrayResize()
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.
Parameters:
array[] - Array to resize new_size - New size for the first dimension.
Sample:
double array1[][4]; int element_count=ArrayResize(array1, 20); // new size - 80 elements
ArraySetAsSeries()
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.
Parameters:
array[] - The numeric array to set set - Array indexing order.
Sample:
double macd_buffer[300]; double signal_buffer[300]; int i,limit=ArraySize(macd_buffer); ArraySetAsSeries(macd_buffer,true); for(i=0; i<limit; i++) macd_buffer[i]=iMA(NULL,0,12,0,MODE_EMA,PRICE_CLOSE,i)-iMA(NULL,0,26,0,MODE_EMA,PRICE_CLOSE,i); for(i=0; i<limit; i++) signal_buffer[i]=iMAOnArray(macd_buffer,limit,9,0,MODE_SMA,i);
ArraySize()
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).
Parameters:
array[] - Array of any type.
Sample:
int count=ArraySize(array1); for(int i=0; i<count; i++) { // some calculations. }
ArraySort()
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().
Parameters:
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.
Sample:
double num_array[5]={4,1,6,3,9}; // now array contains values 4,1,6,3,9 ArraySort(num_array); // now array is sorted 1,3,4,6,9 ArraySort(num_array,WHOLE_ARRAY,0,MODE_DESCEND); // now array is sorted 9,6,4,3,1This article url: http://www.myeatrade.com/433/