Download MetaTrader 5
To add comments, please log in or register
Thousands of developers have already published their products in the Market. Join them!
dck 2011.07.07 11:31 

How to Calculate with date and times?

On several places there are comments like the following ( 

datetime t;
MqlDateTime mdt;
TimeToStruct(t,mdt); += 45;
//or = 50; //50 days from the beginning of the month
//or mdt.hour += 134; //134 hours in the future
//or mdt.hour = 1000; //1000 hours from the beginning of the day 

This works but gives incorrect results. example: -= 50 gives an negative day and not a day one ore two month in the past.

What is MqlDateTime useful for if not for calculations?
and how do you calculate valid dates?

Attached is a indicator that shows the incorrect behavior of the above method

regards and thanks for your help

datetime calculations
Is there a way to get an open time of a weekly bar for instance, given a day and time on that week?
datetest.mq5 4 kb
To add comments, please log in or register