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 frslvr, 04-11-2024, 07:26 AM
      6 responses
      105 views
      1 like
      Last Post NinjaTrader_BrandonH  
      Started by trilliantrader, 04-18-2024, 08:16 AM
      6 responses
      26 views
      0 likes
      Last Post trilliantrader  
      Started by arvidvanstaey, Yesterday, 02:19 PM
      5 responses
      14 views
      0 likes
      Last Post NinjaTrader_Zachary  
      Started by Rapine Heihei, Yesterday, 08:25 PM
      1 response
      12 views
      0 likes
      Last Post NinjaTrader_ChelseaB  
      Started by Mongo, Yesterday, 11:05 AM
      6 responses
      27 views
      0 likes
      Last Post Mongo
      by Mongo
       
      Working...
      X