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

Grey Out Properties Options for User Based on ENUM

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

    Grey Out Properties Options for User Based on ENUM

    I have created an ENUM in the properties menu, I want to disable or grey out other user properties if the ENUM selects one. So if I pick EMA for example disable DynamicPT so they user can't change it from the default.

    Has anyone done this before?

    Code:
     
    public enum type{SMA,EMA};
     
    #region Properties
    [Description("Profit target")]
    [GridCategory("Parameters")]
    public int PT
    {
    get { return pt; }
    set { pt = Math.Max(1, value); }
    }
    [Description("Dynamic profit target")]
    [GridCategory("Parameters")]
    public bool Dynamicpt
    {
    get { return DynamicPT; }
    set { DynamicPT = value; }
    }
    [Description("Type one for entry chart, type two for hedge chart")]
    [GridCategory("Parameters")]
    public strat StratType
    {
    get { return stratType; }
    set { stratType = value; }
    }
    #endregion

    #2
    Hello happypappy,

    Thank you for your post.

    I am not sure how you would gray out the option, but you could check for the enum in the OnBarUpdate() or OnStartUp() and then set the parameters per the enum option thus overriding what the user has set.

    Comment


      #3
      Thanks I found an old thread with a similar question.



      I also found this example, if anyone else ever ask the questions. I should be able to tie events to a GET/SET which is what I want, example below.

      Code:
      public class MyClass 
      { 
        private int _myHeight; 
        public event EventHandler Changed;
      
        protected void OnChanged() {
          if (Changed != null) Changed(this, EventArgs.Empty);
        }
      
        public int myHeight 
        { 
          get { return myHeight; } 
          set {
            myHeight = value; 
            OnChanged();
          } 
        }
        // Repeat the same pattern for all other properties
      }
      However is it possible at all to set these?
      [Browsable(true)] - this is default
      [Browsable(somevariable)] - can I use a variable?

      I assume OnStartUp() occurs when the strat is enabled?
      Last edited by happypappy; 10-26-2014, 08:54 PM.

      Comment


        #4
        Hello happypappy,

        Thank you for your response.

        It would not be possible to set the bool for browsable. The OnStartUp() method is called when the strategy is enabled.

        Comment


          #5
          look here:
          https://www.bigmiketrading.com/ninja...roperties.html

          Comment


            #6
            Originally posted by Baruch View Post
            Wow man perfect thank you, Ill take a look Ill get it to set and see if I can make it refresh and remove them based on the selection, cheers again. Ill post the code here since it seems to be an ongoing issue.

            Comment


              #7
              Wow man this is a heap of code for such a simple function. Never the less it's been a question asked consistently. This code is from the link provided below by Baruch, I made changed to get my hidden functionality to work. I've got to split this into a few posts, I've attached the images and a few core functions here.

              I've uploaded my test start, Ill break down the code into chunks. You add this to the top of the strategy.

              Code:
              [COLOR=blue][FONT=Courier New]publicclass[/FONT][/COLOR][COLOR=#282828][FONT=Courier New] TestEnumAction : Strategy[B][U], ICustomTypeDescriptor[/U][/B][/FONT][/COLOR]
              [COLOR=#282828][FONT=Arial][/FONT][/COLOR]


              Add this function to your class, I couldn't get the UpdateDisplayName to work but it was listed in the code I got from the link so it may be useful for someone.

              Code:
              [COLOR=green][FONT=Courier New]// @EXAMPLE: Add this method to your class. It will be called by all the boiler plate code that is [/FONT][/COLOR]
              [COLOR=green][FONT=Courier New]// hidden below.[/FONT][/COLOR]
              [COLOR=blue][FONT=Courier New]privatevoid[/FONT][/COLOR][COLOR=#282828][FONT=Courier New] ModifyProperties(PropertyDescriptor[] properties)[/FONT][/COLOR]
              [COLOR=#282828][FONT=Courier New]{[/FONT][/COLOR]
              [COLOR=green][FONT=Courier New]// @EXAMPLE: Update the display name of a property[/FONT][/COLOR]
              [COLOR=blue][FONT=Courier New]if[/FONT][/COLOR][COLOR=#282828][FONT=Courier New] (stratType == type.EMA)[/FONT][/COLOR]
              [COLOR=#282828][FONT=Courier New]{[/FONT][/COLOR]
              [COLOR=#282828][FONT=Courier New]UpdateDisplayName(properties, [/FONT][/COLOR][COLOR=maroon][FONT=Courier New]"MyInput0"[/FONT][/COLOR][COLOR=#282828][FONT=Courier New], [/FONT][/COLOR][COLOR=maroon][FONT=Courier New]"Property Name "[/FONT][/COLOR][COLOR=#282828][FONT=Courier New] + DateTime.Now.ToLongTimeString());[/FONT][/COLOR]
              [COLOR=#282828][FONT=Courier New]}[/FONT][/COLOR]
              [COLOR=blue][FONT=Courier New]else[/FONT][/COLOR]
              [COLOR=#282828][FONT=Courier New]{[/FONT][/COLOR]
              [COLOR=#282828][FONT=Courier New]UpdateDisplayName(properties, [/FONT][/COLOR][COLOR=maroon][FONT=Courier New]"MyInput0"[/FONT][/COLOR][COLOR=#282828][FONT=Courier New], [/FONT][/COLOR][COLOR=maroon][FONT=Courier New]"TestUpdate"[/FONT][/COLOR][COLOR=#282828][FONT=Courier New]); [/FONT][/COLOR]
              [COLOR=#282828][FONT=Courier New]}[/FONT][/COLOR]
              [COLOR=green][FONT=Courier New]// @EXAMPLE: Update the hidden status of the attribute[/FONT][/COLOR]
              [COLOR=blue][FONT=Courier New]if[/FONT][/COLOR][COLOR=#282828][FONT=Courier New] (stratType == type.EMA)[/FONT][/COLOR]
              [COLOR=#282828][FONT=Courier New]{[/FONT][/COLOR]
              [COLOR=#282828][FONT=Courier New]Print([/FONT][/COLOR][COLOR=maroon][FONT=Courier New]"Hide"[/FONT][/COLOR][COLOR=#282828][FONT=Courier New]);[/FONT][/COLOR]
              [COLOR=#282828][FONT=Courier New]UpdateHiddenStatus(properties,[/FONT][/COLOR][COLOR=maroon][FONT=Courier New]"Start"[/FONT][/COLOR][COLOR=#282828][FONT=Courier New],[/FONT][/COLOR][COLOR=blue][FONT=Courier New]false[/FONT][/COLOR][COLOR=#282828][FONT=Courier New]);[/FONT][/COLOR]
              [COLOR=#282828][FONT=Courier New]}[/FONT][/COLOR]
              [COLOR=blue][FONT=Courier New]else[/FONT][/COLOR]
              [COLOR=#282828][FONT=Courier New]{[/FONT][/COLOR]
              [COLOR=#282828][FONT=Courier New]Print([/FONT][/COLOR][COLOR=maroon][FONT=Courier New]"Unhide"[/FONT][/COLOR][COLOR=#282828][FONT=Courier New]);[/FONT][/COLOR]
              [COLOR=#282828][FONT=Courier New]UpdateHiddenStatus(properties,[/FONT][/COLOR][COLOR=maroon][FONT=Courier New]"Start"[/FONT][/COLOR][COLOR=#282828][FONT=Courier New],[/FONT][/COLOR][COLOR=blue][FONT=Courier New]true[/FONT][/COLOR][COLOR=#282828][FONT=Courier New]);[/FONT][/COLOR]
              [COLOR=#282828][FONT=Courier New]}[/FONT][/COLOR]
              [COLOR=#282828][FONT=Courier New] [/FONT][/COLOR]
              [COLOR=green][FONT=Courier New]// @EXAMPLE: Update desciption[/FONT][/COLOR]
              [COLOR=blue][FONT=Courier New]if[/FONT][/COLOR][COLOR=#282828][FONT=Courier New] (stratType == type.EMA)[/FONT][/COLOR]
              [COLOR=#282828][FONT=Courier New]{[/FONT][/COLOR]
              [COLOR=#282828][FONT=Courier New]UpdateDescription(properties, [/FONT][/COLOR][COLOR=maroon][FONT=Courier New]"MyInput0"[/FONT][/COLOR][COLOR=#282828][FONT=Courier New], [/FONT][/COLOR][COLOR=maroon][FONT=Courier New]"Property description at "[/FONT][/COLOR][COLOR=#282828][FONT=Courier New] + DateTime.Now.ToLongTimeString());[/FONT][/COLOR]
              [COLOR=#282828][FONT=Courier New]}[/FONT][/COLOR]
              [COLOR=blue][FONT=Courier New]else[/FONT][/COLOR]
              [COLOR=#282828][FONT=Courier New]{[/FONT][/COLOR]
              [COLOR=#282828][FONT=Courier New]UpdateDescription(properties, [/FONT][/COLOR][COLOR=maroon][FONT=Courier New]"MyInput0"[/FONT][/COLOR][COLOR=#282828][FONT=Courier New], [/FONT][/COLOR][COLOR=maroon][FONT=Courier New]"Original"[/FONT][/COLOR][COLOR=#282828][FONT=Courier New]);[/FONT][/COLOR]
              [COLOR=#282828][FONT=Courier New]}[/FONT][/COLOR]
              [COLOR=#282828][FONT=Courier New]}[/FONT][/COLOR]
              [COLOR=#282828][FONT=Arial][/FONT][/COLOR]
              Attached Files

              Comment


                #8
                In the Properties section, the name of the variable is the targeted properties name, so MyInput0 or Start in this case. You need [RefreshProperties(RefreshProperties.All)] next to the properties that control the actions.

                Code:
                [COLOR=blue][FONT=Courier New][/FONT][/COLOR]
                [COLOR=blue][FONT=Courier New]#region[/FONT][/COLOR][COLOR=black][FONT=Courier New] Properties[/FONT][/COLOR][COLOR=#282828][FONT=Courier New][/FONT][/COLOR]
                [COLOR=#282828][FONT=Courier New][Description([/FONT][/COLOR][COLOR=maroon][FONT=Courier New]""[/FONT][/COLOR][COLOR=#282828][FONT=Courier New])][/FONT][/COLOR]
                [COLOR=#282828][FONT=Courier New][GridCategory([/FONT][/COLOR][COLOR=maroon][FONT=Courier New]"Parameters"[/FONT][/COLOR][COLOR=#282828][FONT=Courier New])][/FONT][/COLOR]
                [COLOR=green][FONT=Courier New]//IF I WAS MAKING ALTERTIONS TO THIS I WOULD LOOKE FOR MYINPUT0[/FONT][/COLOR]
                [COLOR=blue][FONT=Courier New]publicint[/FONT][/COLOR][COLOR=#282828][FONT=Courier New] [B][U]MyInput0[/U][/B][/FONT][/COLOR]
                [COLOR=#282828][FONT=Courier New]{[/FONT][/COLOR]
                [COLOR=blue][FONT=Courier New]get[/FONT][/COLOR][COLOR=#282828][FONT=Courier New] { [/FONT][/COLOR][COLOR=blue][FONT=Courier New]return[/FONT][/COLOR][COLOR=#282828][FONT=Courier New] myInput0; }[/FONT][/COLOR]
                [COLOR=blue][FONT=Courier New]set[/FONT][/COLOR][COLOR=#282828][FONT=Courier New] { myInput0 = Math.Max([/FONT][/COLOR][COLOR=purple][FONT=Courier New]1[/FONT][/COLOR][COLOR=#282828][FONT=Courier New], value); }[/FONT][/COLOR]
                [COLOR=#282828][FONT=Courier New]}[/FONT][/COLOR]
                [COLOR=#282828][FONT=Courier New][Description([/FONT][/COLOR][COLOR=maroon][FONT=Courier New]"Contracts"[/FONT][/COLOR][COLOR=#282828][FONT=Courier New])][/FONT][/COLOR]
                [COLOR=#282828][FONT=Courier New][Gui.Design.DisplayName([/FONT][/COLOR][COLOR=maroon][FONT=Courier New]"Contracts"[/FONT][/COLOR][COLOR=#282828][FONT=Courier New])][/FONT][/COLOR]
                [COLOR=#282828][FONT=Courier New][GridCategory([/FONT][/COLOR][COLOR=maroon][FONT=Courier New]"Parameters"[/FONT][/COLOR][COLOR=#282828][FONT=Courier New])][/FONT][/COLOR]
                [COLOR=green][FONT=Courier New]//THE START IS THE PROPERTY YOU LOOK FOR IN THE CODE[/FONT][/COLOR]
                [COLOR=blue][FONT=Courier New]publicint[/FONT][/COLOR][COLOR=#282828][FONT=Courier New] [B][U]Start[/U][/B][/FONT][/COLOR]
                [COLOR=#282828][FONT=Courier New]{[/FONT][/COLOR]
                [COLOR=blue][FONT=Courier New]get[/FONT][/COLOR][COLOR=#282828][FONT=Courier New] { [/FONT][/COLOR][COLOR=blue][FONT=Courier New]return[/FONT][/COLOR][COLOR=#282828][FONT=Courier New] start; }[/FONT][/COLOR]
                [COLOR=blue][FONT=Courier New]set[/FONT][/COLOR][COLOR=#282828][FONT=Courier New] { start = Math.Max([/FONT][/COLOR][COLOR=purple][FONT=Courier New]1[/FONT][/COLOR][COLOR=#282828][FONT=Courier New], value); }[/FONT][/COLOR]
                [COLOR=#282828][FONT=Courier New]}[/FONT][/COLOR]
                [COLOR=#282828][FONT=Courier New][Description([/FONT][/COLOR][COLOR=maroon][FONT=Courier New]"Type one for entry chart, type two for hedge chart"[/FONT][/COLOR][COLOR=#282828][FONT=Courier New])][/FONT][/COLOR]
                [COLOR=#282828][FONT=Courier New][Gui.Design.DisplayName([/FONT][/COLOR][COLOR=maroon][FONT=Courier New]"Strat Selection"[/FONT][/COLOR][COLOR=#282828][FONT=Courier New])][/FONT][/COLOR]
                [COLOR=#282828][FONT=Courier New][GridCategory([/FONT][/COLOR][COLOR=maroon][FONT=Courier New]"Parameters"[/FONT][/COLOR][COLOR=#282828][FONT=Courier New])][/FONT][/COLOR]
                [B][U][COLOR=#282828][FONT=Courier New][RefreshProperties(RefreshProperties.All)] [/FONT][/COLOR][/U][/B][B][U][COLOR=green][FONT=Courier New]// <-- ADD THIS TO ANY PROPERTIES YOU ALTER FROM, THIS IS ESSENTIALLY YOUR EVENT TRIGGER[/FONT][/COLOR][/U][/B][COLOR=green][FONT=Courier New][/FONT][/COLOR]
                [COLOR=blue][FONT=Courier New]public[/FONT][/COLOR][COLOR=#282828][FONT=Courier New] type StratType[/FONT][/COLOR]
                [COLOR=#282828][FONT=Courier New]{[/FONT][/COLOR]
                [COLOR=blue][FONT=Courier New]get[/FONT][/COLOR][COLOR=#282828][FONT=Courier New] { [/FONT][/COLOR][COLOR=blue][FONT=Courier New]return[/FONT][/COLOR][COLOR=#282828][FONT=Courier New] stratType; }[/FONT][/COLOR]
                [COLOR=blue][FONT=Courier New]set[/FONT][/COLOR][COLOR=#282828][FONT=Courier New] { stratType = value;}[/FONT][/COLOR]
                [COLOR=#282828][FONT=Courier New]}[/FONT][/COLOR]
                [COLOR=blue][FONT=Courier New]#endregion[/FONT][/COLOR]
                [COLOR=#282828][FONT=Arial][/FONT][/COLOR]

                Comment


                  #9
                  The rest of the code is far to much to post, download the ZIP file and grab the 3 regions. Like from the picture attached.

                  ThreeUtilityMethods
                  ICustomTypeDescriptors
                  CustomerPropertyDescriptor

                  Copy and paste this entire section, this creates the event handlers references at the top, and associates it to the function we added at the start. I really hope this helps a few people
                  Attached Files

                  Comment


                    #10
                    Thanks for sharing this with our commnunity happypappy, I'm sure will be greatly appreciated.
                    BertrandNinjaTrader Customer Service

                    Comment


                      #11
                      Originally posted by happypappy View Post
                      The rest of the code is far to much to post, download the ZIP file and grab the 3 regions. Like from the picture attached.

                      ThreeUtilityMethods
                      ICustomTypeDescriptors
                      CustomerPropertyDescriptor

                      Copy and paste this entire section, this creates the event handlers references at the top, and associates it to the function we added at the start. I really hope this helps a few people
                      Nice. One quibble. Your UpdateHiddenStatus() method will toggle every boolean attribute of the property it handles. You might want to make the method more restrictive to the particular attributes.

                      Comment

                      Latest Posts

                      Collapse

                      Topics Statistics Last Post
                      Started by Misplace, Today, 11:55 AM
                      0 responses
                      5 views
                      0 likes
                      Last Post Misplace  
                      Started by dtaylor, Yesterday, 02:24 AM
                      1 response
                      10 views
                      0 likes
                      Last Post NinjaTrader_Eduardo  
                      Started by sofortune, 05-10-2024, 10:28 AM
                      7 responses
                      60 views
                      0 likes
                      Last Post sofortune  
                      Started by saturntd, 05-17-2024, 10:18 PM
                      1 response
                      9 views
                      0 likes
                      Last Post NinjaTrader_Eduardo  
                      Started by llanqui, Today, 11:26 AM
                      0 responses
                      5 views
                      0 likes
                      Last Post llanqui
                      by llanqui
                       
                      Working...
                      X