help ima

 
for(int i=0; i<limit; i++)
     {
      //---- ma_shift set to 0 because SetIndexShift called abowe
      ExtBlueBuffer[i]=iMA(NULL,0,media21Period,0,MODE_EMA,0,i);
      ExtRedBuffer[i]=iMA(NULL,0,media8Period,0,MODE_EMA,0,i);
  
    Ima21candprec[i]=iMA(NULL,0,media21Period,0,MODE_EMA,0,i+2);
      Ima8candprec[i]=iMA(NULL,0,media8Period,0,MODE_EMA,0,i+2);


      Ima21Candprec=Ima21candprec[i];
      Ima8Candprec=Ima8candprec[i];
      ima21=ExtBlueBuffer[i];
      ima8=ExtRedBuffer[i];
         }
         /*if(barTemp!=Bars)
         {
            if(ima8>ima21)
            {
               Alert("Long su "+Symbol()+" a TF "+IntegerToString(Period(),0,0));
               Comment("\nLong\nAlla Barra" + barTemp+ "\nCommento: "+ commento);
               barTemp=Bars;
            }
           if(ima21>ima8)
           {
            Comment("\nShort\nCommento: "+ commento);
            Alert("Short su "+Symbol()+" a TF "+IntegerToString(Period(),0,0));
            barTemp=Bars;
           }
         */

      Comment("Moving Avarage 21:  "+DoubleToString(ima21,4) + "\nMoving Avarage 8: " + DoubleToString(ima8,4)+
              "\nMoving Avarage 21Prec: "+DoubleToString(Ima21Candprec,4) + "\nMoving Avarage 8 Prec : " + DoubleToString(Ima8Candprec,4)+
              "\nlimit: "+i);
  
      
//---- done
   return(0);
  }


Hello everyone the following code gives me the allert trend at every candle and tell me which moving average is located below and above which the two so as to determine the trend.

 I would serve the allert only when crossing the medium so I am trying to store the value of the medium to the previous candle with: "Ima21candprec [i] = iMA (NULL, 0, media21Period, 0, MODE_EMA, 0, i + 2);

Ima8candprec [i] = iMA (NULL, 0, media8Period, 0, MODE_EMA, 0, i + 2); " for the value of these two variables always gives me 00, you tell me where I'm wrong?