closing candle above or below the moving average

 
bool NuovaCandela()
  {
   static datetime TempoUltimaCandela;
   datetime TempoCandelaAttuale=Time[0];
   if(TempoCandelaAttuale!=TempoUltimaCandela)
     {
      TempoUltimaCandela = TempoCandelaAttuale;
      return (true);
        }else{
      return (false);
     }
  }


int trendMediemmobili()
  {
    double mmoblie_9;
    mmoblie_9= iMA(Symbol(),Period(),9,0,MODE_EMA,PRICE_CLOSE,1);
   
       if((Close[1]< mmoblie_9)&& (Close[0]>mmoblie_9)){
       su++; 
       }
       if((Close[1] > mmoblie_9)&& (Close[0]< mmoblie_9)){
       giu++; 
       }
  
   return 0;
  }


int start()
   for (i = Bars-10; i >= 0; i--) 
    {
      if(NuovaCandela()==true)
      trendMediemmobili();
      }
      
      Comment("Giu "+ giu+
              "\nsu"+ su );
 
The "trendMediemmobili ()" should increase the variable "on" when the candle "n-1" (the previous candle) closes below the moving average 9 times and the candle "n" (current candle) closes above the moving average 9 periods and vice versa should increase the variable "down" when the candle "n-1" (the previous candle) closes above the moving average 9 times and the candle "n" (current candle) closes below the moving average of 9 periods.
But it does not work sempree .... you know how to help me fix it?
 
texcs: closes below the moving average 9 times and the candle "n" (current candle) closes above the moving average 9 periods
if((Close[1]< mmoblie_9)&& (Close[0]>mmoblie_9)){

TrendMediemmobili tests if the previous candle (Close[1]) closed below and the current Bid (Close[0]) is above the moving average.

Calling it 9 times changes nothing except how many times the variable is incremented.

 
I care that is compared with each new candle with the previous one, like I change?
 

So it seems that it works well as you test it

int trendMedia9(){

    double mmoblie_9;
    mmoblie_9= iMA(Symbol(),Period(),9,0,MODE_EMA,PRICE_CLOSE,1);
   
       if((Close[2]< mmoblie_9)&& (Close[1]>mmoblie_9))
       {
       su++; 
       ObjectCreate(ChartID(),IntegerToString(Time[0],0,0),OBJ_VLINE,0,Time[0],0);
       ObjectSetInteger(ChartID(),IntegerToString(Time[0],0,0),OBJPROP_COLOR,Green);

       }
       
       else if((Close[2] > mmoblie_9)&& (Close[1]< mmoblie_9))
       {
       giu++;
       ObjectCreate(ChartID(),IntegerToString(Time[0],0,0),OBJ_VLINE,0,Time[0],0);
       ObjectSetInteger(ChartID(),IntegerToString(Time[0],0,0),OBJPROP_COLOR,clrDarkRed);
       }
 
 
       return 0;
       }
 

 But I think too many signals you tips to reduce and rendeere + reliable signals?

Reason: