Fire once on bar close

 

Hi,


I have written an indicator to fire a method when the bar closes. However it seems to be firing over and over once the bar closes. Any ideas, relevant code is below.


int start()
{ 

   int limit;
   int counted_bars=IndicatorCounted();
   
   //---- check for possible errors
   
   if(counted_bars<0) 
      return(-1);
     
   if (counted_bars == 0) //Don't run on every bar when indicator first added
      return (0);
      
   limit= Bars- counted_bars;
   
   //---- main loop
   for(int i=0; i<limit; i++)
   {
      FireMethodONCE();
   }
   //---- done
   return(0);
     
}

 
Global datetime check_time;
if(check_time<Time[i]) {
FireMethodONCE();
check_time = Time[i];
}

Try this.
 
datetime check_time ;

int  init ()
{
     check_time = Time [ 0 ] ;
     return ( 0 ) ;
}

...

if ( check_time < Time [ 0 ] )
   {
     check_time = Time [ 0 ] ;
     FireMethodONCE () ;
   }
  
...
     
datetime check_time ;
  
int  init ()
{
     check_time = iTime ( 0 , 0 , 0 ) ;
     return ( 0 ) ;
}

...

if ( check_time < iTime ( 0 , 0 , 0 ) )
   {
     check_time = iTime ( 0 , 0 , 0 ) ;
     FireMethodONCE () ;
   }
  
...
      
Reason: