Download MetaTrader 5
To add comments, please log in or register
Log in to MQL5.community using OpenID. It is convenient!
LouK
143
LouK 2014.02.05 18:03 

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.

ydrol
593
ydrol 2014.02.05 18:19  

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];

Simon Gniadkowski
Moderator
17963
Simon Gniadkowski 2014.02.05 18:35  
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
darksideofthemoon
57
darksideofthemoon 2014.02.05 21:42  
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 //
}
/
To add comments, please log in or register