Simple script illustrating getting the maximum value in an array. Code identical for MQL4 and MQL5.
void OnStart(){
double testarray[5] = {0.1, 0.2, 15, 1.5, 0.01}; //sample array with 5 elements
Print(maxValueOfArray(testarray));
}
double maxValueOfArray(double &arrayToSearch[]){ //function data type should be the same as the data type we are expecting to return
int indexMaxValueOfArray = ArrayMaximum(arrayToSearch, 0, WHOLE_ARRAY); //ArrayMaximum returns the index of the maximum value and not the maximum value of itself
return(arrayToSearch[indexMaxValueOfArray]); //return the value at the index determined to hold the maximum value, as obtained by ArrayMaximum()
}
MT4 output:

MT5 output:

Discussion
No comments yet.