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

GetNextExpiry not working as expected

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

    GetNextExpiry not working as expected

    As of today, January 23 2019, the following code returns "01-19" which is not a valid expiry for the ES futures contract.

    What is the correct way to get the expiry date for the front month contract?

    Instrument eq = Instrument.GetInstrument("ES");
    string ds = eq.MasterInstrument.GetNextExpiry(DateTime.Now).To String("MM-yy");
    Print(ds);

    #2
    Hello Ricam,
    Thanks for your note.

    That code is referencing the "ES" stock. Futures contracts are all viewed as their own individual instruments inside the NinjaTrader database (ie. "ES 03-19" and "ES 06-19" are different instruments) so you would need to include the expiry as well to us GetInstrument(). This may look something like:
    Code:
    Instrument eq = Instrument.GetInstrument("ES 03-19");

    If you simply want to get the expiry of the current Bars object you can use something like the following:
    Code:
    Bars.Instrument.MasterInstrument.GetNextExpiry(DateTime.Now).ToString("MM-yy")
    Josh G.NinjaTrader Customer Service

    Comment


      #3
      That completely misses the point of what I am so obviously trying to do which is simply to programatically find the front month of a futures contract from its two character symbol. How can I enter the expiry as an argument of GetInstrument when the whole purpose is to determine what that expiry is???

      Meanwhile the help guide entry specifically says that GetExpiry applies to FUTURES CONTRACTS. The way it works now seems to be totally useless.

      What about getting the next closest date greater than today from the Rollover collection, would that work and how would it be done? Or does that also require already knowing in advance the answer to the question that I am trying to answer?

      Obviously the front month is available since the database management applet can update it automatically.
      Last edited by Ricam; 01-24-2019, 10:22 AM.

      Comment


        #4
        Ricam,

        If you want to pull the next closest expiration you will need to pass in the date time for when that would be the front month instead of DateTime.Now
        Josh G.NinjaTrader Customer Service

        Comment


          #5
          That isn't right, either. It also presupposes foreknowledge of the answer to the question. All I want to do is complete the correct front month Instrument Full Name for TODAY's date.

          What does seem to work is passing in the FullName of an expired contract along with TODAY'S date time. The following code returns "03-19" as the value of ds, which is correct as of the date of this post.

          Instrument eq = Instrument.GetInstrument("ES 06-18");
          string ds = " "+eq.MasterInstrument.GetNextExpiry(DateTime.N ow). ToString("MM-yy");
          Last edited by Ricam; 01-24-2019, 03:36 PM.

          Comment


            #6
            If I put the VALID FullName of ANY Futures Contract, past, present or future, into GetExpiry, it does seem to return the correct front month. It works with ES 06-20, ES 09-18, ZB 12-18, etc. I suggest revising the example in the Help Guide to reflect this.
            Last edited by Ricam; 01-24-2019, 03:37 PM.

            Comment


              #7
              Ricam,

              Thanks for your input. I will pass that along.
              Josh G.NinjaTrader Customer Service

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by junkone, Today, 11:37 AM
              0 responses
              1 view
              0 likes
              Last Post junkone
              by junkone
               
              Started by quantismo, 04-17-2024, 05:13 PM
              5 responses
              33 views
              0 likes
              Last Post NinjaTrader_Gaby  
              Started by proptrade13, Today, 11:06 AM
              1 response
              5 views
              0 likes
              Last Post NinjaTrader_Clayton  
              Started by love2code2trade, 04-17-2024, 01:45 PM
              4 responses
              34 views
              0 likes
              Last Post love2code2trade  
              Started by cls71, Today, 04:45 AM
              2 responses
              10 views
              0 likes
              Last Post eDanny
              by eDanny
               
              Working...
              X