print the average values to the "x" candle and the "x-1"

 

Hi Guys, this function should print the average values to the "x" candle and the "x-1" candle but it prints the same value please help me fix it I do not understand where I am going wrong?

   for(int i=0; i<limit; i++) 
     { 
      //---- ma_shift set to 0 because SetIndexShift called abowe 
      MediaBuffer[i]=iMA(Symbol(),Period(),mediaPeriod,mediaShift,MODE_EMA,PRICE_CLOSE,i);
      Media=MediaBuffer[i]; //Verde
     
      MediaCandelaPrec=iMA(Symbol(),Period(),mediaPeriod,mediaShift,MODE_EMA,PRICE_CLOSE,i-1);
      
      if(NuovaCandela()==true)
         trendMediemmobili();
      }
       Comment("\nMedia Candela Prec: "+ DoubleToString(MediaCandelaPrec,3)+"\nMedia Candela: " +DoubleToString(Media,3));
 
   return(0)
   
   
 
texcs81: I do not understand where I am going wrong?
  1. When i is zero, i-1 is the future, so of course that doesn't work. If you had used strict, you would have know that from the logs.
  2. See How to do your lookbacks correctly. Start using the new OnCalculate
  3. If mediaShift is negative, indexes less than that will always be blank. Must use the new form (#2) or recalculate all bars per tick.


Reason: