Holding a value for X candles

 
void TouchedSR()
  {
   InsideResistance=false;
   InsideSupport=false;
   for(int i=0; i<10; i++)
     {
      double HiCandle = iHigh(NULL, TradingTimeframe, i);
      double LoCandle = iLow(NULL, TradingTimeframe, i);
      //Test for being inside a zone.
      if(LoCandle <= HI_Res && HiCandle >= LO_Res && Bid>WeekPivot && Bid<=R138 && Bid>=DRangeHigh-DRange75)
        {
         InsideResistance = true;
        }
      else
         if(LoCandle <= HI_Sup && HiCandle >= LO_Sup && Bid<WeekPivot && Bid>=S138 && Bid<=DRangeLow+DRange75)
           {
            InsideSupport = true;
           }
     }
  }

I am trying to hold the value 'InsideResistance' or 'InsideSupport' for 10 candles unless the opposite becomes true. I am somewhat new to mql4 and I am wondering if I am accomplishing this with the code above. 


Thanks for your help.

 
Digitals113: I am trying to hold the value 'InsideResistance' or 'InsideSupport' for 10 candles unless the opposite becomes true. 

That is babel. Until you can state it in concrete terms, it can not be coded and no one can help you.

 
William Roeder:

That is babel. Until you can state it in concrete terms, it can not be coded and no one can help you.


OK I will give more explanation.. Once the bid goes above a price 'InsideResistance' becomes true. I want to hold the value as true for 10 candles even if the bid goes below the price.

 
Digitals113: I want to hold the value as true for 10 candles even if the bid goes below the price.
  1. On condition, remember the non-series bar index and when the as-series equivalent becomes 11, reset.
    #define  SERIES(I)   (Bars - 1 - I) // As-series to non-series or back.
  2. Or remember the time and use iBarShift to get as-series index.
 
William Roeder:
  1. On condition, remember the non-series bar index and when the as-series equivalent becomes 11, reset.
  2. Or remember the time and use iBarShift to get as-series index.

I know how to code the second option, could you explain more about this so I can understand better? Thank you.

 
Digitals113: could you explain more about this so I can understand better? 

What part is unclear?

 
William Roeder:

What part is unclear?

int I = 10
(Bars - 1 - I)

Is this correct?

 
void TouchedSR()
  {
   double HiCandle = iHigh(NULL, TradingTimeframe, 0); //high of current candle
   double LoCandle = iLow(NULL, TradingTimeframe, 0); //low of current candle
//Test for being inside a zone.
   if(LoCandle <= HI_Res && HiCandle >= LO_Res && Bid>WeekPivot && Bid<=R138 && Bid>=DRangeHigh-DRange75) //Signal code
     {
      InsideResistance = true; //signal true
      ResSignal=iTime(NULL,TradingTimeframe,0); //Time of candle signal happened
     }
   if(!CloseEnough(ResSignal,0)) //Check if ResSignal is greater than 0
     {
      RST=iBarShift(NULL,TradingTimeframe,ResSignal,true); //Shift of bar signal
      if(RST>10) //if shift is more than 10 candles
        {
         InsideResistance=false; //signal false
         ResSignal=0; //Reset signal time
        }
     }
  }

This is the code that seems to do the job, is there anything I can improve on?