Update problems - date time broken - how to detect new bar

 

Can anyone tell me how to correct datetime for this update?

This is a snippet that had been working for over a year. It's purpose is to detect when a new bar has drawn. Was bullet proof. Not now. Doesn't work following the upgrade.

int checkTime(){

int thisBarOpened=datetime Time[0];

if(thisBarOpened!=lastBarOpened){newBar=true;lastBarOpened=thisBarOpened;}

if(newBar){

// do stuff if newBar

}

}

4 errors produced:

'Time' - unexpected token

'[' - unexpected token

'[' - array required

'datetime' - expression expected

Any help would be greatly appreciated. Otherwise, I guess I go back to mod arithmetic, which is how I did it before using this method.

 

to cast a value use brackets eg thisBarOpened = (datetime)Time[0];

But datetime is now 64 bit and wont fit in an int (which is 32bit), so why not just leave thisBarOpened as a datetime ?

datetime thisBarOpened=Time[0];

 
LouK:

Can anyone tell me how to correct datetime for this update?

This is a snippet that had been working for over a year. It's purpose is to detect when a new bar has drawn. Was bullet proof. Not now. Doesn't work following the upgrade.

int checkTime(){

int thisBarOpened=datetime Time[0];

if(thisBarOpened!=lastBarOpened){newBar=true;lastBarOpened=thisBarOpened;}


If you double post you will find your posts being deleted . .. if you carry on after that you will find your User ID BANNED. Please do not double post: https://www.mql5.com/en/forum/149338
 
LouK:

Can anyone tell me how to correct datetime for this update?


Make some proper code:

//somewhere in the global scope:
datetime lasttime;

//somewhere in OnTick() handler:
if(Time[0] > lasttime)
{
        lasttime = Time[0];
        // do something on new bar //
}
Reason: