Search code examples
mql4mql5

How to get tomorrow date in mql5?


I want to draw a horizontal trendline that extends from today to tomorrow, And I have trouble getting time tomorrow.

for example today is 2021.12.17 00:00:00

Comment( iTime(_Symbol, PERIOD_D1, 0) + (PERIOD_D1*60) );

// Today: 2021.12.17 00:00:00    
// MQL4:  2021.12.18 00:00:00 ... it's ok.
// MQL5:  2021.12.28 09:28:00 ... it's not ok! why?

MQL4: As you can see in the code above, in mql4, through the iTime function and adding a period, the date of tomorrow can be obtained, it's return 2021.12.18 00:00:00 .

MQL5: But this code shows date 2021.12.28 09:28:00 in mql5.

In other words, PERIOD_D1 is equal to 1440 in mql4 but in mql5 is equal to 16408, Why?

Comment(PERIOD_D1);
// MQL4: 1440
// MQL5: 16408 why?!!!

Solution

  • Unlike MQL4, PERIOD_D1 does not relate to the amount of minutes in the period in MQL5. The simple workaround is to add (1440*60) to iTime().

    Alternatively, use PeriodSeconds() as below

    iTime(_Symbol, PERIOD_D1, 0) + PeriodSeconds(PERIOD_D1)