MathMax

 

Is there a shorter way to do this?

int a,b,c,d,e,f,g,h;

MathMax(MathMax(MathMax(a,b),MathMax(c,d)),MathMax(MathMax(e,f),MathMax(g,h)));

-Steve
 
ssn wrote >>

Is there a shorter way to do this?


-Steve


Why not array...? https://docs.mql4.com/array/ArrayMaximum
 
DDFedor wrote >>


Why not array...? https://docs.mql4.com/array/ArrayMaximum


Do arrays take variables?
 

if values of one type also are connected by sense, then - so

 
ssn wrote >>

Do arrays take variables?


Yes in the sense you can treat array elements as variables.

double myarray[8]={a,b,c,d,e,f,g,h};

double    myarrayMaxValue=myarray[ArrayMaximum(myarray)];

Print("Max value = ", myarrayMaxValue);
 
Note that u can't initialize an array with variables, it won't compile. It can only be initialized with constants.

You can do this:
double myarray[8];
myarray[0] = a;
myarray[1] = b;
// and so on...

Also, using defines helps for clarity:
#define A 0
#define B 1

//...

myarray[A] = a;
myarray[B] = b;
(this example is not the best since the variable names are meaningless by themselves, but the point is clear).
 
Have anyone ever encountered occasion where iHighest(.... WHOLE_ARRAY...) doesn't work? This post reminds me having this problem then resorting to MathMax().
 
cameofx:
Have anyone ever encountered occasion where iHighest(.... WHOLE_ARRAY...) doesn't work? This post reminds me having this problem then resorting to MathMax().

nevermind, I must've screwed up that time. I tested now it turned out fine...

   double Hi_est_1 = High[iHighest(NULL,0,MODE_HIGH,WHOLE_ARRAY,0)];
   double Hi_est_2 = High[iHighest(NULL,0,MODE_HIGH,Bars,0)];
   double Hi_est_3 = 0.0; 
   
   for(int i=Bars-1; i>=0; i--){
   Hi_est_3 = MathMax(High[i],MathMax(Hi_est_3,High[i+1]));
   }
   
   Alert("Hi_est_1 = ", Hi_est_1," Hi_est_2 = ", Hi_est_2," Hi_est_3 = ", Hi_est_3);
Reason: