Support Board
Date/Time: Mon, 18 May 2026 23:40:02 +0000
[User Discussion] - Study for Holiday Reminder
View Count: 227
| [2026-04-03 18:16:34] |
| Tony - Posts: 715 |
|
I wrote a study for holiday reminder, so you will never have to worry that you would forget a holiday when market is closed (or close early), it reminds you on the holiday and one day ahead. i.e. it would say "Market closed on Friday Chicago time" yesterday and today (I am writing this message on Good Friday), it will display "Market closed at [your local time] [your local date]" if there will be an early close (i.e. Thanksgiving) In case you need instructions on how to build custom studies from source code, here is the link: How to Build an Advanced Custom Study from Source Code #include "sierrachart.h" SCDLLName("HolidayCheck") 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==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 || Month==7 && Day==4 && WeekDay>0 || 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; } SCSFExport scsf_TemplateFunction(SCStudyInterfaceRef sc) { if (sc.SetDefaults) { sc.GraphName = "Holiday Check"; sc.GraphRegion = 0; sc.AutoLoop = 1; sc.UpdateAlways = 1; sc.Input[0].Name = "Vertical Position"; sc.Input[0].SetInt(92); sc.Input[1].Name = "Horizontal Position"; sc.Input[1].SetInt(120); sc.Input[2].Name = "Font Size"; sc.Input[2].SetInt(12); sc.Input[3].Name = "Font Color"; sc.Input[3].SetColor(127,127,255); sc.Input[4].Name = "Flash Message"; sc.Input[4].SetYesNo(0); return; } SCDateTime ChicagoCurrentTime = sc.ConvertDateTimeFromChartTimeZone(sc.CurrentSystemDateTime, TIMEZONE_CHICAGO); SCDateTime ChicagoEarlyCloseTime {ChicagoCurrentTime}; int CheckToday {HolidayCheck(ChicagoCurrentTime)}; int CheckTomorrow {HolidayCheck(ChicagoCurrentTime + SCDateTime::DAYS(1))}; if (CheckTomorrow==1 || CheckTomorrow==2) ChicagoEarlyCloseTime = ChicagoCurrentTime + SCDateTime::DAYS(1); ChicagoEarlyCloseTime.SetTime(12 * 3600); SCDateTime LocalEarlyCloseTime {sc.ConvertDateTimeToChartTimeZone(ChicagoEarlyCloseTime, TIMEZONE_CHICAGO)}; SCString MessageString {""}; MessageString.Format("\n"); if (CheckToday==1 || CheckTomorrow==1) MessageString.AppendFormat("Market closed on %s Chicago Time\n\n", SHORT_NAME_FOR_DAY_OF_WEEK[ChicagoEarlyCloseTime.GetDayOfWeek()]); if (CheckToday==2 || CheckTomorrow==2) MessageString.AppendFormat( "Market closed at %d %s, %s %d\n\n", LocalEarlyCloseTime.GetHour(), LocalEarlyCloseTime.GetHour()<12 ? "am" : "pm", SHORT_NAME_FOR_MONTH[LocalEarlyCloseTime.GetMonth()], LocalEarlyCloseTime.GetDay() ); if (!(sc.CurrentSystemDateTime.GetSecond()%5) && sc.Input[4].GetYesNo()) MessageString.Format("\n"); s_UseTool Tool; Tool.Clear(); Tool.ChartNumber = sc.ChartNumber; Tool.LineNumber = 74191; Tool.DrawingType = DRAWING_TEXT; Tool.UseRelativeVerticalValues = 1; Tool.BeginDateTime = sc.Input[1].GetInt(); Tool.EndDateTime = sc.Input[1].GetInt(); Tool.BeginValue = sc.Input[0].GetInt(); Tool.EndValue = sc.Input[0].GetInt(); Tool.FontSize = sc.Input[2].GetInt(); Tool.Color = sc.Input[3].GetColor(); Tool.AddMethod = UTAM_ADD_OR_ADJUST; Tool.Text = MessageString; sc.UseTool(Tool); } Date Time Of Last Edit: 2026-04-10 17:11:29
|
| [2026-04-03 18:23:17] |
| AlgoAlpha_1 - Posts: 10 |
|
Nice!
|
To post a message in this thread, you need to log in with your Sierra Chart account:
