Help for working with bar completion

 
Hi, I`m a newbie in this. I ´m trying to work with automated expert advisors that work only at bar completion, I found this code but I don`t know how to use it well,  
 
static datetime prevtime=0;
...
if(prevtime == Time[0]) return(0);
prevtime = Time[0];
 
anybody can help me?
 
Hi,

here's the explanation.

This piece of code is equivalent to the following:
static datetime prevtime=0;  // previously recorded time of current bar; static(!) variable, such that value is remembered on successive calls
...
 
if (prevtime != Time[0]) {   // are we in a new bar?
  prevtime = Time[0];        // remember new time
  ...                        // perform the calculations we want to
} else {
  return(0);                 // do nothing 
}
If nothing follows the if-expression you can actually leave out the else-clause
static datetime prevtime=0;  // previously recorded time of current bar; static(!) variable, such that value is remembered on successive calls
...
 
if (prevtime != Time[0]) {   // are we in a new bar?
  prevtime = Time[0];        // remember new time
  ...                        // perform the calculations we want to
}
So if the start time of the current bar (Time[0]) changes, you do something, otherwise you don't.

Hope this helps!

Cheers!

Max
 
int bars;

int Start()
{
if (Bars>bars)
{
...;
...;
bars=Bars;
}
}
Reason: