Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

Partner 728x90

Collapse

Contract rollover date

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

    Contract rollover date

    Is there a way to retrieve the rollover date for a contract from NinjaScript?

    #2
    There is not a supported\documented method, but this information is readable from NinjaScript.

    Please see the following indicator which uses some of the concepts:

    MatthewNinjaTrader Product Management

    Comment


      #3
      Originally posted by NinjaTrader_Matthew View Post
      There is not a supported\documented method, but this information is readable from NinjaScript.

      Please see the following indicator which uses some of the concepts:

      http://www.ninjatrader.com/support/f...d=4&linkid=558
      Thanks for the code link Mathew, I'll give it a try!

      Comment


        #4
        Howdy--

        I fully understand that what I'm about to ask would be unsupported, however would it be plausible to think that using the exposed classes in the Rollover indicator (http://www.ninjatrader.com/support/f...ocal_links.php) that one might be able to surmise how to programmatically add expiries, rollover dates and offset values--as opposed to adding them manually via the Instrument Manger GUI?

        Thanks,

        Aventeren

        Comment


          #5
          Hello,

          I have to state it but what you are asking would not be supported at all.

          I am unsure if you could utilize the indicator in any manor to do what you are looking for, something you could look into is there is a file located in your install directory that holds instument information.

          rollover dates are stored in this file so in theory edit this file and reset your instruments. As far if this will work correctly I do not know this would be something you could try. As long as you make a backup of the original file you should be able to reset this. the file would be db\Instruments.txt in your install directory.

          Please let me know if i may be of additional assistance.
          JesseNinjaTrader Customer Service

          Comment


            #6
            Originally posted by NinjaTrader_Jesse View Post
            Hello,

            I have to state it but what you are asking would not be supported at all.

            I am unsure if you could utilize the indicator in any manor to do what you are looking for, something you could look into is there is a file located in your install directory that holds instument information.

            rollover dates are stored in this file so in theory edit this file and reset your instruments. As far if this will work correctly I do not know this would be something you could try. As long as you make a backup of the original file you should be able to reset this. the file would be db\Instruments.txt in your install directory.

            Please let me know if i may be of additional assistance.
            Thanks for pointing these out to me. This is exactly what I was looking for.

            Any idea if there is a similar .txt file where the offsets are stored?

            I clearly understand this whole exercise is unsupported, however I'll play around with adding new expiries (and hopefully offsets via another route) by amending the .txt file, and the I'll report back for the benefit of the other members.

            Thanks for your help.

            Aventeren
            Last edited by aventeren; 09-18-2014, 08:29 AM.

            Comment


              #7
              Hello,

              Thank you for the follow up.

              For offsets unfortunately there is no local file for this.

              Please let me know if I may be of additional assistance.
              JesseNinjaTrader Customer Service

              Comment


                #8
                Jesse--

                I'm starting to poke around with changing the Instruments text file in the Program files (db folder), but I'm getting an "Access is Denied" message after I modify the file and try to re-save (I'm just adding a new "12-59, 19590825" expiry and rollover date to the ZW line per the formatting instructions in the file).

                Any ideas?

                Thanks,

                Aventeren

                Comment


                  #9
                  Hello,

                  It sounds like you may not have permission to write to the directory. You can try to copy the file to your desktop and modify it then copy it back. Also please note this file gets replaced every time you run the installer.

                  I look forward to being of further assistance.
                  JesseNinjaTrader Customer Service

                  Comment


                    #10
                    Calculate Actual Contract Expiry Date

                    I wrote this code to get the actual contract expiry date. 7 days before the Triple Witching Hour this code switches to the next contract. It can be adapted according personal preferences:

                    Code:
                    [FONT="Courier New"][SIZE="2"]
                    // get the current contract
                    // return 7 days before the rollover the next contract
                    DateTime dtToday = DateTime.Now;
                    
                    int iYearBase = dtToday.Year;
                    int iYearContract = iYearBase;
                    int iMonthBase = dtToday.Month;
                    int iMonthContract = ( ( iMonthBase - 1 ) / 3 ) * 3 + 3;
                    
                    DateTime dt3rdFriday = GetDateByOrdinalDay(iYearBase, iMonthContract, DayOfWeek.Friday, 3);
                    if ( dt3rdFriday.Subtract(dtToday).TotalDays < 7 )
                    {
                       // when the rollover date is in less than 7 days or it was already
                       // --> switch to the next expiry date
                       iMonthContract += 3;
                       if ( iMonthContract > 12 )
                       {
                          // we are in the next year
                          iMonthContract = 3;
                          iYearContract++;
                       }
                    }
                    // iMonthContract has the month and iYearContract the year of the current future contract[/SIZE][/FONT]
                    This is the function to calculate the 3rd Friday of a month:

                    Code:
                    [FONT="Courier New"][SIZE="2"]
                    /// <summary>
                    /// returns the date of a x-th week day in a month.
                    /// </summary>
                    /// <param name="iYear">The year to calculate for</param>
                    /// <param name="iMonth">The month to calculate for</param>
                    /// <param name="dayOfWeek">The day of week to find</param>
                    /// <param name="iOrdinal">The instance of the day of week to find</param>
                    /// <returns>The resulting DateTime</returns>
                    //-------------------------------------------------------------------------------------------
                    public DateTime GetDateByOrdinalDay(int iYear, int iMonth, DayOfWeek dayOfWeek, int iOrdinal)
                    //-------------------------------------------------------------------------------------------
                    {
                       DateTime Month1stDayOfWeek = new DateTime(iYear, iMonth, 1);
                       // for negative ordinal it must be adjusted
                       int iOrdinalAdjust = iOrdinal < 0 ? 1 : 0;
                       // Convert Sunday explicitly to 7
                       int iMonth1stDayOfWeek = (Month1stDayOfWeek.DayOfWeek == DayOfWeek.Sunday) ? 
                                     7 : 
                                     (int) Month1stDayOfWeek.DayOfWeek;
                       // calculate the initial difference between the requested day and the 1st day of the month
                       int iDayOffset = (int) dayOfWeek - iMonth1stDayOfWeek;
                       // let the music play
                       return Month1stDayOfWeek.AddDays
                                (
                                    iDayOffset + 
                                    ( iOrdinal + iOrdinalAdjust - (iDayOffset < 0 ? 0 : 1) ) * 7
                                );
                    }[/SIZE][/FONT]
                    Last edited by AlBundy; 04-10-2015, 04:13 AM.

                    Comment

                    Latest Posts

                    Collapse

                    Topics Statistics Last Post
                    Started by smartromain, 03-13-2024, 01:42 AM
                    5 responses
                    92 views
                    0 likes
                    Last Post AndreiBig  
                    Started by Noerclou, Today, 04:55 AM
                    0 responses
                    4 views
                    0 likes
                    Last Post Noerclou  
                    Started by llanqui, Yesterday, 09:59 AM
                    2 responses
                    17 views
                    0 likes
                    Last Post llanqui
                    by llanqui
                     
                    Started by ThoriSten, Today, 03:56 AM
                    0 responses
                    6 views
                    0 likes
                    Last Post ThoriSten  
                    Started by PhillT, 04-19-2024, 02:16 PM
                    3 responses
                    25 views
                    0 likes
                    Last Post mangel2000  
                    Working...
                    X