Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Multiple Strings as dropdown in NinjaScriptProperty

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

    Multiple Strings as dropdown in NinjaScriptProperty

    Hello,

    I would like to have a group of different strings as parameters to select like "Indicator1", "Indicator2", "Indicator3". Is that possible?

    Here is something I would like to do, but of course that is the wrong syntax:

    Code:
    #region Properties
    [NinjaScriptProperty]
    [Display(Name1="Indicator1", Name2="Indicator2", Name3="Indicator3", Description="Strat", Order=1, GroupName="Parameters")]
    { get; set; }
    #endregion
    Kind regards
    Gerik

    #2
    Originally posted by Gerik View Post
    I would like to have a group of different strings as parameters to select like "Indicator1", "Indicator2", "Indicator3". Is that possible?
    Yes.

    The simplest way is to define an enum type that contains your strings,
    like this,

    public enum MyEnumType { Indicator1, Indicator2, Indicator3 }

    and then setup your property, like this,

    public MyEnumType MyEnum { get; set; }

    in your code, you would then check MyEnum, like this,

    if (MyEnum == MyEnumType.Indicator1)
    {
    ....
    }


    Study @MovingAverageRibbon.cs, search for RibbonMAType.
    Hint: Add it to your chart, note the property grid parameters,
    see the dropdown for 'Moving average'? Study that code.

    Last edited by bltdavid; 02-04-2022, 06:31 AM.

    Comment


      #3
      Hello Gerik,

      Thanks for your post.

      There are also some examples in our Help Guide that can help direct you:

      SampleUniversalMovingAverage (demonstrates creating an enum) - https://ninjatrader.com/support/help...ned_parame.htm

      SampleIndicatorTypeConverter (demonstrates creating more "user-firendly" enums) -https://ninjatrader.com/support/helpGuides/nt8/using_a_typeconverter_to_custo.htm

      We look forward to assisting.

      Comment


        #4
        Thank you David and Jim.

        Comment


          #5
          Hello,

          I have an additional question:

          When using

          Code:
          [NinjaScriptProperty]
          [Display(Name="Indicator", Description="Indicator", Order=1, GroupName="Parameters")]
          public MyEnumType EnumIndicator
          { get; set; }
          
          public enum MyEnumType { Indicator1, Indicator2, Indicator3 }
          I would like to ask for additional properties depending on the selected enum value. So e.g. in case "Indicator1" is selected, I would like to ask for the parameters <length1>, <value1> and in case "Indicator2" is selected, I would e.g. like to ask only for <value2>.

          Is it possible to include this somehow in an if-structure?

          Sincerely
          Gerik

          Comment


            #6
            Hello Gerik,

            Yes, it is possible to include logic and customize the behavior of the property grid.

            The example below shows how controls can be disabled or removed from the property grid based on selection.

            https://ninjatrader.com/support/help...r_to_custo.htm

            Comment


              #7
              How does one change the display name for a property?

              Comment


                #8
                Hello bltdavid,

                We should note that we use Denys Vuika's WPF property grid and instead of using DisplayNameAttribute, we use DisplayAttribute.Name (for localization reasons.)

                So we actually want to change DisplayAttribute.Name.

                The following can be tested in the GetProperties() method of SampleIndicatorTypeConverter:

                Code:
                for (int i = 0; i < toggleValue1.Attributes.Count; i++)
                {
                    if (toggleValue1.Attributes[i] is DisplayAttribute)
                        (toggleValue1.Attributes[i] as DisplayAttribute).Name = "New Display Name";
                }

                Comment

                Latest Posts

                Collapse

                Topics Statistics Last Post
                Started by NullPointStrategies, Yesterday, 05:17 AM
                0 responses
                64 views
                0 likes
                Last Post NullPointStrategies  
                Started by argusthome, 03-08-2026, 10:06 AM
                0 responses
                139 views
                0 likes
                Last Post argusthome  
                Started by NabilKhattabi, 03-06-2026, 11:18 AM
                0 responses
                75 views
                0 likes
                Last Post NabilKhattabi  
                Started by Deep42, 03-06-2026, 12:28 AM
                0 responses
                45 views
                0 likes
                Last Post Deep42
                by Deep42
                 
                Started by TheRealMorford, 03-05-2026, 06:15 PM
                0 responses
                50 views
                0 likes
                Last Post TheRealMorford  
                Working...
                X