my indicator doesnt execute in the past

 

Hello:

Below you have my start function. The problem I am having with this Custom Indicator is that It apparently doesnt process in all the chart´s bars, but only in some bars before the present.

It just tries to know if price is above, below or inbetween ichimoku cloud. If it is below it returns 20, above: 80, inbetween: 50.

(it does perfectly in the current bar, but a about 1 year before (daily chart) to the back it returns the value "80".

thanks in advance

//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start()
  {
   int    counted_bars=IndicatorCounted();
//----
   
   
   
   int i,                           // Bar index
       Counted_bars;                // Number of counted bars
//--------------------------------------------------------------------
   Counted_bars=IndicatorCounted(); // Number of counted bars
   i=Bars-Counted_bars-1;           // Index of the first uncounted
   while(i>=0)                      // Loop for uncounted bars
     {
      double spanA=iIchimoku(NULL,getSupPeriod(Period()),9,26,52,MODE_SENKOUSPANA,i);
   double spanB=iIchimoku(NULL,getSupPeriod(Period()),9,26,52,MODE_SENKOUSPANB,i);
  // Print(getSupPeriod(Period()));
   
   double may=MathMax(spanA,spanB);
   double min=MathMin(spanA,spanB);
 
   
   
      if(Close[i]>may)
      {
         upOrDown[i]=80;
      }
      else
      if(Close[i]<min)
      {
         upOrDown[i]=20;
      }
       else
      
      {
         upOrDown[i]=50;
      }
      i--;                          // Calculating index of the next bar
     }
//--------------------------------------------------------------------

   
//----
   return(0);
  }
//+------------------------------------------------------------------+

int getSupPeriod(int p)
{
   if(p==PERIOD_M1){return(PERIOD_M5);}
   if(p==PERIOD_M5){return(PERIOD_M15);}
   if(p==PERIOD_M15){return(PERIOD_M30);}
   if(p==PERIOD_M30){return(PERIOD_H1);}
   if(p==PERIOD_H1){return(PERIOD_H4);}
   if(p==PERIOD_H4){return(PERIOD_D1);}
   if(p==PERIOD_D1){return(PERIOD_W1);}
   if(p==PERIOD_W1){return(PERIOD_MN1);}
   
}
 

UPDATE

It is executing in the past, somehow it is getting that the price is always over Ichimoku cloud in the weekly chart so it returns "80", i have no idea why since that is not true.

 
Sadly you cannot access the history of a higher timeframe from a lower -BB-
 
  1. BarrowBoy:
    Sadly you cannot access the history of a higher timeframe from a lower -BB-
    news to me.
  2. double spanA=iIchimoku(NULL,getSupPeriod(Period()),9,26,52,MODE_SENKOUSPANA,i);
    i is the shift for the current timeframe but your asking for the Ichimoku of a different one. You need the shift for that timeframe.
        int sp = getSupPeriod(Period());
    for (i=Bars-Counted_bars-1; i>=0; i--){
        int spi= iBarShift(NULL, sp, Time[i]);
        double spanA=iIchimoku(NULL,sp,9,26,52,MODE_SENKOUSPANA,spi);
        ...
        //i--;                          // Calculating index of the next bar
    }