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 sjsj2732, 03-23-2026, 04:31 AM
        0 responses
        49 views
        0 likes
        Last Post sjsj2732  
        Started by NullPointStrategies, 03-13-2026, 05:17 AM
        0 responses
        300 views
        0 likes
        Last Post NullPointStrategies  
        Started by argusthome, 03-08-2026, 10:06 AM
        0 responses
        294 views
        0 likes
        Last Post argusthome  
        Started by NabilKhattabi, 03-06-2026, 11:18 AM
        0 responses
        139 views
        1 like
        Last Post NabilKhattabi  
        Started by Deep42, 03-06-2026, 12:28 AM
        0 responses
        98 views
        0 likes
        Last Post Deep42
        by Deep42
         
        Working...
        X