Mql5 ( price zone and tests)

 
int intervalPredicate(double close, double open, double high, double low)
{  

   double value = interval_percentage/100.0;
   double difference = NormalizeDouble((high-low), 10);
   double threshold = NormalizeDouble(difference*value, 10);
   double low_upper = low+threshold;
   double high_lower = high-threshold;
   //Print("value :" +value +  " difference " + difference + "High: " + high + " Low: " + low + " open: " + open + " close: " + close + " low upper: " + low_upper + " high lower" + high_lower );
   if (close <= low_upper && open <= low_upper){
   
      return 1;
   
   }
   
   else if (close >=high_lower && open >= high_lower) {
   
   
      return 2;
   }
      
   else {
   
      return 0;
   
   }
   
}




double extreme_point (int intervalPredicate, double &higharray[], double &lowarray[]){

   if (intervalPredicate == 1) {
   
       double temp_max = 0.000001;
       for (int i = 2; i<200; i++){
        
         if (higharray[i] > temp_max){
        
            temp_max = higharray[i];
            
         } 
       }
       
       return temp_max;
       
             
    } 
                  
     if (intervalPredicate == 2) {
   
       double temp_min = 100000000;
       for (int i = 2; i<200; i++){
        
         if (lowarray[i] < temp_min){
        
            temp_min = lowarray[i];
            
         } 
       }
       
       return temp_min;     
        
     } 
     
         
     return 0;
   
}

bool setup_bar_test (double high, double low,int intervalPredicate , double extreme_point )

{

   if (intervalPredicate == 1) {
   
      if ((high > extreme_point) && (low < extreme_point)){
      
         return true;
      
      }
      
      
      }
      
      if (intervalPredicate == 2){
      
       if ((low < extreme_point) && (high > extreme_point)){
       
       return true;
       }
     
      
      }
      
    return false;
      
 }



void local_extreme(double &high[], double &low[],double atr, double extreme_point,int intervalPredicate,double &high1array[][], double &low1array[][] ) {

  
 double extreme_point_upper_border = 0;
 double extreme_point_lower_border = 0;
  
   if (intervalPredicate == 1) {
   
      extreme_point_upper_border = extreme_point - extreme_zone_multiplier * atr;
   
   }
   
   else if (intervalPredicate == 2) {
   
      extreme_point_lower_border = extreme_point + extreme_zone_multiplier * atr;
   
   }
   
   
   
   int high_extreme_counter = 0;
   int low_extreme_counter = 0;
   
   for (int i = 7; i<200; i++){
   
      if( intervalPredicate == 1 &&
         high[0] > high[i]    &&
         high[i] >= extreme_point_upper_border &&
         high[i] >= high[i+5] &&
         high[i] >= high[i+4] &&
         high[i] >= high[i+3] &&
         high[i] >= high[i+2] &&
         high[i] >= high[i+1] &&
         high[i] >= high[i-5] &&
         high[i] >= high[i-4] &&
         high[i] >= high[i-3] &&
         high[i] >= high[i-2] &&
         high[i] >= high[i-1]){
   
            high1array[high_extreme_counter][0] = i;
            high1array[high_extreme_counter][1] = high[i]; 
   
            high_extreme_counter++;
      }
      
      else if(intervalPredicate == 2 &&
         
         low[0] < low[i]    &&
         low[i] <= extreme_point_lower_border &&
         low[i] <= low[i+5]&&  
         low[i] <= low[i+4]&&  
         low[i] <= low[i+3]&&  
         low[i] <= low[i+2]&&  
         low[i] <= low[i+1]&&  
         low[i] <= low[i-5]&&  
         low[i] <= low[i-4]&&  
         low[i] <= low[i-3]&&  
         low[i] <= low[i-2]&&  
         low[i] <= low[i-1] ){

            
            low1array[low_extreme_counter][0] = i;
            low1array[low_extreme_counter][1] = low[i];
            
            low_extreme_counter++;
      
      }
   
   }
      
   

}

int extreme_point_test_bullish (double &high[], double atr, double extreme_point){

    
  
   double extreme_point_upper_border = 0;
   
   extreme_point_upper_border = extreme_point - extreme_zone_multiplier * atr;
   
     
   int high_extreme_counter = 0;
  
   
   for (int i = 7; i<200; i++){
   
      if(
         high[0] > high[i]    &&
         high[i] >= extreme_point_upper_border &&
         high[i] >= high[i+5] &&
         high[i] >= high[i+4] &&
         high[i] >= high[i+3] &&
         high[i] >= high[i+2] &&
         high[i] >= high[i+1] &&
         high[i] >= high[i-5] &&
         high[i] >= high[i-4] &&
         high[i] >= high[i-3] &&
         high[i] >= high[i-2] &&
         high[i] >= high[i-1]){
   
  
            high_extreme_counter++;
      }
      
  }  
  
  return high_extreme_counter;  
}  

int extreme_point_test_bearish(double &low[],double atr, double extreme_point) {

  
   double extreme_point_lower_border = 0;
       
   extreme_point_lower_border = extreme_point + extreme_zone_multiplier * atr;
   
   int low_extreme_counter = 0;
   
   for (int i = 7; i<200; i++){
   
    
      
      if(         
         low[0] < low[i]    &&
         low[i] <= extreme_point_lower_border &&
         low[i] <= low[i+5]&&  
         low[i] <= low[i+4]&&  
         low[i] <= low[i+3]&&  
         low[i] <= low[i+2]&&  
         low[i] <= low[i+1]&&  
         low[i] <= low[i-5]&&  
         low[i] <= low[i-4]&&  
         low[i] <= low[i-3]&&  
         low[i] <= low[i-2]&&  
         low[i] <= low[i-1] ){

            
            low_extreme_counter++;
      
      }
   
   }
      
   return low_extreme_counter;

}

I am trying to build an EA that defines a zone and counts the number of the tests to the zone. I calculate the highest/lowest point of the last 200 bars. Use it as the upper/lower border and calculate lower/upper border with the 3*atr. The goal is to find out how many times a price zone is tested. Also the tests to the zone must be at least 10 bars apart. But somehow the code keeps giving me mixed results. Sometimes it prints a signal where it shouldn't, sometimes it doesn't print where it should and sometimes prints a signal at a level depending on the outputs even debugging shows that it should anyway.

***

 
Please insert the code correctly:  FIRST press the button   Code, and THEN paste the code in the pop-up window.
 
  1. Please edit your (original) post and use the CODE button (Alt-S)! (For large amounts of code, attach it.)
              General rules and best pratices of the Forum. - General - MQL5 programming forum (2019)
              Messages Editor

  2. int intervalPredicate(double close, double open, double high, double low){…}
    
    
    double extreme_point (int intervalPredicate, double &higharray[], double &lowarray[]){
       if (intervalPredicate == 1) {
    Do not post code that will not even compile. If it's a function, how can it be a variable?