Only process each bar once

 
How would one go about guaranteeing that each bar is only processed once?

I have a routine that performs some counting on each bar of occurrences of a setup. I need to make sure that each bar is only processed once so that each "occurrence" of this setup is only counted once. I can only need to process each bar after the bar itself is closed ... not tick by tick.

Any ideas would be greatly appreciated.
 

Use this - OTTOMH :)

if (Volume[0]>1) return(0); // quit AFTER first tick of new, allowing you to evaluate High[1] etc ONCE below this line

 

You could execute your code at the very first tick of a new bar ( i.e. right after the previous bar has closed ).

Here's a function that will return TRUE if a new bar has just formed:

// This function returns TRUE at the very first tick a bar i.e. after the previous bar has just closed
bool NewBar()
{
   if(PreviousBarTime<Time[0])
   {
      PreviousBarTime = Time[0];
      return(true);
   }
 
   return(false);    // in case if - else statement is not executed
}

you need to declare datetime PreviousBarTime at the beginning of your EA...

then in your code you could just use

if ( NewBar() )
{
...... code you need to be executed after a bar has closed here ....
}

thank you

automatedfx@gmail.com