Finding the max value in array

 

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?

 

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!

 

  

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?



 

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

 
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
 
Hi can anyone help me out with this.
//In MQL4 we can simply do this

int maxIndex = ArrayMaximum(High,4,0); // Will return the index of highest values in the High array (default timeseries bar data in mql4)

How can we do this in MQL5 as there are no such arrays. Using MqlRates didn't helped either.

 
You can use iHighest()
 
Hafiz Tamur Ahmed: How can we do this in MQL5 as there are no such arrays. Using MqlRates didn't helped either.

There is no predefined array High[] so you get the values into an array.

Perhaps you should read the manual. CopyHigh
   How To Ask Questions The Smart Way. 2004
      How To Interpret Answers.
         RTFM and STFW: How To Tell You've Seriously Screwed Up.

 
Dominik Egert:
You can use iHighest()

Yes thanks. I tried this already before coming back to this post. It worked. Thanks BTW.

 
William Roeder:

There is no predefined array High[] so you get the values into an array.

Perhaps you should read the manual. CopyHigh
   How To Ask Questions The Smart Way. 2004
      How To Interpret Answers.
         RTFM and STFW: How To Tell You've Seriously Screwed Up.

Yeah I tried this too by copying the data but it wasn't so efficient. iHighest() worked perfectly. Thanks for help any how.

 
Hafiz Tamur Ahmed:v Yeah I tried this too by copying the data but it wasn't so efficient. iHighest() worked perfectly. Thanks for help any how.

You didn't ask how to find the highest. You asked for a replacement of High[]

Reason: