Checking previous bars

 

Hello,

can someone tell why I can not check previous colored bar(ColorT[bar+1], ColorT[bar+2], etc...) Indicator is using ADX values and according to them colors solid candles. I would like to play with these colored candles. Do I need another loop for this or how to solve it?

for(bar=limit; bar>=0 && !IsStopped(); bar--)
     {
      bool f1=false,f2=false,f3=false;
      To[bar]=EMPTY_VALUE;
      Tc[bar]=EMPTY_VALUE;
      Up[bar]=EMPTY_VALUE;
      Dn[bar]=EMPTY_VALUE;
      Ex[bar]=EMPTY_VALUE;
      if(ADX1[bar+1]<ADX1[bar])f1=true;
      if(ADX2[bar+1]<ADX2[bar])f2=true;
      if(ADX3[bar+1]<ADX3[bar])f3=true;
      if(f1 && f2 && f3 && ADX1[bar]>Alvl && ADX2[bar]>Alvl2)
        {
         double di=PADX1[bar]-MADX1[bar];
         double hi=MathMax(open[bar],close[bar]);
         double lo=MathMin(open[bar],close[bar]);
         double op=open[bar];
         if(di>0)
           {
            To[bar]=lo;
            Tc[bar]=hi;
            ColorT[bar]=1;
            if(To[bar+1]==EMPTY_VALUE) Up[bar]=low[bar]-ATR[bar]*3/8;
          //if(ColorT[bar+2]==1 && ColorT[bar+1]!=1 && ColorT[bar]==1)   do something...
           }
         else
           {
            To[bar]=hi;
            Tc[bar]=lo;
            ColorT[bar]=0;
            if(To[bar+1]!=EMPTY_VALUE && To[bar]==EMPTY_VALUE) Dn[bar]=high[bar]+ATR[bar]*3/8;
          //if(ColorT[bar+2]==1 && ColorT[bar+1]!=1 && ColorT[bar]==1)   do something...
           }
        }
      else
        {
         if(To[bar+1]!=EMPTY_VALUE)Ex[bar]=close[bar+1];
         else Ex[bar]=Ex[bar+1];
        }
     }