highest(or lowest) value of a indicator

 

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

 
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?
 
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.
 
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
 
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.
 
I think I must be missing something. I'm still stuck.
 
Show complete code.
 
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.
 
William Roeder #:
Get each value, find the highest.Is that so hard?

Hi William,


I was trying to extract the highest value in the ATR indicator within 200 bars in MQL4. 


I tried to add this but what are you changing in the custom indicators to find the highest value?

 double FirstHigh(int i=ATR(), int i>200)
{
   double hh1 = iCustom(_Symbol,Period, "hh1",14, iFrom); --iFrom;
   while(iFrom >= iTo)
{
     double val1 = iCustom(_Symbol,Period, "hh1",5, iFrom); --iFrom;
     if(hh < val) hh1 = val1;
   }
   return hh1;

    double SecondHigh(int i=ATR(), int i>200)
{
   double hh2 = iCustom(_Symbol,Period, "hh2",14, iFrom); --iFrom;
   while(iFrom >= iTo)
{
     double val2 = iCustom(_Symbol,Period, "hh2",5, iFrom); --iFrom;
     if(hh2 < val2) hh2 = val;
   }
   return hh2;


   double ATR = ((FirstHigh+SecondHigh)/2);
 
Sanjay Rathore #: I was trying to extract the highest value in the ATR indicator within 200 bars in MQL4.
  1. double FirstHigh(int i=ATR(), int i>200)

    i=ATR() is meaningless. int i>200 is nonsense. Do not post code that will not even compile.

  2. Your two functions do not have a closing bracket after the return. Do not post code that will not even compile.

  3. Perhaps you should read the manual. You get the ATR using iATR - Technical Indicators - MQL4 Reference, not some indicator called “hh1.”
       How To Ask Questions The Smart Way. (2004)
          How To Interpret Answers.
             RTFM and STFW: How To Tell You've Seriously Screwed Up.

  4. double ATR = ((FirstHigh+SecondHigh)/2);
    First/SecondHigh are functions. You don't call functions like that.

    MT4: Learn to code it.
    MT5: Begin learning to code it.

    If you don't learn MQL4/5, there is no common language for us to communicate. If we tell you what you need, you can't code it. If we give you the code, you don't know how to integrate it into your code.

  5. Or pay (Freelance) someone to code it. Top of every page is the link Freelance.
              Hiring to write script - General - MQL5 programming forum (2019)