How To Know when it is the end or beginning of a new bar

 

Hey there,

I'm experiencing some big problems when it comes to determining when a newly bar is formed, or an old bar is closed.

The code only needs to execute when a new bar is formed.

So far I have tried:

if(Volume[0] == 0) {//do stuff }

and

if(Bars > barsTotal || Volume[0] == 0){
 barsTotal = Bars;
//do stuff
}

but it wont work.

Any help would be appreciated!

 
 
Ah good awesome thanks I did not see that thread
 

I cannot get this code to work:


static datetime CurrentBarOpenTime ;

if(iTime(Symbol(),0,0)==CurrentBarOpenTime) return;
else CurrentBarOpenTime=iTime(Symbol(),0,0);


//Code goes here

Any idea why it wont work?

Thanks!

 
Ok seem to be working fine now, thanks