Double top function

 

Hi all

I trying to code the condition of finding DT. I want to check previous 40 bars starting from 6th bar to find the one(H1) with max equals to previous d1 bar.
Then I want to check if neck of double bottom is over 20% of average daily range
if conditions are met return True.


Plz help

bool DT ()
{ 
  int i;
  double ATRd = iATR(Symbol(),1440,14,0);

     for (i=1; i<40;i++)
           {
          if(iHigh(NULL,PERIOD_D1,1)==iHighest(NULL,PERIOD_H1,MODE_HIGH,i,6))
              {  break;
                   
               if( iHigh(NULL,PERIOD_D1,1)- iLowest(NULL,PERIOD_H1,MODE_LOW,i,6)>0.2*ATRd)
               return(true);
               else return(false);
               }}
}
 

You have to be really lucky to get a DT with totally equal hights.

Better you define a range for the values.

 
  1. eddie: You have to be really lucky to get a DT with totally equal hights.
    They won't be exact, not even close, and even if they were you still have to handle: The == operand. - MQL4 forum

  2. if( iHigh(NULL,PERIOD_D1,1)- iLowest(NULL,PERIOD_H1,MODE_LOW,i,6)>0.2*ATRd)
    return(true);
    else return(false);
    is
    if(condition) return true;
    else          return false;
    same as
    if(condition) return condition;
    
    sam as
    return condition;
    Simplify your code.
    return iHigh(NULL,PERIOD_D1,1)- iLowest(NULL,PERIOD_H1,MODE_LOW,i,6)>0.2*ATRd;

  3.  iLowest does not return a price.What do you think 1.2345 - 5 means?
 
WHRoeder:
  1. eddie: You have to be really lucky to get a DT with totally equal hights.
    They won't be exact, not even close, and even if they were you still have to handle: The == operand. - MQL4 forum

  2. is
    same as
    sam as
    Simplify your code.

  3.  iLowest does not return a price.What do you think 1.2345 - 5 means?


Huge thanks, I have corrected the code according to ur suggestions. Now it seems that finally working :))

bool DT ()
{ 
  int i;
  double ATRd = iATR(Symbol(),1440,14,0);

     for (i=1; i<40;i++)
           {
          if(iHigh(NULL,PERIOD_D1,1)==  iHigh(Symbol(),PERIOD_H1,  NormalizeDouble(iHighest(NULL,PERIOD_H1,MODE_HIGH,i,6),0) )         )
              {                    
               return iHigh(NULL,PERIOD_D1,1)- iLow(Symbol(),PERIOD_H1,  NormalizeDouble(iLowest(NULL,PERIOD_H1,MODE_LOW,i,0),0) ) >  prAtrDTDB*ATRd;
              }}



// prAtrDTDB - extern var
 
Do NOT use NormalizeDouble, EVER. For ANY Reason. It's a kludge, don't use it. It's use is always wrong
Reason: