From 3a77d0aa0374c0c96f059a7a4f617a9100467a63 Mon Sep 17 00:00:00 2001 From: Adrian Kierzkowski Date: Fri, 22 Apr 2022 17:23:09 +0200 Subject: [PATCH] Refs #337 New week detection. Added check if it's the first day of the week (which is Monday in MQL). Previously we only checked if current day of the week has changed. --- DateTime.mqh | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/DateTime.mqh b/DateTime.mqh index 49502d55f..156c78831 100644 --- a/DateTime.mqh +++ b/DateTime.mqh @@ -113,9 +113,14 @@ class DateTime { _result |= DATETIME_SECOND; } - if (dt_curr.GetValue(DATETIME_DAY | DATETIME_WEEK) != dt_last.GetValue(DATETIME_DAY | DATETIME_WEEK)) { - // New week started. - _result |= DATETIME_WEEK; + if (dt_curr.GetValue(DATETIME_DAY | DATETIME_WEEK) == 0) { + // It's the first day of the week (Sunday). + // Note that GetValue() for the above flags just returns value of GetDayOfWeek(). + // @see https://docs.mql4.com/dateandtime/dayofweek + if (dt_curr.GetValue(DATETIME_DAY | DATETIME_WEEK) != dt_last.GetValue(DATETIME_DAY | DATETIME_WEEK)) { + // New week started. + _result |= DATETIME_WEEK; + } } #ifdef __debug__