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

How to get front contracts dates?

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

    How to get front contracts dates?

    I have list of futures like this:
    NQ,CL,GC

    I need to convert it into front contracts:
    NQ 03-22,CL 03-22,GC 04-22

    Would be great if it can be done via NinjaScript.
    Thanks.

    #2
    Hello Leeroy_Jenkins,

    Thanks for your post.

    If you are trying to add additional data series to a custom NinjaScript, you could do so by calling AddDataSeries() and specifying the instrument and contract date of the instrument. For example, see below.

    //Add a 5-minute series for NQ 03-22 instrument
    AddDataSeries("NQ 03-22", BarsPeriodType.Minute, 5);

    See this help guide documentation for more information: https://ninjatrader.com/support/help...dataseries.htm

    Note that there are no documented means for converting, for example, NQ to NQ 03-22

    Let us know if we may assist further.
    Brandon H.NinjaTrader Customer Service

    Comment


      #3
      I'm trying to make list of symbols that I'm gonna trade. Because this list changes a few times in a week, I though it would be great if NT just parses from file my symbols.

      Note that there are no documented means for converting, for example, NQ to NQ 03-22
      That's the problem. Even though it's possible to access to contract rollovers via RolloverCollection, there is no way to get current front contracts.

      Or If I try to import symbols manually it doesn't convert NQ to NQ 03-22.

      And there is no way to create instrument list via NinjaScript.

      Dead end.

      Comment


        #4
        Hello Leeroy_Jenkins,

        Thanks for your note.

        It might be possible through unsupported code to add an entire instrument list through the code. However, this would break the warning we provide in the Help Guide linked and listed below.

        As stated in the AddDataSeries() help guide page: Arguments supplied to AddDataSeries() should be hardcoded and NOT dependent on run-time variables which cannot be reliably obtained during State.Configure (e.g., Instrument, Bars, or user input). Attempting to add a data series dynamically is NOT guaranteed and therefore should be avoided. Trying to load bars dynamically may result in an error.

        AddDataSeries(): https://ninjatrader.com/support/help...dataseries.htm

        This thread will be open for other forum community members to share their insight.

        Let us know if we may assist further.
        Brandon H.NinjaTrader Customer Service

        Comment


          #5
          You can use NinjaScript to determine the Instrument associated with the "Next Expiry" date of the MasterInstrument as follows:
          Code:
          string MasterName = "ES";    // For example
          Instrument CurrentContract = Instrument.GetInstrument(MasterName + Instrument.GetInstrument(MasterName+" ##-##").MasterInstrument.GetNextExpiry(DateTime.Now).ToString(" MM-yy"));
          Running this today produces ES 03-22.

          Hope that helps.

          Thanks.
          Multi-Dimensional Managed Trading
          jeronymite
          NinjaTrader Ecosystem Vendor - Mizpah Software

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by elirion, Today, 01:36 AM
          0 responses
          3 views
          0 likes
          Last Post elirion
          by elirion
           
          Started by gentlebenthebear, Today, 01:30 AM
          0 responses
          4 views
          0 likes
          Last Post gentlebenthebear  
          Started by samish18, Yesterday, 08:31 AM
          2 responses
          9 views
          0 likes
          Last Post elirion
          by elirion
           
          Started by Mestor, 03-10-2023, 01:50 AM
          16 responses
          391 views
          0 likes
          Last Post z.franck  
          Started by rtwave, 04-12-2024, 09:30 AM
          4 responses
          34 views
          0 likes
          Last Post rtwave
          by rtwave
           
          Working...
          X