For loop unwanted counts problem?

 

Hi,

As seen the following code at 00:00 it cycles down 1000 - 0 and increments ++ on each signal found. 

for(int i=Bars-1; i>=0; i--)
{
   double ma = iMA(_Symbol,_Period,200,0,MODE_SMA,PRICE_CLOSE,i);
   static int count=0; 
      
   if(Open[i]<ma && Close[i]>ma) count++;
      
   Print(" i = ",i," count = ",count);
}

The problem is on next bar say 00:15 it cycles 1001-0 only this time increments each signal found again? when i need it to only increment new signals as they occur not the repeat unwanted counts.     

Not sure what to do?         

 
What does the keyword static do, and should you be using it?
 
Thanks to you for saying this ive now reallised the following does what i need 
int start()
{   
   int count;
  
   for(int i=Bars-1; i>=0; i--)
   {
      double ma = iMA(_Symbol,_Period,200,0,MODE_SMA,PRICE_CLOSE,i);

      if(Open[i]<ma && Close[i]>ma) count++;
      Print(" i = ",i," count = ",count);      
   }

   return(0); 
}

By doing the count outside the block and taking static away it now counts the previous signals once and each new signal.

Thanks for that reminder.

 
   int count;
Assuming you are using strict (which you should always use), count now contains random values.