MathMax from several numbers

 

Hello Folks,


I would like to know how I can get the maximum value of let's say five values.

MathMax only allows two values. From another post here I've found this code to do three numbers: MathMax(MathMax(A,B),C)

But how do I do more than three?


Thanks.

WorstCases

 

You can either continue ot iterate the MathMax sequence:

   Double MaxValue=MathMax(MathMax(MathMax(MathMax(A,B),C),D),E);

Or you could store the values in an array:

   double MyArray[5];
   MyArray[0]=A;
   MyArray[1]=B;
   MyArray[2]=C;
   MyArray[3]=D;
   MyArray[4]=E;
   double MaxValue=ArrayMaximum(MyArray);
 
Thank you very much!
 
double MyArray[5];
   MyArray[0]=A;
   MyArray[1]=B;
   MyArray[2]=C;
   MyArray[3]=D;
   MyArray[4]=E;
   double MaxValue=ArrayMaximum(MyArray);
I just tried this code, but if I'm not totally wrong ArrayMaximum will tell me which Array has the highest number, but won't give me the number itself. How do I approach to get the number value itself?
 
WorstCases:
I just tried this code, but if I'm not totally wrong ArrayMaximum will tell me which Array has the highest number, but won't give me the number itself. How do I approach to get the number value itself?
double MaxValue=MyArray[ArrayMaximum(MyArray)];
 
WorstCases:
I just tried this code, but if I'm not totally wrong ArrayMaximum will tell me which Array has the highest number, but won't give me the number itself. How do I approach to get the number value itself?

Why are u guessing what it does? The first thing u should do is read the documentation for the specific function, in this case see here -> https://docs.mql4.com/array/ArrayMaximum. It even has an example that answers your question!

 

Sorry - Dumb question.

Could do it myself.

Print ("MaxValue: ", MyArray[MaxValue]);