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:
    string instrumentListName = "FOREX";
    NinjaTrader.Cbi.InstrumentList list1 = NinjaTrader.Cbi.InstrumentList.GetObject(instrumentListName);
    
    foreach (Instrument i in list1.Instruments)
    {
        Print("My name is " + i.FullName);
    }
    
    
    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:
    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";
    }
    
    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 stafe, Today, 12:34 PM
      2 responses
      20 views
      0 likes
      Last Post stafe
      by stafe
       
      Started by asmmbillah, Today, 11:18 AM
      1 response
      18 views
      0 likes
      Last Post NinjaTrader_ChrisL  
      Started by nickse2003, Today, 09:56 AM
      1 response
      28 views
      0 likes
      Last Post NinjaTrader_ChristopherJ  
      Started by ATMtrader0001, Today, 10:08 AM
      5 responses
      39 views
      0 likes
      Last Post ATMtrader0001  
      Started by WHICKED, Today, 09:47 AM
      1 response
      26 views
      0 likes
      Last Post NinjaTrader_Spencer  
      Working...
      X