Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

list of instruments

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

    list of instruments

    Hi, in my indicator I would like a drop down list in the parameter settings section of all available instruments in my "Default" instrument list. My indicator is designed to run based off of another instrument that correlates to the one defined for the chart. This list will enable me to select which instrument I want to correlate.

    Any assistance is greatly appreciated.

    #2
    Hello FCatan,

    Thank you for your inquiry.

    Please note that this method is only an example and is unsupported. This will be only pulling the FullName string from the instrument list.

    Please ensure that you have using System.Collections.Generic; in your using declarations.

    Code:
    protected override void Initialize()
            {						
    			NinjaTrader.Cbi.InstrumentList listOfInstruments = NinjaTrader.Cbi.InstrumentList.GetObject("Default");
    			List<string> AvailableInstruments = new List<string>();
    			
    			foreach (Instrument instrument in listOfInstruments.Instruments)
    			{
    				AvailableInstruments.Add(instrument.FullName);
    			}
    			ArrayAvailableInstruments = AvailableInstruments.ToArray();
            }
    
    private string theListOfInstruments;
    
    		[Description("Instruments")]
    		[GridCategory("Parameters")]
    		[TypeConverter(typeof(StringListConverter))]
    		public string TheListOfInstruments
    		{
    			get { return theListOfInstruments; }
    			set { theListOfInstruments = value; }
    		}
    
    [Browsable(false)]
    		public string[] ArrayAvailableInstruments
    		{
    			set { StringListConverter.value = value; }
    		}
    Ensure that the code below is outside of your indicator's class:
    Code:
    public sealed class StringListConverter : StringConverter
    		{
    
    			public static string[] value;
    			public override bool GetStandardValuesSupported(ITypeDescriptorContext context)
    			{
    				return true;
    			}
    
    			public override bool GetStandardValuesExclusive(ITypeDescriptorContext context)
    			{
    				return true;
    			}
    
    			public override TypeConverter.StandardValuesCollection GetStandardValues(ITypeDescriptorContext context)
    			{
    				return new StandardValuesCollection(value);
    			}
    		}
    For further information about this, please take a look at this link: http://exploitcsharp.blogspot.com/20...n-list-in.html

    I would suggest reading more about the use of type converters in C#: https://msdn.microsoft.com/en-us/library/ayybcxe5.aspx
    Zachary G.NinjaTrader Customer Service

    Comment


      #3
      Thank you Zachary. Your response worked like a charm!

      Now I need to "Add" the instrument that is selected for the same period type. I know this also needs to be coded in the Initialization section, but how do I know what instrument was selected?

      Comment


        #4
        Hello FCatan,

        The instrument that is selected is assigned to the "theListOfInstruments" string variable.
        Zachary G.NinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by Geovanny Suaza, 02-11-2026, 06:32 PM
        0 responses
        571 views
        0 likes
        Last Post Geovanny Suaza  
        Started by Geovanny Suaza, 02-11-2026, 05:51 PM
        0 responses
        330 views
        1 like
        Last Post Geovanny Suaza  
        Started by Mindset, 02-09-2026, 11:44 AM
        0 responses
        101 views
        0 likes
        Last Post Mindset
        by Mindset
         
        Started by Geovanny Suaza, 02-02-2026, 12:30 PM
        0 responses
        548 views
        1 like
        Last Post Geovanny Suaza  
        Started by RFrosty, 01-28-2026, 06:49 PM
        0 responses
        549 views
        1 like
        Last Post RFrosty
        by RFrosty
         
        Working...
        X