Download MetaTrader 5

I need to get the highest value of a buffer

To add comments, please log in or register
Neal_Van
334
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..

honest_knave
Moderator
2297
honest_knave  
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
Neal_Van
334
Neal_Van  
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?

honest_knave
Moderator
2297
honest_knave  
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.
Neal_Van
334
Neal_Van  
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..
Keith Watford
Moderator
10570
Keith Watford  
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.
Neal_Van
334
Neal_Van  
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.
Neal_Van
334
Neal_Van  
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.  
Keith Watford
Moderator
10570
Keith Watford  
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):
honest_knave
Moderator
2297
honest_knave  
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.

Neal_Van
334
Neal_Van  
thanks for helping me fellas.. I got it to work.. it was difficult for me but not too difficult..
To add comments, please log in or register