Support Board
Date/Time: Sat, 12 Jul 2025 05:49:06 +0000
Post From: EOD or holiday detection for auto trading?
[2025-07-01 05:51:34] |
Tony - Posts: 611 |
@User316362 You probably already figured it out, just in case, if you still need a function to detect holidays, I recently wrote a function, given a SCDateTime, return values: 0: Normal situation, market open from Sun.6pm to Fri.6pm Eastern 1: Market Closed 2: Market Open until 13:00 Eastern if you live in Eastern time zone, you could add SCDateTime::HOURS(6) to the variable "InputDateTime", then the detection is based on sessions, instead of calendar days, that might be a better solution. int HolidayCheck(SCDateTime InputDateTime) { int year = InputDateTime.GetYear(); int GF_Day {0}; int GF_Month {0}; int g = (int)(year % 19); int c = (int)(year / 100); int h = (int)((c - (int)(c / 4) - (int)((8 * c + 13) / 25) + 19 * g + 15) % 30); int i = h - (int)(h / 28) * (1 - (int)(h / 28) * (int)(29 / (h + 1)) * (int)((21 - g) / 11)); GF_Day = i - (int)((year + (int)(year / 4) + i + 2 - c + (int)(c / 4)) % 7) + 26; GF_Month = 3; if (GF_Day > 31) { GF_Month++; GF_Day -= 31; } int Month {InputDateTime.GetMonth()}; int Day {InputDateTime.GetDay()}; int WeekDay {InputDateTime.GetDayOfWeek()}; int ReturnValue {0}; if (WeekDay != 6) { if ( Month==1 && Day==1 || Month==1 && Day==2 && WeekDay==1 || Month==GF_Month && Day==GF_Day || Month==7 && Day==4 || Month==11 && WeekDay==4 && Day>21 && Day<=28 || Month==12 && Day==25 || Month==12 && Day==24 && WeekDay==5 || Month==12 && Day==26 && WeekDay==1 ) ReturnValue = 1; if ( Month==1 && WeekDay==1 && Day>14 && Day<=21 || Month==2 && WeekDay==1 && Day>14 && Day<=21 || Month==5 && WeekDay==1 && Day+7>31 || Month==6 && Day==19 || Month==6 && Day==18 && WeekDay==5 || Month==6 && Day==20 && WeekDay==1 || Month==7 && Day==3 && WeekDay>0 && WeekDay<6 || Month==7 && Day==5 && WeekDay==1 || Month==9 && WeekDay==1 && Day<=7 || Month==11 && WeekDay==5 && Day-1>21 && Day-1<=28 || Month==12 && Day==24 && WeekDay>0 && WeekDay<5 ) ReturnValue = 2; } return ReturnValue; } Date Time Of Last Edit: 2025-07-01 07:04:44
|