How to compare differents values

 

Hello,

I want to compare differentes values and to keep the highest or the lowest in an ea.

How I can code that. Is there a fonction to compare the value of variables?

Thank you

 
A really good place to start learning about MT4 programming is the book
 

Start reading about if statements and Operators

if (apples > oranges) // if apples is greater than oranges
   eatFruit()         // run some function

This form is a great place to learn and develop your programming skills. Welcome.

 

Thank you.


I know for 2 values, but I want to compare the values of a list 8,10,...values, and to keep the highest.

 
crystal7:

Thank you.


I know for 2 values, but I want to compare the values of a list 8,10,...values, and to keep the highest.


Different ways you can use a while function to compare High[x+10] <==> High[x]

Do an attempt to compare the high of last 10 bars and keep the highest....

 

Off the top of my head.... Not tested and will not compile. But those are some options. Or something like that.

double highest_value( double value_Ray[] ){

arraysort( double value_Ray[] ); //sort in highest first

return( value_Ray[0] );

}


double highest_value( double value_Ray[] ){ double highest_value;

for(int i=arraysize( value_Ray )-1; i>=0; i--){

if( value_Ray[i]>highest_value || highest_value==0 ){ highest_value= value_Ray[i] ;}

}

return( highest_value );

}

If you don't have the values in arrays then ... you could

if( value1>=value2 && value1>=value3 ){double highest=value1;}else

if( value2>=value1 && value2>=value3 ){ highest=value2;}else

if( value3>=value1 && value3>=value2 ){ highest=value3;}else

etc........ but very crude indeed.

 
ubzen:

Off the top of my head.... Not tested and will not compile. But those are some options. Or something like that.

double highest_value( double value_Ray[] ){

arraysort( double value_Ray[] ); //sort in highest first

return( value_Ray[0] );

}


double highest_value( double value_Ray[] ){ double highest_value;

for(int i=arraysize( value_Ray )-1; i>=0; i--){

if( value_Ray[i]>highest_value || highest_value==0 ){ highest_value= value_Ray[i] ;}

}

return( highest_value );

}

If you don't have the values in arrays then ... you could

if( value1>=value2 && value1>=value3 ){double highest=value1;}else

if( value2>=value1 && value2>=value3 ){ highest=value2;}else

if( value3>=value1 && value3>=value2 ){ highest=value3;}else

etc........ but very crude indeed.


Do you see this crystal7 3 different ways given by ubzen to compare values ....
 

Thank you


I'm not familiar with array, but I will learn and test that.

If i have some problems I come back to you.

 

how is ArrayMaximum() sounds

 
qjol:

how is ArrayMaximum() sounds

Nice function. Learn something new every-day. :)
 
ubzen:
Nice function. Learn something new every-day. :)

That's also what I do Thank you qjol