Finding the max value in array

To add comments, please log in or register
iCurrency
31
iCurrency  

Hello, I want to find the max value from several variables that are symbols which change constantly:

 double NZDCADbid=MarketInfo("NZDCAD",MODE_BID); //0.89451

double EURGBPbid=MarketInfo("EURGBP",MODE_BID);//0.88951

So I have tried to replace numbers 4 & 9:

double num_array[2]={4,9};

   int    maxValueIdx=ArrayMaximum(num_array,WHOLE_ARRAY,0);



double num_array[2]={NZDCADbid,EURGBPbid}; 


But it did not work...!

Can somebody help?

Carl Schreiber
Moderator
7099
Carl Schreiber  

You can't define a an array with variables (NZDCADbid,EURGBPbid) or functions, or things like Bid,Ask only by constants.

You have to assign the values separately:

num_array[0] = NZDCADbid;
num_array[1] = EURGBPbid;

Please use the SRC button to post code!

iCurrency
31
iCurrency  

  

double NZDCADbid=0,88766
double EURGBPbid=0,89777 
double num_array[2];
   num_array[0] = NZDCADbid;
   num_array[1] = EURGBPbid;
 
  
   double maxValueIdx=
ArrayMaximum(num_array,WHOLE_ARRAY,0); 



   This is code. I would like to know is this code written correctly and is it going to give me maximum value between NZDCAD and EURGBP?



Carl Schreiber
Moderator
7099
Carl Schreiber  

Check it yourself by a script running in the debugger..

whroeder1
17942
whroeder1  
iCurrency: This is code.
  1. When you post code please use the SRC button! Please edit your post.
              General rules and best pratices of the Forum. - General - MQL5 programming forum

  2.    double maxValueIdx=
    ArrayMaximum(num_array,WHOLE_ARRAY,0);
    Perhaps you should read the manual. The function does not return a double.
              Array Functions / ArrayMaximum - Reference on algorithmic/automated trading language for MetaTrader 5
To add comments, please log in or register