NavigationUser loginWho's new
Who's onlineThere are currently 1 user and 33 guests online.
Online users:
|
MQL4 Array FunctionsHi folks, We have talked about the Arrays in a previous article and we covered all the aspects of the Arrays in general and in MQL4 in particular. But MQL4 concerned more about the arrays and for that it built a set of functions handling the arrays. Today will talk about this set of build-in MQL4 functions one by one.
ArrayBsearch: Syntax: int ArrayBsearch( double array[], double value, int count=WHOLE_ARRAY, int start=0, int direction=MODE_ASCEND) Description: The ArrayBsearch function searches an array for the occurrence of a value. The function returns the index of the first occurrence of the value if the value is found in the array and returns the nearest one if the value is not found. The function searches only the first dimension of the array and cannot be used with the arrays of strings or serial numbers. Note: You have to sort the numeric arrays using ArraySort() function before performing binary search. Parameters: double value int count int start int direction Example: datetime daytimes[]; ArrayCopy: Syntax: int ArrayCopy( object& dest[], object source[], int start_dest=0, int start_source=0, int count=WHOLE_ARRAY) Description: The ArrayCopy function copies an array to another array. The source and destination arrays must be of the same type, but arrays with type double[], int[], datetime[], color[], and bool[] can be copied as arrays with same type. The function returns the number of the elements has been copied. Parameters: object source[] int start_dest int start_source int count Example double array1[][6]; ArrayCopyRates: Syntax: int ArrayCopyRates( double& dest_array[], string symbol=NULL, int timeframe=0) Description: The ArrayCopyRates function copies the rate from the chart RateInfo array to a two-dimensional array where the second dimension has these elements. 0 – time; Parameters: string symbol int timeframe Constant Value Description PERIOD_M1 1 1 minute. PERIOD_M5 5 5 minutes. PERIOD_M15 15 15 minutes. PERIOD_M30 30 30 minutes. PERIOD_H1 60 1 hour. PERIOD_H4 240 4 hour. PERIOD_D1 1440 Daily. PERIOD_W1 10080 Weekly. PERIOD_MN1 43200 Monthly. 0 (zero) 0 The current Time frame used on the chart. Use 0 if you want the current timeframe of the chart. Example: double array1[][6]; ArrayCopySeries: Syntax: int ArrayCopySeries( double& array[], int series_index, string symbol=NULL, int timeframe=0) Description: The ArrayCopyRates function copies a series array to another array. The function returns the number of the elements has been copied. Parameters: int series_index Constant Value Description MODE_OPEN 0 Open price. MODE_LOW 1 Low price. MODE_HIGH 2 High price. MODE_CLOSE 3 Close price. MODE_VOLUME 4 Volume, used in Lowest() and Highest() functions. MODE_TIME 5 Bar open time, used in ArrayCopySeries() function. Note: If the series_index is MODE_TIME, the first distension array must be a datetime array. string symbol int timeframe Example: datetime daytimes[]; Syntax: int ArrayDimension( int array[]) Description: The ArrayDimension function returns the dimensions count of the given array. Parameters: Example: int num_array[10][5]; ArrayGetAsSeries: Syntax: bool ArrayGetAsSeries( object array[]) Description: The ArrayGetAsSeries function checks the elements of given array and retruns true if the array is a series array (array elements indexed from last to first) and false otherwise. Parameters: Example: if(ArrayGetAsSeries(array1)==true) Syntax: int ArrayInitialize( double& array[], double value) Description: The ArrayInitialize function sets all the elements of the given numeric array to the same value. The function returns the count of the elements in the created array. Parameters: double value Example: //---- setting all elements of array to 2.1 ArrayIsSeries: Syntax: bool ArrayIsSeries( object array[]) Description: The ArrayIsSeries function checks the given array if it’s a series array (time, open, close, high, low, or volume) or not. The function returns true if the array is a series array and false otherwise. Parameters: Example: if(ArrayIsSeries(array1)==false) ArrayMaximum: Syntax: int ArrayMaximum( double array[], int count=WHOLE_ARRAY, int start=0) Description: The ArrayMaximum function searches the elements of the given array for the maximum value. The function returns the index of the maximum value Parameters: int count int start Example: double num_array[15]={4,1,6,3,9,4,1,6,3,9,4,1,6,3,9}; ArrayMinimum: Syntax: int ArrayMinimum ( double array[], int count=WHOLE_ARRAY, int start=0) Description: The ArrayMinimum function searches the elements of the given array for the minimum value. The function returns the index of the minimum value Parameters: int count int start Example: double num_array[15]={4,1,6,3,9,4,1,6,3,9,4,1,6,3,9}; ArrayRange: Syntax: int ArrayRange( object array[], int range_index) Description: The ArrayRange function returns the count of the elements of the given dimension of the given array. Note: Because the arrays in MQL4 are zero-based array, the size of the array is the largest index + 1. Parameters: object array[] int range_index Example: int dim_size; ArrayResize: Syntax: int ArrayResize( object& array[], int new_size) Description: The ArrayResize function sets a new size for the first dimension of the given array. The function returns the count of the elements of the resized array if it successfully resized the array and 0 otherwise. Parameters: Object& array[] int new_size Example: double array1[][4]; ArraySetAsSeries: Syntax: bool ArraySetAsSeries( double& array[], bool set) Description: The ArraySetAsSeries function reverses the index order of the given array to a series array. The function returns true in success and false otherwise. Parameters: bool set Example: double macd_buffer[300]; ArraySize: Syntax: int ArraySize( object array[]) Description: The ArraySize function returns the size of the given array. Parameters: Example: int count=ArraySize(array1); ArraySort: Syntax: int ArraySort( double& array[], int count=WHOLE_ARRAY, int start=0, int sort_dir=MODE_ASCEND) Description: The ArraySort function sorts the first dimension of the given numeric array. Note: Series arrays can't be sorted by this function. Parameters: int count int start int sort_dir Example: double num_array[5]={4,1,6,3,9}; I hope you enjoyed the article! Coders Guru |