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

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 helpwanted, Today, 03:06 AM
        1 response
        8 views
        0 likes
        Last Post sarafuenonly123  
        Started by Brevo, Today, 01:45 AM
        0 responses
        7 views
        0 likes
        Last Post Brevo
        by Brevo
         
        Started by aussugardefender, Today, 01:07 AM
        0 responses
        5 views
        0 likes
        Last Post aussugardefender  
        Started by pvincent, 06-23-2022, 12:53 PM
        14 responses
        242 views
        0 likes
        Last Post Nyman
        by Nyman
         
        Started by TraderG23, 12-08-2023, 07:56 AM
        9 responses
        385 views
        1 like
        Last Post Gavini
        by Gavini
         
        Working...
        X