Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Displayin the second front month?

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

    Displayin the second front month?

    Hi,

    I understand that we can neatly get the front futures month a couple of ways, by either using the Merge function or (on a chart) using the notation e.g. "NQ ##-##".

    However, is there a way to elegantly get the *second* front month contract, either using NinjaScript or some other way?

    Thanks!

    James

    #2
    Hello James,

    Thanks for opening the thread.

    Could you provide me a bit more information on what you would like to do exactly?

    Do you want to isolate 1 previous contract month when viewing the continuous contract month, or do you want to have all previous contract months take precedence over the next contract month?

    What do you want to do with this data? Do you want to display it on a chart and use those values like a regular data series, or do you want to create a custom Series<double> that holds these values so you can use it for calculation in an indicator? The former is possible but will be much more complicated than the latter.

    I look forward to assisting further.
    JimNinjaTrader Customer Service

    Comment


      #3
      The first of what you suggest "display it on a chart" would be helpful.
      But ultimately, I need a custom Series <double>.

      Ultimately, I would like to create an indicator that is calculated from the 1st and 2nd month futures prices. For this, I would need the time series of the continuous front month (e.g from Merge(?)). Next, I would need a continuous time series with the second month, e.g. rolling in the same way that the 1st month continuous contract does.

      Thanks for the help!

      Comment


        #4
        Hello James,

        Thanks for clearing that up for me.

        You will need to use a BarsRequest to request a desired amount of data for a given period of time. This would allow you to pull in the data for the time period you are looking for from the previous contract months. You can then sort that data as you see fit.

        With this data downloaded and sorted, you could then write it to a file, or store it to a custom Series<double>.

        With the data written to a file, you could then parse that recorded data in a custom BarType within OnDataPoint() to have that data plot on a chart when you match the front month, bar type and lookback period. You would just have the BarType pull information from the data you have stored. You could use a custom AddOn to perform the BarsRequests, sort the data and write to file. Then a custom BarType could load that alternate data in OnDataPoint().

        If you wish to enclose this in an indicator to keep the process simple, you could do the BarsRequests in an indicator and loop through a Series<double> that has been synchronized with the primary data series to assign your own values. You could then use the primary data series and your series double within that indicator to perform the calculations you need.

        BarsRequests are documented here: http://ninjatrader.com/support/helpG...arsrequest.htm

        Attached is an example of a BarsRequest applied to an indicator.

        Documentation on creating custom bar types can be found here: https://ninjatrader.com/support/help.../bars_type.htm

        Please let me know if I may be of further assistance.
        Attached Files
        JimNinjaTrader Customer Service

        Comment


          #5
          Is there a way to get a list of contract months?
          For example, when clicking through the GUI, I can get the Instruments->Instrument->Contract months

          Can I get this list via script?
          That would be a great start.

          Comment


            #6
            Hello AntiMatter,

            Yes, you can get the rollover dates and associated contract month by looping through the RolloverCollection. The ContractMonth property is a DateTime object and will have to be converted if you want it in expiry format.

            Code:
            foreach (var rollover in Bars.Instrument.MasterInstrument.RolloverCollection)
            {
                Print("Contract Month: " + rollover.ContractMonth.ToString());
                Print("Date: " + rollover.Date.ToString());
                Print("Offset: " + rollover.Offset.ToString());
            }
            RolloverCoillection - https://ninjatrader.com/support/help...collection.htm

            Please let me know if I may be of further assistance.
            JimNinjaTrader Customer Service

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by Mestor, 03-10-2023, 01:50 AM
            16 responses
            388 views
            0 likes
            Last Post z.franck  
            Started by rtwave, 04-12-2024, 09:30 AM
            4 responses
            31 views
            0 likes
            Last Post rtwave
            by rtwave
             
            Started by yertle, Yesterday, 08:38 AM
            7 responses
            29 views
            0 likes
            Last Post yertle
            by yertle
             
            Started by bmartz, 03-12-2024, 06:12 AM
            2 responses
            22 views
            0 likes
            Last Post bmartz
            by bmartz
             
            Started by funk10101, Today, 12:02 AM
            0 responses
            7 views
            0 likes
            Last Post funk10101  
            Working...
            X