Download MetaTrader 5
To add comments, please log in or register
Share your programs. That will improve your rating.
Jesse Phipps
802
Jesse Phipps 2014.06.24 20:46 

How can I return the highest(or lowest) value of a indicator over a set period in a EA?

So for instance If I want my EA to trade when indicator one reaches a high of 10 or more and within 5 bars from that indicator two also reaches a high of 10 or more. So it would trade when two indicators made new highs within 5 bars of each other.

I've been stuck a few days so examples would be greatly appreciated.


-Thank you

whroeder1
13596
whroeder1 2014.06.24 22:55  
atxjess: How can I return the highest(or lowest) value of a indicator over a set period in a EA?
Get each value, find the highest.
double highestInd(int iFrom, int iTo=0){
   double hh = iCustom( ... iFrom); --iFrom;
   while(iFrom >= iTo){
     double val = iCustom( ... iFrom); --iFrom;
     if(hh < val) hh = val;
   }
   return hh;
}
Is that so hard?
Jesse Phipps
802
Jesse Phipps 2014.06.25 04:14  
WHRoeder:
atxjess: How can I return the highest(or lowest) value of a indicator over a set period in a EA?
Get each value, find the highest.Is that so hard?

I get this error when I try this code "'highestInd' - function can be declared only in the global scope". I need it to be local so say If both indicators high is greater than 10 within 5 bars of each other. It would buy.
sokramm
49
sokramm 2014.06.25 05:17  
atxjess:

I get this error when I try this code "'highestInd' - function can be declared only in the global scope".

I think you need to review the beginning of https://book.mql4.com/basics/functions
Jesse Phipps
802
Jesse Phipps 2014.06.25 19:18  
sokramm:

I think you need to review the beginning of https://book.mql4.com/basics/functions

I understand functions, this code can only be declared on a global scope meaning on initialization. So the values would set when I load the EA but never update. I need it to check if the parameters are met on every bar.
Jesse Phipps
802
Jesse Phipps 2014.06.26 02:48  
I think I must be missing something. I'm still stuck.
Drazen Penic
2403
Drazen Penic 2014.06.26 09:48  
Show complete code.
whroeder1
13596
whroeder1 2014.06.26 11:49  
atxjess: I think I must be missing something. I'm still stuck.
  1. Put the function definition (highestInd) outside of existing code and call it inside your function.
  2. Show your code, there are no mind readers here.
/
To add comments, please log in or register