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.
    <span class="name">Brandon H.</span><span class="title">NinjaTrader Customer Service</span><iframe name="sig" id="sigFrame" src="/support/forum/core/clientscript/Signature/signature.php" frameborder="0" border="0" cellspacing="0" style="border-style: none;width: 100%; height: 120px;"></iframe>

    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.
        <span class="name">Brandon H.</span><span class="title">NinjaTrader Customer Service</span><iframe name="sig" id="sigFrame" src="/support/forum/core/clientscript/Signature/signature.php" frameborder="0" border="0" cellspacing="0" style="border-style: none;width: 100%; height: 120px;"></iframe>

        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 go2toa, 09-14-2024, 05:43 AM
          2 responses
          19 views
          0 likes
          Last Post go2toa
          by go2toa
           
          Started by scrapsalll, Today, 09:22 PM
          0 responses
          9 views
          0 likes
          Last Post scrapsalll  
          Started by aligator, 06-22-2022, 01:10 PM
          14 responses
          1,919 views
          0 likes
          Last Post diegomezhur  
          Started by ceebeetrader, Yesterday, 06:01 PM
          2 responses
          16 views
          0 likes
          Last Post ceebeetrader  
          Started by Aviram Y, 03-22-2023, 04:44 AM
          4 responses
          186 views
          0 likes
          Last Post defa0009  
          Working...
          X