Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

NinjaTrader.Cbi.InstrumentList.

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

    NinjaTrader.Cbi.InstrumentList.

    Hi, this is NT7 code that extracts the current instruments from the instrument list then displays them in the parameter section with the current expiry date. Any suggestions how to achieve this with NT8? thanks


    // this section loads the list of instruments to select from
    NinjaTrader.Cbi.InstrumentList listOfInstruments = NinjaTrader.Cbi.InstrumentList.GetObject("Default" ); // method accesses the 'Default' list in the Instrument Manager
    List<string> AvailableInstruments = new List<string>();
    foreach (Instrument instrument in listOfInstruments.Instruments) //only include first 2 characters ignoring instruments that begin with '^'
    {
    if (instrument.FullName.Substring(0,1) != "^")
    {
    addme = instrument.FullName.Substring(0,2);
    if (!AvailableInstruments.Contains(addme)) AvailableInstruments.Add(addme);
    }
    }
    ArrayAvailableInstruments = AvailableInstruments.ToArray();

    if (theListOfInstruments == null) defaultInst = Instrument.MasterInstrument.Name; // no instrument selected so default to current charts instrument
    else defaultInst = theListOfInstruments;




    // this section selects the most recent xpiry contract for the instrument selected
    if (defaultInst != Instrument.MasterInstrument.Name) // if instrument from list, select the most recent expiry
    {
    NinjaTrader.Cbi.InstrumentList list = NinjaTrader.Cbi.InstrumentList.GetObject("Default" ); // method accesses the 'Default' list in the Instrument Manager
    List<Instrument> myList=new List<Instrument>();
    foreach (Instrument myInstrument in list.Instruments){myList.Add(myInstrument);}
    var result=from row in myList where row.FullName.Contains(defaultInst) orderby row.Expiry descending select row.FullName;
    bool contractFound = false;
    if (result!=null){if (result.Count()>0) {contractFound=true;}}
    List<string> selectedInstruments = result.ToList<string>();
    if (contractFound)
    {
    selected_contract = selectedInstruments[0];
    }
    else
    {
    selected_contract = "";
    runProgram = false;
    }
    }

    #2
    Hello pman777,
    Thanks for your post.

    I suspect the logic would remain mostly the same but you would need to go line by line and make sure everything is accessing the correct properties and methods for NT8.

    Is there a certain part of the conversion that is stumping you?
    Josh G.NinjaTrader Customer Service

    Comment


      #3
      thanks for response. Apparently NinjaTrader.Cbi.InstrumentList does not contain definition for GetObject ... is there documentation I can reference to find out how to convert the code?

      Comment


        #4
        That code is unsupported so there is no documentation I am able to provide for this specific conversion.

        Try using ".GetInstruments" instead of ".GetObject":

        NinjaTrader.Cbi.InstrumentList.GetInstruments()
        Josh G.NinjaTrader Customer Service

        Comment


          #5
          thanks ... when I code that I get the following message: Cannot implicitly convert type 'System.Collections.ObjectModel.Collection<NinjaTr ader.Cbi.Instrument>' to 'NinjaTrader.Cbi.InstrumentList'

          Comment


            #6
            is there any examples you can provide that show an instrument being selected from the indicator properties list that is then used to "Add" a higher time frame chart using that instrument? thanks for all your help.

            Comment


              #7
              After looking at this further I could not get NinjaTrader.Cbi.InstrumentList.GetInstruments() to return a full list for me either. I got it to return my custom list name as the instruments full name, but I'm not sure what that's actually doing or used for. I'm going to look into that and let you know if I discover anything helpful.

              For now it looks like you would need to loop over instrument.MasterInstrument.RolloverCollection and do some logic to figure out which is the current contract like the 'rollover indications indicator'
              https://ninjatrader.com/support/foru...d=7&linkid=905
              is there any examples you can provide that show an instrument being selected from the indicator properties list that is then used to "Add" a higher time frame chart using that instrument?
              Dynamically loading an additional data series is not currently possible. This is however under investigation by our Development Team as a feature request and I will have your vote added to that request. The tracking number is SFT-882
              Josh G.NinjaTrader Customer Service

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by Geovanny Suaza, 02-11-2026, 06:32 PM
              0 responses
              581 views
              0 likes
              Last Post Geovanny Suaza  
              Started by Geovanny Suaza, 02-11-2026, 05:51 PM
              0 responses
              338 views
              1 like
              Last Post Geovanny Suaza  
              Started by Mindset, 02-09-2026, 11:44 AM
              0 responses
              103 views
              0 likes
              Last Post Mindset
              by Mindset
               
              Started by Geovanny Suaza, 02-02-2026, 12:30 PM
              0 responses
              554 views
              1 like
              Last Post Geovanny Suaza  
              Started by RFrosty, 01-28-2026, 06:49 PM
              0 responses
              552 views
              1 like
              Last Post RFrosty
              by RFrosty
               
              Working...
              X