Coders, what am i doing wrong in this snipit of code?

 
void SetCandleColor(int col, int i) 
{ 
//+----------------   part one below
     int limit;
     int counted_bars=IndicatorCounted();

     //---- check for possible errors
     if(counted_bars<0) return(-1);
     //---- last counted bar will be recounted
     if(counted_bars>0) counted_bars--;
     limit=Bars-counted_bars;
     
     //---- main loop 
     
     for(int shift= limit-1; shift >=1; shift--)
     {
     int M15_bar3 = iBarShift(NULL, PERIOD_M15, Time[shift]); 
     double M15_Close3 = iClose(NULL, PERIOD_M15, M15_bar3);
      }
//+-----------------part 2 below

double high,low,bodyHigh,bodyLow; 
{
  bodyHigh = M15_Close3; 
  bodyLow = (iClose(Symbol(),PERIOD_H1,i)-5*Point); 
  high = iHigh(Symbol(),PERIOD_H1,i); 
  low = iLow(Symbol(),PERIOD_H1,i); 
  } 
  Bar1[i] = low;
   Candle1[i] = bodyLow;
    Bar2[i] = low;
     Candle2[i] = bodyLow;
     Bar3[i] = low;
   Candle3[i] = bodyLow;
    Bar4[i] = low;
     Candle4[i] = bodyLow;
      switch(col)
       { 
       case 1: 
       Bar1[i] = high; 
       Candle1[i] = bodyHigh; 
       break; 
       
       case 2: 
       Bar2[i] = high;
        Candle2[i] = bodyHigh;
         break; 
         
         case 3: 
       Bar3[i] = high; 
       Candle3[i] = bodyHigh; 
       break; 
       
       case 4: 
       Bar4[i] = high;
        Candle4[i] = bodyHigh;
         break; 
         
       case 5: 
       Bar5[i] = high;
        Candle5[i] = bodyHigh;
         break;  
         
         }
        }
//+------------------------------------------------------------------+  
The code compiles but mt4 does not open.. The problem lies withing part one of the code. I do not know what i am doing worng here. Please help.
 
Add . . . Print("limit= ", limit); before your "main loop" . . see what it is, I suspect it is <= 1
 
RaptorUK:
Add . . . Print("limit= ", limit); before your "main loop" . . see what it is, I suspect it is <= 1

ok. I have found the problem. Thanks for the help.
 
  1.      for(int shift= limit-1; shift >=1; shift--)
         {
         int M15_bar3 = iBarShift(NULL, PERIOD_M15, Time[shift]); 
         double M15_Close3 = iClose(NULL, PERIOD_M15, M15_bar3);
          }
    The loop does nothing. If you want the LAST 15 minute bar just:
    //     for(int shift= limit-1; shift >=1; shift--)
    //     {
         int M15_bar3 = iBarShift(NULL, PERIOD_M15, Time[1]); 
         double M15_Close3 = iClose(NULL, PERIOD_M15, M15_bar3);
    //      }
  2. If you want the 15 minute bar of the candle you're computing you'ld use Time[i]
  3. But you're not using the variables at all. Delete the loop.
Reason: