new bar formed?

 

Hello,


How we know when a new bar is formed, please?


It's because I would want to stop analyse, trade...ets when something happened in the last bar.


Regards

Chris

 

W

> How we know when a new bar is formed

When the current bar gives its first tick

You can detect this with

...

if (Volume[0]==1) 
 {
   // First tick is here so do stuff for new bar



 }

...

Good Luck

-BB-

 
BarrowBoy:

W

> How we know when a new bar is formed

When the current bar gives its first tick

You can detect this with

...

...

Good Luck

-BB-

Thanks BarrowBoy

 

you could also:



int barsTotal = 0;

int start()
{
   if(Bars > barsTotal){
      //...do stuff..;
      barsTotal = Bars;
   }
}
 
jmca:

you could also:



I do that in first and I would be sure if something like newBarFormed exists?

also thanks

Chris

 
jmca:

you could also:




i like this better somehow closer to my style.

Thx

 
onemore:


i like this better somehow closer to my style.

Thx


but both versions show a new bar even when the price of the current bar changes direction, any reason why?
 

How about:

datetime lastBarOpenTime;
bool IsNewBar()
{
datetime thisBarOpenTime = Time[0];
if(thisBarOpenTime != lastBarOpenTime)
{
lastBarOpenTime = thisBarOpenTime;
return (true);
}
else
return (false);
}

 
Bars is unreliable (doesn't change once you reach max bars in chart) Volume is unreliable (you can miss ticks) Always use time.
start(){
   static datetime Time0; if (Time0 == Time[0]) return; Time0 = Time[0];
   ...
 

Gosh, this is an old topic!

> Always use time..

Is the right answer

-BB-

 
BarrowBoy:

Gosh, this is an old topic!

> Always use time..

Is the right answer

-BB-


  Is time really that reliable ?

  The granularity of Time[0] is in seconds, so if

  within the first second you get two ticks, it would

  count as two newbars. :/