Download MetaTrader 5

Need to write "Get periods between datetime1 and datetime 2"

To add comments, please log in or register
Jacob Funk
92
Jacob Funk  

Hi, I'm looking to write a function that returns the number of periods (in terms of the _Period) between two datetimes. Right now I can't figure out how to interpret the result of _Period or GetPeriod because I've only used it to pass in to other functions. Would be awesome if someone could advise or give me a few pointers (no 0x0875565s though) to get this figured out. Thanks!

 Shark 

Jin
1539
Jin  

Shark,

_Period or Period() returns the enumerator ENUM_TIMEFRAMES, that is an integer, if you prefer, an internal code that represents the current period.

For instance, for "M5" Period() returns 5, for "H1" Period() return 16385.

Use the function PeriodSeconds() to know the number of seconds of the current period:

Print(PeriodSeconds(_Period));   // returns for "M5" the value 5, and for "H1" this function returns 3600.

Also, remember that type datetime is equivalent to long, and each unit represents 1 second.

Then:

datetime dat1 = D'2011.02.15 03:50:46';
datetime dat2 = D'2011.02.16 14:22:13';

Print((long)(dat2 - dat1));   // it will print the number of seconds between the datetimes.

 

Regards

Jin  

  

 

To add comments, please log in or register