A new-bar tick?

 

Hi MQLers,

is there something like a new-bar tick ( I do not think so)? I mean - how does the terminal decide "this incoming data do not belong to the existing bar anymore, therefore I am gonna close it now and start with the next one"? The background is that I need to keep track of how certain bars ( their indexes) have moved in time, e.g. take a bar which is now Time[5] and I ned to be able to locate in ten minutes, or even continually but still be able to track its index.

 

Any ideas?

Mac 

 
Martinigue:

Hi MQLers,

is there something like a new-bar tick ( I do not think so)? I mean - how does the terminal decide "this incoming data do not belong to the existing bar anymore, therefore I am gonna close it now and start with the next one"? 

Time.  On an M1 chart,  if Time[0] is 12:54:00 and the tick just arrived at a time of 12:55:03  then it is part of a new bar.  It is possible to receive no ticks for over a minute and for a M1 bar to be missing.
 
Use Volume [0] better than time
 
mikedavis265:
Use Volume [0] better than time
Always use Time. Never use Volume or Bar_Count. Volume[0] or Volume[1] Tick could be missed. Bar_Count will not update once the MaxBars_OnChart count is met.
 

Use the following code:


datetime BarTime;
bool NewBar;

int init()
{

BarTime=Time[0];
}

int start()
{
NewBar=isNewBar();

if (NewBar)
{
DO bla bla bla..........
}
}

bool isNewBar() 
{
//---- 
   bool res=false; 
   if (BarTime!=Time[0]) 
      BarTime=Time[0];  
      res=true;
} 
 
bachapk:

Use the following code:

datetime BarTime;
bool NewBar;

int init()
{

BarTime=Time[0];
}

int start()
{
NewBar=isNewBar();

if (NewBar)
{
DO bla bla bla..........
}
}

bool isNewBar() 
{
//---- 
   bool res=false; 
   if (BarTime!=Time[0]) 
      BarTime=Time[0];  
      res=true;
} 

Correction :

datetime BarTime;
bool NewBar;

int init()
{

BarTime=Time[0];
}

int start()
{

// NewBar=isNewBar();

if (BarTime != Time[0}) // if (NewBar)
  {
  DO bla bla bla..........
  }
}

// --- there's no need to use this, beside it return nothing
// bool isNewBar() 
// {
//---- 
//    bool res=false; 
//    if (BarTime!=Time[0]) 
//       BarTime=Time[0];  
//       res=true;
// } 
 
lol
 
// --- there's no need to use this, beside it return nothing
// bool isNewBar() 
// {
//---- 
//    bool res=false; 
//    if (BarTime!=Time[0]) 
//       BarTime=Time[0];  
//       res=true;
// } 
In fact that is dangerous (even if corrected,) as it can NOT be called more than once per tick.
int start(){
   static datetime Time0; if (Time0 == Time[0]) return; Time0 = Time[0];
   // start of a new bar
Reason: