Small problem whit refresh Buffer or Object

 

Hello to everyone, I have a small problem using this code:

//--------NewBar------------
bool NewBar()
  {

   static datetime lastbar;
   datetime curbar=Time[0];
   if(lastbar!=curbar)
     {
      lastbar=curbar;
      return (true);
     }
   else{return(false);}}
//--------NewBar------------

that helps me to read the code only once for each new bar. If time frame change, the buffers or objects are updated only after the new bar is formed, how can i fix this problem Without having to read the Tick Tick?

 
  1. Move lastbar globally and set it to zero in init.
  2. Simplified
    bool NewBar(){
       static datetime lastbar;
       datetime prevBar=lastbar; lastbar=Time[0];
       return prevBar!=lastbar;
    }
  3. I disagree with making a new bar function, because it can only be called once
    per tick. A variable can be tested multiple times.
 
Thanks whroeder1 !!!