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

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 tkaboris, Today, 08:32 AM
      1 response
      3 views
      0 likes
      Last Post NinjaTrader_Jesse  
      Started by sidlercom80, 10-28-2023, 08:49 AM
      178 responses
      2,409 views
      0 likes
      Last Post NinjaTrader_BrandonH  
      Started by betsuni_123, Yesterday, 04:20 PM
      4 responses
      23 views
      0 likes
      Last Post betsuni_123  
      Started by Creamers, 04-27-2024, 05:32 AM
      8 responses
      55 views
      0 likes
      Last Post NinjaTrader_ChelseaB  
      Started by geotrades1, Today, 08:33 AM
      0 responses
      6 views
      0 likes
      Last Post geotrades1  
      Working...
      X