Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Instrument List

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

    Instrument List

    Is there any way to get the instrument list for the current instrument from code?
    Basically I need to do different action depending on which list the current instrument is in.

    Thanks

    #2
    Hello wookey, and thank you for your question.

    There is no direct way to map instruments to instrument lists.

    Going the other way - instrument list to instrument - while this is not documented, and we can only offer limited support, you may loop through instrument lists using this code :

    Code:
    [FONT=Courier New]string instrumentListName = "FOREX";
    NinjaTrader.Cbi.InstrumentList list1 = NinjaTrader.Cbi.InstrumentList.GetObject(instrumentListName);
    
    foreach (Instrument i in list1.Instruments)
    {
        Print("My name is " + i.FullName);
    }
    
    [/FONT]
    You could, then, store a list of instrument list names in your code, and then loop through them to see if a given instrument is on a list. This will in turn allow you to map instruments back to instrument lists, which should resolve your query. That code may look like this :

    Code:
    [FONT=Courier New]private string[] instrumentLists = {"FOREX"};
    private static string listFromInstrument(Instrument instrument)
    {
        foreach(string instrumentList in instrumentLists)
        {
            NinjaTrader.Cbi.InstrumentList list1 = NinjaTrader.Cbi.InstrumentList.GetObject(instrumentList);
    
            foreach (Instrument i in list1.Instruments)
            {
                if (i.FullName == instrument.FullName)
                {
                    return instrumentList;
                }
            }
        }
        return "Default";
    }
    [/FONT]
    Please let us know if there are any other ways we can help.
    Jessica P.NinjaTrader Customer Service

    Comment


      #3
      This solution works. Thank you!

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by cmoran13, 04-16-2026, 01:02 PM
      0 responses
      37 views
      0 likes
      Last Post cmoran13  
      Started by PaulMohn, 04-10-2026, 11:11 AM
      0 responses
      23 views
      0 likes
      Last Post PaulMohn  
      Started by CarlTrading, 03-31-2026, 09:41 PM
      1 response
      162 views
      1 like
      Last Post NinjaTrader_ChelseaB  
      Started by CarlTrading, 04-01-2026, 02:41 AM
      0 responses
      98 views
      1 like
      Last Post CarlTrading  
      Started by CaptainJack, 03-31-2026, 11:44 PM
      0 responses
      152 views
      2 likes
      Last Post CaptainJack  
      Working...
      X