Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

How to check that a datetime is Holiday or Weekend ?

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    How to check that a datetime is Holiday or Weekend ?

    Hi,

    In my indicator code, I need to add a logic to check for Holiday and Weekends for given date. How to do that ? I need your help.

    #2
    Hello nandhumca,

    Are you wanting this based on the TradingHours template?

    You can loop through the trading hours sessions to know the date.


    And holidays.


    You can compare any DateTime.DayOfWeek to DayOfWeek.Saturday or DayOfWeek.Sunday.

    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Hi Chelsea,

      I dont want based on TradingHours Template. For given dateTime, I want to know that is that Holiday or Not . If you have any sample code, kindly share it.
      Last edited by nandhumca; 08-30-2021, 08:37 AM.

      Comment


        #4
        Hello nandhumca,

        The second link is how to find holidays. Did you copy the code from the help guide into a script test and found the resulting print is insufficient?

        You can compare the holiday.Date to any other DateTime object.


        If you mean you don't want to follow the holidays set in the TradingHours template, you want some custom C# code that arbitrarily lists holidays in your part of the world, this would be something you have to custom build.

        Below is a link to a google search of 'C# date is holiday' which returns some pretty good results.
        Chelsea B.NinjaTrader Customer Service

        Comment


          #5
          Hi Chelsea,

          I tried to see what values it holds. It is not listing all the Holidays . Below is the output.

          Code:
           foreach(KeyValuePair<DateTime, string> holiday in TradingHours.Holidays)
          {
          Print(holiday);
          }
          [12/25/2015 12:00:00 AM, Christmas Day]
          [1/1/2016 12:00:00 AM, New Year's Day]
          [3/25/2016 12:00:00 AM, Good Friday]
          [12/26/2016 12:00:00 AM, Christmas Day]
          [1/2/2017 12:00:00 AM, New Year's Day]
          [4/14/2017 12:00:00 AM, Good Friday]
          [12/25/2017 12:00:00 AM, Christmas Day]
          [1/1/2018 12:00:00 AM, New Year's Day]
          [3/30/2018 12:00:00 AM, Good Friday]
          [12/25/2018 12:00:00 AM, Christmas Day]
          [1/1/2019 12:00:00 AM, New Year's Day]
          [4/19/2019 12:00:00 AM, Good Friday]
          [12/25/2019 12:00:00 AM, Christmas Day]
          [1/1/2020 12:00:00 AM, New Year's Day]
          [4/10/2020 12:00:00 AM, Good Friday]
          [12/25/2020 12:00:00 AM, Christmas Day]
          [1/1/2021 12:00:00 AM, New Year's Day]
          [12/24/2021 12:00:00 AM, Christmas Eve]

          Comment


            #6
            Hello nandhumca,

            What TradingHours template is being used?
            Print(TradingHours.Name);

            May I have a screenshot of the Trading Hours window showing the trading hours template with that name with the holidays in view?
            Chelsea B.NinjaTrader Customer Service

            Comment


              #7
              Below is the output of Print(TradingHours.Name); Attached the trading hour window.

              CME US Index Futures ETH
              Attached Files

              Comment


                #8
                Hello nandhumca,

                Apologies, I gave an incomplete answer.

                Those are the full holidays for this template.

                There is also a TradingHours.PartialHolidays for holidays that don't take up the full day.
                Chelsea B.NinjaTrader Customer Service

                Comment


                  #9
                  Np. Thanks. 11/25/2021 12:00:00 AM is Saturday. Why it is showing that as partial holiday. If it is partial holiday, will there be any trading happens? if so, how to get the full Holiday list ?

                  Comment


                    #10
                    Hello nandhumca,

                    This would be in the Central time zone for the exchange. I am seeing an early close for 11/26 2015 in the screenshot (showing you have not modified this) which is a Thursday.

                    What date and time is 11/25 at 12:00 when converted to the central time zone?

                    There will be no trading during the full and partial holidays during the time listed in the TradingHours template.

                    You can get the list of full holidays by looping through TradingHours.Holidays. You can get the list of partial holidays by looping through TradingHours.PartialHolidays. You can loop through both to get both.
                    Last edited by NinjaTrader_ChelseaB; 08-30-2021, 12:40 PM.
                    Chelsea B.NinjaTrader Customer Service

                    Comment

                    Latest Posts

                    Collapse

                    Topics Statistics Last Post
                    Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                    0 responses
                    579 views
                    0 likes
                    Last Post Geovanny Suaza  
                    Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                    0 responses
                    334 views
                    1 like
                    Last Post Geovanny Suaza  
                    Started by Mindset, 02-09-2026, 11:44 AM
                    0 responses
                    101 views
                    0 likes
                    Last Post Mindset
                    by Mindset
                     
                    Started by Geovanny Suaza, 02-02-2026, 12:30 PM
                    0 responses
                    554 views
                    1 like
                    Last Post Geovanny Suaza  
                    Started by RFrosty, 01-28-2026, 06:49 PM
                    0 responses
                    551 views
                    1 like
                    Last Post RFrosty
                    by RFrosty
                     
                    Working...
                    X