• If this is your first visit, you will have to register before you can post. To view messages, please scroll below and select the forum that you would like to visits. Questions? Be sure to check out the Forum FAQ.

Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

trading days vs calendar days

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

    trading days vs calendar days

    hi,

    Is there an easy way to count actual trading days on a forward looking basis ?

    So for example, S&P 500 e-mini trades 1700 to 1615, starting on Sunday night

    I'd like to be able to easily make the following computations :
    Mon 7 Jan 13 17:15 + 3 trading days = Thu 10 Jan 13 17:15 [i.e. 72 hours later]
    Tue 9 Jan 13 17:15 + 3 trading days = Sun 13 Jan 13 17:15 [i.e. treat the Sunday open as if it were right after the Friday close]
    Wed 9 Jan 13 12:00 + 3 trading days = Mon 14 Jan 13 12:00
    Mon 30 Dec 12 12:00 + 3 trading days = Fri 4 Jan 13 12:00 [i.e. take into account the New Year's holiday]

    I can't find such a functionality, and I don't want to have to make tables in Excel that have to get looked up. Doesn't NT already have the products calendars built in (with holidays?) and is there a way of accessing that to count trading days forwards ?

    I started programming something, but then I get thrown off by trying to make something that adapts to those weekend rules correctly. I also would need to make a table of holidays for each relevant contract, which is a nightmare.

    Alternatively, is there a way to get whether a forward date is within the trading horus of a contract ? I could always make a loop that counts days and checks whether it's in trading hours and then count again if needed. I can't find that either. I don't mind the performance hit on that, as this computation doesn't need to be performed frequently.

    Thanks
    Andrew

    #2
    Hello,

    NinjaTrader uses session templates to determine trading hours for a given Instrument.

    You can view the defined hours by going to Tools -> session manager -> select the template in question.

    Specifically the ES uses the templates CME US Index Futures ETH by default but many traders allso use CME US Index Futures RTH (Electronic Trading and Regular Trading Hours)

    Be aware these hours have changed recently and if you haven't done so already may need to be updated on your end: http://www.ninjatrader.com/Advisory/Advisory12.php

    In terms of holiday trading you will have to manually filter out these days if you wish to not trade on them.

    An example of how you might filter labor day. I used to use this for backtesting but you would want to remove it from a live strategy as this is performing unnecessary checks
    Code:
                //Labor
                if (ToDay(Time[0]) == 19990906 || 
                    ToDay(Time[0]) == 20000904 || 
                    ToDay(Time[0]) == 20010903 || 
                    ToDay(Time[0]) == 20020902 || 
                    ToDay(Time[0]) == 20030901 || 
                    ToDay(Time[0]) == 20040906 || 
                    ToDay(Time[0]) == 20050905 || 
                    ToDay(Time[0]) == 20060904 ||
                    ToDay(Time[0]) == 20070903  || 
                    ToDay(Time[0]) == 20080901  || 
                    ToDay(Time[0]) == 20090907  || 
                    ToDay(Time[0]) == 20100906  || ToDay(Time[0]) == 20110905)
                {
                    return;
                }
    http://www.ninjatrader.com/support/h...ries_class.htm

    Please let me know if I can be of further assistance.
    LanceNinjaTrader Customer Service

    Comment


      #3
      hi Lance,

      Thanks for this. Is there an easy way to access the detaisl of the session from within the NinjaScript ? Something along the lines of a function that indicates whether a Datetime input is a valid trading day and time would be helpful in this case. I'm aware there is a way to access the current session's start and end times, but that isn't going to be immediately helpful.

      I want to avoid having to hard code anything to do with the instrument as much as possible and refer to the data of the instrument itself.

      Thank you for the update wrt trading times for the CME, i hadn't yet done that.

      Thanks
      AS

      Comment


        #4
        Hello,

        There aren't any pre-built functions for doing this but you could do a check to ensure the current time is between the sessions begin/end.

        //pseudo code
        if ToTime(Time[0]) > SessionEnd && ToTime(Time[0]) < SessionBegin
        http://www.ninjatrader.com/support/h...ml?session.htm

        However you shouldn't need to do this unless you're working with a multi-timeframe indicator/strategy as the OnBarUpdate() is only called when a new bar is closed. You won't have bars closing outside of the session template.

        Let me know if I can be of further assistance.
        LanceNinjaTrader Customer Service

        Comment


          #5
          Originally posted by curmudgeon View Post
          hi,

          Is there an easy way to count actual trading days on a forward looking basis ?

          So for example, S&P 500 e-mini trades 1700 to 1615, starting on Sunday night

          I'd like to be able to easily make the following computations :
          Mon 7 Jan 13 17:15 + 3 trading days = Thu 10 Jan 13 17:15 [i.e. 72 hours later]
          Tue 9 Jan 13 17:15 + 3 trading days = Sun 13 Jan 13 17:15 [i.e. treat the Sunday open as if it were right after the Friday close]
          Wed 9 Jan 13 12:00 + 3 trading days = Mon 14 Jan 13 12:00
          Mon 30 Dec 12 12:00 + 3 trading days = Fri 4 Jan 13 12:00 [i.e. take into account the New Year's holiday]

          I can't find such a functionality, and I don't want to have to make tables in Excel that have to get looked up. Doesn't NT already have the products calendars built in (with holidays?) and is there a way of accessing that to count trading days forwards ?

          I started programming something, but then I get thrown off by trying to make something that adapts to those weekend rules correctly. I also would need to make a table of holidays for each relevant contract, which is a nightmare.

          Alternatively, is there a way to get whether a forward date is within the trading horus of a contract ? I could always make a loop that counts days and checks whether it's in trading hours and then count again if needed. I can't find that either. I don't mind the performance hit on that, as this computation doesn't need to be performed frequently.

          Thanks
          Andrew
          Use a while loop with an internal counter that only advances if it is not a weekend day.

          Comment


            #6
            Originally posted by koganam View Post
            Use a while loop with an internal counter that only advances if it is not a weekend day.
            hi Koganam,

            That's what I've initially implemented, but I get thrown off by two things :
            1/ holidays (there must be a more elegant solution than making a list of soon ones and having it read in during initialization of the strategy)
            2/ many futures (plus FX) trade starting Sunday night. So Thursday after open + 1 day = Sunday night, but Friday midday + 1 day = Monday night

            2 is easy enough to get around so long as you make that a parameter in the input of the script, but I was hoping for a more elegant fix using the in-built trading session templates, otherwise maintenance would become a nuisance.

            1 is potentially bigger pain, as I'm now testing reparametrizing an existing strategy on to Eurex listed products which not only has different holidays than the USA, but has different holidays for different products.

            Comment


              #7
              Originally posted by curmudgeon View Post
              hi Koganam,

              That's what I've initially implemented, but I get thrown off by two things :
              1/ holidays (there must be a more elegant solution than making a list of soon ones and having it read in during initialization of the strategy)
              Unfortunately not. There is a script somewhere on this forum that made a function that lists them, so that one only needs update the list for coming years.

              Ref: http://www.ninjatrader.com/support/f...d.php?p=140164

              Look at post #3 by kdoren.
              2/ many futures (plus FX) trade starting Sunday night. So Thursday after open + 1 day = Sunday night, but Friday midday + 1 day = Monday night
              Should not be an issue. Your while loop checks if the day is Sunday, then checks the session template to see if it is a valid bar, which it should be, as there should be no bars outside the session template. No need to check on weekdays.
              2 is easy enough to get around so long as you make that a parameter in the input of the script, but I was hoping for a more elegant fix using the in-built trading session templates, otherwise maintenance would become a nuisance.

              1 is potentially bigger pain, as I'm now testing reparametrizing an existing strategy on to Eurex listed products which not only has different holidays than the USA, but has different holidays for different products.
              Unfortunately, nothing can be done about the holiday issue, other than the inelegant list method. I am waiting to see whether NT8 will solve this one for us.

              Comment


                #8
                Thanks, Koganam

                NT team, could you pls add another vote for having the holiday calendar well integrated into the next version ?

                Also, one thing I've noted is that it can be really painful (and error prone) to enter in unsupported contracts. What would be helpful would be two things :
                1/ rollover templates the same way you have session templates for futures, so that contracts that share the same calendar can be set up without having to manually do each one's own calendar.
                2/ a way to do batch imports of futures and not just stocks (i.e. with relevant session info and calendar expiry info), as well as data vendor tickers. Even if this has to be manually set up with a spreadsheet, being able to do it that way would be a lot easier than doing the current method.

                Thank you

                Comment


                  #9
                  Hello,
                  Originally posted by curmudgeon View Post
                  NT team, could you pls add another vote for having the holiday calendar well integrated into the next version ?

                  1/ rollover templates the same way you have session templates for futures, so that contracts that share the same calendar can be set up without having to manually do each one's own calendar.

                  2/ a way to do batch imports of futures and not just stocks (i.e. with relevant session info and calendar expiry info), as well as data vendor tickers. Even if this has to be manually set up with a spreadsheet, being able to do it that way would be a lot easier than doing the current method.
                  I will have all three of these submitted and let you know when they have been logged.

                  Please let me know if I can be of further assistance.
                  LanceNinjaTrader Customer Service

                  Comment


                    #10
                    Originally posted by curmudgeon View Post
                    NT team, could you pls add another vote for having the holiday calendar well integrated into the next version ?
                    This has been logged and added to ID #956
                    1/ rollover templates the same way you have session templates for futures, so that contracts that share the same calendar can be set up without having to manually do each one's own calendar.
                    2/ a way to do batch imports of futures and not just stocks (i.e. with relevant session info and calendar expiry info), as well as data vendor tickers. Even if this has to be manually set up with a spreadsheet, being able to do it that way would be a lot easier than doing the current method.
                    Have both been added to ID #128

                    Please let me know if I can be of further assistance.
                    LanceNinjaTrader Customer Service

                    Comment

                    Latest Posts

                    Collapse

                    Topics Statistics Last Post
                    Started by ttodua, Today, 01:12 AM
                    0 responses
                    1 view
                    0 likes
                    Last Post ttodua
                    by ttodua
                     
                    Started by NinjaCustomer, Today, 01:01 AM
                    0 responses
                    3 views
                    0 likes
                    Last Post NinjaCustomer  
                    Started by mohdqallaf, Today, 12:55 AM
                    0 responses
                    3 views
                    0 likes
                    Last Post mohdqallaf  
                    Started by dvcpro4, Yesterday, 07:08 PM
                    2 responses
                    26 views
                    0 likes
                    Last Post NT-Roland  
                    Started by chrismcdermut, Yesterday, 01:46 PM
                    3 responses
                    19 views
                    0 likes
                    Last Post MojoJojo  
                    Working...
                    X