There are 86400 seconds in a day.
Compare the timestamp of the bar you are interested in and the current time.
Divide the difference by 86400 to get days.
There are 86400 seconds in a day.
Compare the timestamp of the bar you are interested in and the current time.
Divide the difference by 86400 to get days.
oh, .... this is the way noone should rely on...
Because sometimes you don't have 86400 seconds in a day? Those pesky leap seconds...
honest_knave: Because sometimes you don't have 86400 seconds in a day? Those pesky leap seconds...



All quite useful, however the OP talked about days, not trading days. The latter has a plethora of meanings. The former is rather definite (leap seconds to one side).
I didnt know if such simple thing was so hard in MT to achieve...
Even ThinkOrSwim has that feature...
True but what good is days? Orders kept over weekend or market holidays, shouldn't be treated differently.
Because of the problems with broker TZs mentioned above, what I would to is get iBarShift That gives elapsed bars, and for days multiply by _Period/PERIOD_D1.
True but what good is days? Orders kept over weekend or market holidays, shouldn't be treated differently.
Because of the problems with broker TZs mentioned above, what I would to is get iBarShift That gives elapsed bars, and for days multiply by _Period/PERIOD_D1.
no, i just use that variable in calculations... When NewDay comes, then I save a new value in array, then I calculate something from this array... and I needed the exact solution.
for example, when NewDay starts, I want to draw horizontal line on the low of that bar, till the next day..
no, i just use that variable in calculations... When NewDay comes, then I save a new value in array, then I calculate something from this array... and I needed the exact solution.
for example, when NewDay starts, I want to draw horizontal line on the low of that bar, till the next day..
for MT4
if (day!=Day()) { day=Day(); //new day }
for MT5
MqlDateTime dt_struct; TimeToStruct(TimeCurrent(),dt_struct); if (day!=dt_struct.day) { day=dt_struct.day; //new day }
selnomeria: no, i just use that variable in calculations... When NewDay comes, then I save a new value in array, then I calculate something from this array... and I needed the exact solution.
for example, when NewDay starts, I want to draw horizontal line on the low of that bar, till the next day..  If it's new day, save the value in the buffer, otherwise copy the value from the previous bar. 
I a on XYZ minute timeframe chart.
how can I:
1) calculate how many days gone from Time[xyz] ?
2) calculate how many days gone from first bar of chart