• If this is your first visit, you will have to register before you can post. To view messages, please scroll below and select the forum that you would like to visits. Questions? Be sure to check out the Forum FAQ.

Announcement

Collapse
No announcement yet.

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")
    JoshNinjaTrader 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, 09: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
        JoshNinjaTrader 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, 02: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, 02:37 PM.

            Comment


              #7
              Ricam,

              Thanks for your input. I will pass that along.
              JoshNinjaTrader Customer Service

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by TikDaddy, Today, 02:08 PM
              2 responses
              7 views
              0 likes
              Last Post NinjaTrader_JoshG  
              Started by Brillo, Today, 01:52 PM
              0 responses
              12 views
              0 likes
              Last Post Brillo
              by Brillo
               
              Started by TazoTodua, 02-09-2018, 08:40 AM
              10 responses
              880 views
              0 likes
              Last Post NinjaTrader_JoshG  
              Started by TazoTodua, Yesterday, 04:35 AM
              6 responses
              18 views
              0 likes
              Last Post eDanny
              by eDanny
               
              Started by MattP, Today, 12:25 PM
              1 response
              6 views
              0 likes
              Last Post NinjaTrader_PatrickG  
              Working...
              X