Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Get "current" roll Instrument

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

    Get "current" roll Instrument

    Is there a way to get the current roll version of an instrument, given the master instrument name?

    For example, something like

    Code:
    Instrument current = GetCurrentInstrument("GC"); //Would give 'GC FEB24' today
    franco.tiveron
    NinjaTrader Ecosystem Vendor - franco.tiveron

    #2
    Hello franco.tiveron,

    Thank you for your post.

    Please see the RolloverIndications indicator script linked below, which demonstrates finding the next rollover expiry in code:

    https://ninjatraderecosystem.com/user-app-share-download/rolloverindications-2/

    If you have any other questions, please let me know.

    Comment


      #3
      Can I assume that the following line (line 197 in RolloverIndications.cs) is the correct way to obtain a rollover instrument name give the master instrument and a rollover object?
      Or, in other words, the name of a rollover instrument in NinjaTrader is ALWAYS <name of the master instrument><one space><rollover.ToString()>?

      Code:
      nextExpiryString = string.Format("{0} {1}", Instrument.MasterInstrument.Name, Instrument.MasterInstrument.RolloverCollection[nextRollCount].ToString());
      ​
      Finally, is the following code to get the current rollover instrument safe?

      Code:
      string GetCurrentInstrumentName(string masterInstrumentName) {
          var currentRollover = Instrument.All
             .First(i => i.MasterInstrument.Name == masterInstrumentName && i.MasterInstrument.InstrumentType == InstrumentType.Future)
      ​       .MasterInstrument
             .RolloverCollection
             .OrderBy(rollover => rollover.ContractMonth)
             .Last(rollover => !double.IsNaN(rollover.Offset));
      
          return $"{masterInstrumentName} {currentRollover}";
      }
      ​
      Last edited by franco.tiveron; 01-04-2024, 03:57 PM.
      franco.tiveron
      NinjaTrader Ecosystem Vendor - franco.tiveron

      Comment


        #4
        Hello,

        Yes, that is the correct line from the script that gets the next expiry.

        For that snippet, if your linq statement is returning the value they expected that should be fine to use.

        Otherwise, you can copy the code from the RolloverIndications script to get the current expiry.

        You can use the Instrument Manager to view how the rollovers are defined in the platform, or you could also loop through the RolloverCollection and print the values to verify how the rollovers are seen in your script and form your logic around that.

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by Geovanny Suaza, 02-11-2026, 06:32 PM
        0 responses
        633 views
        0 likes
        Last Post Geovanny Suaza  
        Started by Geovanny Suaza, 02-11-2026, 05:51 PM
        0 responses
        364 views
        1 like
        Last Post Geovanny Suaza  
        Started by Mindset, 02-09-2026, 11:44 AM
        0 responses
        105 views
        0 likes
        Last Post Mindset
        by Mindset
         
        Started by Geovanny Suaza, 02-02-2026, 12:30 PM
        0 responses
        567 views
        1 like
        Last Post Geovanny Suaza  
        Started by RFrosty, 01-28-2026, 06:49 PM
        0 responses
        568 views
        1 like
        Last Post RFrosty
        by RFrosty
         
        Working...
        X