I need to get the highest value of a buffer

 

I have a few questions...

Do I have to use a cycle to get access the past bars or is the function ArrayMaximum all that is needed?

Also if someone could provide an example it would be appreciated..

 
Neal_Van:

I have a few questions...

Do I have to use a cycle to get access the past bars or is the function ArrayMaximum all that is needed?

Also if someone could provide an example it would be appreciated..

ArrayMaximum will work. Just remember it returns the index with the highest value, not the actual value.

Examples in the documentation (easier to follow in the MT4 documentation): 

MT4

MT5

ArrayMaximum - Array Functions - MQL4 Reference
ArrayMaximum - Array Functions - MQL4 Reference
  • docs.mql4.com
ArrayMaximum - Array Functions - MQL4 Reference
 
honest_knave:

ArrayMaximum will work. Just remember it returns the index with the highest value, not the actual value.

Examples in the documentation (easier to follow in the MT4 documentation): 

MT4

MT5

the example provides a set array with constant values called num_array:

void OnStart()
  {
//---
   double num_array[15]={4,1,6,3,19,4,2,6,3,9,4,5,6,3,9};
   int    maxValueIdx=ArrayMaximum(num_array,WHOLE_ARRAY,0);
   Print("Max value = ",num_array[maxValueIdx]," at index=",maxValueIdx);

  }

I've tried replacing num_array with my buffer and there was no result. 

What could I be doing wrong?

 
Neal_Van:

the example provides a set array with constant values called num_array:

void OnStart()
  {
//---
   double num_array[15]={4,1,6,3,19,4,2,6,3,9,4,5,6,3,9};
   int    maxValueIdx=ArrayMaximum(num_array,WHOLE_ARRAY,0);
   Print("Max value = ",num_array[maxValueIdx]," at index=",maxValueIdx);

  }

I've tried replacing that with my buffer and there was no result. 

What could I be doing wrong?

You'll need to post up your code.
 
honest_knave:
You'll need to post up your code.

That is the section of code I'm having trouble with.. I don't post my entire code it is not for the world..
 
Neal_Van:

the example provides a set array with constant values called num_array:

void OnStart()
  {
//---
   double num_array[15]={4,1,6,3,19,4,2,6,3,9,4,5,6,3,9};
   int    maxValueIdx=ArrayMaximum(num_array,WHOLE_ARRAY,0);
   Print("Max value = ",num_array[maxValueIdx]," at index=",maxValueIdx);

  }

I've tried replacing num_array with my buffer and there was no result. 

What could I be doing wrong?

Please use the SRC button when posting code. I have done it for you this time.

What do you mean that there was no result. The print must have printed something or the code is not being executed.
 
Keith Watford:
Please use the SRC button when posting code. I have done it for you this time.

What do you mean that there was no result. The print must have printed something or the code is not being executed.
oh my apologizes.. I thought I did click source.. I must have pasted it wrong.
 
Keith Watford:
Please use the SRC button when posting code. I have done it for you this time.

What do you mean that there was no result. The print must have printed something or the code is not being executed.
there was a whole value for the result but the indicator buffer value is never higher than a decimal value.. usually the level is .10 to .25 but the result of this code was in the hundreds and it is incorrect.  
 
I refer you to what Honest Knave has already told you.


honest_knave:

 ArrayMaximum will work. Just remember it returns the index with the highest value, not the actual value. Examples in the documentation (easier to follow in the MT4 documentation):
 
Neal_Van:
That is the section of code I'm having trouble with.. I don't post my entire code it is not for the world..

Also, if you expect help you need to post at least some of your code i.e. the section you are having trouble with.

Posting up the example from the help files is no use - the example code works so there must be a problem with your implementation.

 
thanks for helping me fellas.. I got it to work.. it was difficult for me but not too difficult..
Reason: