Support Board
Date/Time: Tue, 16 Sep 2025 17:10:05 +0000
Post From: ConvertDateTimeToChartTimeZone broken on daylight savings day when using SetTimeHMS
[2022-03-14 04:06:20] |
User719512 - Posts: 321 |
See the code and output below. The RTH_Open_Time_ChartTime should be 8:30 but is converting to 9:30. This breaks studies that are comparing a CurrentBarDateTime against the RTH_Open_Time_PT which has been converted to chart time in the variable RTH_Open_Time_ChartTime using ConvertDateTimeToChartTimeZone. The scenario: a study wants to detect a particular time of day. So the study gets the current bar time, converts it to a known time zone, sets the time to the desired time in that time zone, and calls ConvertDateTimeToChartTimeZone to store the desired time (in chart time) in a variable. That variable is getting a time that is 1 hour off. On the Globex open today 3/13, that desired time was 15:00 PT or 17:00 CT. My study did not detect that time till 18:00 CT and caused all further calculations to be off. See below for the output and the code I ran on a particular bar to try to identify the issue. It appears if you have a valid DateTime and call SetTimeHMS, then despite that time looking good when you print it, calling ConvertDateTimeToChartTimeZone on that time will give an invalid result. This may only be an issue on the DST time change day, but we have studies that are anchored to the Globex open on Sunday, and will give bad results for an entire week because of this. A fix and/or workaround would be appreciated. OUTPUT ====== Chart: F.US.ENQM22[M] 30 Sec #1 | Study: MGI | !!! This bar is sc.Index 15684 and is on a Chicago Timezone Chart at 18:00 on 3/13/2022 (daylight savings day) !!! | 2022-03-13 19:11:54.140 * Chart: F.US.ENQM22[M] 30 Sec #1 | Study: MGI | CurrentBarDateTime: 2022-03-13 18:00:00 | 2022-03-13 19:11:54.140 * Chart: F.US.ENQM22[M] 30 Sec #1 | Study: MGI | CurrentBarDateTime_PT: 2022-03-13 16:00:00 | 2022-03-13 19:11:54.140 * Chart: F.US.ENQM22[M] 30 Sec #1 | Study: MGI | CurrentBarDateTime_PT --> CurrentBarDateTime_ChartTime: 2022-03-13 18:00:00 | 2022-03-13 19:11:54.140 * Chart: F.US.ENQM22[M] 30 Sec #1 | Study: MGI | RTH_Open_Time_PT: 2022-03-13 06:30:00 | 2022-03-13 19:11:54.140 * Chart: F.US.ENQM22[M] 30 Sec #1 | Study: MGI | RTH_Open_Time_PT --> RTH_Open_Time_ChartTime: 2022-03-13 09:30:00 | 2022-03-13 19:11:54.140 * CODE ==== if (sc.Index == 15684) { SCDateTime CurrentBarDateTime = sc.BaseDateTimeIn[sc.Index]; SCDateTime CurrentBarDateTime_PT = sc.ConvertDateTimeFromChartTimeZone(CurrentBarDateTime, TIMEZONE_LOS_ANGELES); SCDateTime RTH_Open_Time_PT = CurrentBarDateTime_PT; RTH_Open_Time_PT.SetTimeHMS(6,30,0); msg.Format("!!! This bar is sc.Index %d and is on a Chicago Timezone Chart at 18:00 on 3/13/2022 (daylight savings day) !!!", sc.Index); sc.AddMessageToLog(msg, 1); msg.Format("CurrentBarDateTime: %s", GetDateTimeString(CurrentBarDateTime).GetChars()); sc.AddMessageToLog(msg, 1); msg.Format("CurrentBarDateTime_PT: %s", GetDateTimeString(CurrentBarDateTime_PT).GetChars()); sc.AddMessageToLog(msg, 1); SCDateTime CurrentBarDateTime_ChartTime = sc.ConvertDateTimeToChartTimeZone(CurrentBarDateTime_PT, TIMEZONE_LOS_ANGELES); msg.Format("CurrentBarDateTime_PT --> CurrentBarDateTime_ChartTime: %s", GetDateTimeString(CurrentBarDateTime_ChartTime).GetChars()); sc.AddMessageToLog(msg, 1); msg.Format("RTH_Open_Time_PT: %s", GetDateTimeString(RTH_Open_Time_PT).GetChars()); sc.AddMessageToLog(msg, 1); SCDateTime RTH_Open_Time_ChartTime = sc.ConvertDateTimeToChartTimeZone(RTH_Open_Time_PT, TIMEZONE_LOS_ANGELES); msg.Format("RTH_Open_Time_PT --> RTH_Open_Time_ChartTime: %s", GetDateTimeString(RTH_Open_Time_ChartTime).GetChars()); sc.AddMessageToLog(msg, 1); } |