Download MetaTrader 5

Small problem whit refresh Buffer or Object

To add comments, please log in or register
fly7680
636
fly7680  

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?

whroeder1
15923
whroeder1  
  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.
fly7680
636
fly7680  
Thanks whroeder1 !!!
To add comments, please log in or register