EA Saving Dates of HIgh/Low of Reversal condition of oversold and overbought conditions to predict next oversold area What am i missing?.

 

(MQL4)I am trying to code a function that can remember the date of a low or high given a specific condition until that condition is generated again and determines a new high.

The problem im having is that if i make a simple Highest or Lowest Function it uses periods and as a new day comes and the highest or lowest point is outside the Period Range  the Highest and Lowest is not longer the Highest and Lowest value of the Trend.  

i tried subtracting the new periods to cancel them by using iBarshift of the relevant lowest but does not work, what am i missing. 

double PShift = 3;

double PShift2 = 4;

double PShiftdiff = PShift2 - PShift;

   double Lowest = iLow(NULL,PERIOD_D1,(iLowest(NULL,PERIOD_D1,MODE_LOW,PShift,1)));

   double Highest = iHigh(NULL,PERIOD_D1,(iHighest(NULL,PERIOD_D1,MODE_HIGH,PShift,1))); //i want this high to be remember regardless of the amount of periods chosen to find the highest value in this case the highest value of a reversal and the lowest  

    // so it can remember  oversold reversal high/low then overbought high/low so it can use this data to predict next oversold reversal. 

   double HTime = iTime(NULL,PERIOD_D1, Highest);

   double BarshiftH = iBarShift(NULL,PERIOD_D1, HTime);  

if(Slope<1.5 && Slope>-1.5) { if(mid >rsimid) { if(Open[0]<mid+stdev2a) { if(iHigh(NULL,PERIOD_D1,PShift2)>Highest) { PShift = PShift+PShiftdiff; PShift2 = PShift +PShiftdiff; } } } 

 

Use static or globally declared variables.

   double min,max;
   static double highest,lowest,range;
//---check for new bar
   static int k,bar,prevBar;
   if(k!=i)
     { 
//---get minimum and maximum
      bar=iBarShift(NULL,TimeFrame,time[i]);
      if(prevBar!=bar)
        {
         min=iLow(NULL,TimeFrame,iLowest(NULL,TimeFrame,MODE_LOW,Period-1,bar+1);
         max=iHigh(NULL,TimeFrame,iHighest(NULL,TimeFrame,MODE_HIGH,Period-1,bar+1);
         if(highest<max)
            highest=max;
         if(lowest<min)
            lowest=min;
         range=highest-lowest;
         prevBar=bar;
        }
      k = i;
     }  
 

Thanks Appreciate your feedback, i was able to code what i needed, was focused on trying to restrict time when it was as simple as simply using the begining and end of each event/condition to obtain the data i needed using static variables.  Simplest things always get me.  

 

Since i finished a good portion of my code i ran the EA through the tester but got results with a 58% modeling quality using a 4h TF on 1 years worth of data.  any idea on how reliable these results may be? 

 

The modelling quality depends on which lower timeframe the tester is using. In this case probably not lower than M15 (will indicate when testing starts).

Since the range is calculated on the previous bars, results should be quite accurate. That said, I wouldn't trust the tester algorithm 100%.

Reason: