Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Hide or show some properties based on another properties value

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

    Hide or show some properties based on another properties value

    Hello,

    I'm developing a strategy and since there are a lot of potential user defined variables, I want to keep things as much clean and organized as possible.
    What I'm trying to achieve is to hide or show some properties based on a boolean:

    Example:

    Click image for larger version

Name:	image.png
Views:	382
Size:	4.1 KB
ID:	1262693

    I want to hide the Long Entry Line and Short Entry Line variable IF Calculate on given price is false. The moment I turn Calculate on given price​ to true those two variables should pop up.
    Searching the documents and other topics here on the forum, I have come across the [RefreshProperties(RefreshProperties.All)] and [Browsable()] attribute and tried to "dynamically" change that, but I couldn't get it to work.

    I have some coding experience but I have never worked with attributes like this and the documentation on Attributes is very small, so any help on the matter is well appreciated

    ​​​​​​​Thanks for your help

    #2
    Hello zSucco,

    Thank you for your post.

    I recommend checking out the following reference sample script:Use case Home in that script shows how to toggle if properties are shown/hidden based on a bool checkbox. You may search the script for "use case #1" and jump to different comments and regions of code that are relevant to that use case. This information should be exactly what you are looking to achieve.

    Please let us know if we may be of further assistance.

    Comment


      #3
      Hello Emily,

      Thank you for your help, I'll get an in depth look as soon as I can, I'll get back to you

      Have a good day

      Comment


        #4
        Sample Indicator TypeConverter

        Sample Indicator TypeConverter Ninjatrader https://pastecode.io/s/gmoe33p2 https://ninjatrader.com/support/helpGuides/nt8/NT%20HelpGuide%20English.html?using_a_typeconverter_to_custo.htm


        Code:
                // Custom Grid properties which will implement custom behavior
                #region Use Case #1: Show/hide properties based on secondary input
        
                [RefreshProperties(RefreshProperties.All)] // Needed to refresh the property grid when the value changes
                [Display(Name = "Toggle show/hide", Order = 1, GroupName = "Use Case #1")]
                public bool ShowHideToggle
                { get; set; }
        
                [Range(1, int.MaxValue)]
                [Display(Name = "Toggle value #1", Order = 2, GroupName = "Use Case #1")]
                public int ToggleValue1
                { get; set; }
        
                [Range(1, int.MaxValue)]
                [Display(Name = "Toggle value #2", Order = 3, GroupName = "Use Case #1")]
                public int ToggleValue2
                { get; set; }
        
                #endregion​
        Code:
            #region Use Case #1/: Show/hide properties based on secondary input & Disable/enable properties based on secondary input
        
            // This custom TypeConverter is applied ot the entire indicator object and handles two of our use cases
            // IMPORTANT: Inherit from IndicatorBaseConverter so we get default NinjaTrader property handling logic
            // IMPORTANT: Not doing this will completely break the property grids!
            // If targeting a "Strategy", use the "StrategyBaseConverter" base type instead
            public class MyConverter : IndicatorBaseConverter // or StrategyBaseConverter
            {
                public override PropertyDescriptorCollection GetProperties(ITypeDescriptorContext context, object component, Attribute[] attrs)
                {
                    // we need the indicator instance which actually exists on the grid
                    SampleIndicatorTypeConverter indicator = component as SampleIndicatorTypeConverter;
        
                    // base.GetProperties ensures we have all the properties (and associated property grid editors)
                    // NinjaTrader internal logic determines for a given indicator
                    PropertyDescriptorCollection propertyDescriptorCollection = base.GetPropertiesSupported(context)
                                                                                ? base.GetProperties(context, component, attrs)
                                                                                : TypeDescriptor.GetProperties(component, attrs);
        
                    if (indicator == null || propertyDescriptorCollection == null)
                        return propertyDescriptorCollection;
        
        
                    #region Use Case #1: Show/hide properties based on secondary input
        
                    // These two values are will be shown/hidden (toggled) based on "ShowHideToggle" bool value
                    PropertyDescriptor toggleValue1 = propertyDescriptorCollection["ToggleValue1"];
                    PropertyDescriptor toggleValue2 = propertyDescriptorCollection["ToggleValue2"];
        
                    // This removes the following properties from the grid to start off with
                    propertyDescriptorCollection.Remove(toggleValue1);
                    propertyDescriptorCollection.Remove(toggleValue2);
        
                    // Now that We've removed the default property descriptors, we can decide if they need to be re-added
                    // If "ShowHideToggle" is set to true, re-add these values to the property collection
                    if (indicator.ShowHideToggle)
                    {
                        propertyDescriptorCollection.Add(toggleValue1);
                        propertyDescriptorCollection.Add(toggleValue2);
                    }
        
                    // otherwise, nothing else to do since they were already removed
        
                    #endregion
            }​

        https://ninjatrader.com/support/helpGuides/nt8/NT%20HelpGuide%20English.html?using_a_typeconverter_to_custo.htm


        Last edited by PaulMohn; 08-08-2024, 07:36 AM.

        Comment


          #5
          RenkoTrader v1.6

          Click image for larger version  Name:	enum.png Views:	0 Size:	9.4 KB ID:	1313419


          https://pastecode.io/s/2mj8xbbw https://pastecode.io/s/ow7sge2r https://pastecode.io/s/2mj8xbbw https://ninjatraderecosystem.com/user-app-share-download/renko-trader-bot-semi-automatic-with-interface-and-higher-time-frame-filter/


          https://pastecode.io/s/2mj8xbbw https://ninjatraderecosystem.com/user-app-share-download/renko-trader-bot-semi-automatic-with-interface-and-higher-time-frame-filter/


          https://pastecode.io/s/2mj8xbbw https://pastecode.io/s/ow7sge2r https://pastecode.io/s/2mj8xbbw https://ninjatraderecosystem.com/user-app-share-download/renko-trader-bot-semi-automatic-with-interface-and-higher-time-frame-filter/


          https://pastecode.io/s/2mj8xbbw https://pastecode.io/s/ow7sge2r https://pastecode.io/s/2mj8xbbw https://ninjatraderecosystem.com/user-app-share-download/renko-trader-bot-semi-automatic-with-interface-and-higher-time-frame-filter/


          https://pastecode.io/s/2mj8xbbw

          https://ninjatraderecosystem.com/use...-frame-filter/
          Last edited by PaulMohn; 08-08-2024, 08:10 AM.

          Comment


            #6
            ColorThePlot

            https://ninjatraderecosystem.com/user-app-share-download/colortheplot/


            Click image for larger version  Name:	ColorThePlot.png?w=1180&ssl=1.png Views:	0 Size:	37.8 KB ID:	1313437


            Description: This indicator can be used to color the rising and falling conditions of most any other indicators plot when used as the input series to this indicator. ColorThePlot offers the ability to select rising and falling colors, sound alerts, email, alerts, Direction change marking, panel color based on direction, bar coloring based on direction. […]

            Comment


              #7
              Hello @NinjaTrader_ChelseaB​,

              Does this work with strategies vs indicator?

              Code:
              namespace NinjaTrader.NinjaScript.[B]Strategies[/B]
              {
                  [TypeConverter("NinjaTrader.NinjaScript.[B]Strategies[/B].MyXConverter")]​
              
                  public class MyXConverterStrat : [B]Strategy[/B]
                  {​
                      
                      bool MyX()
                      {
                          if(Cond0())
                          {
                               return true;
                           }
                              
                           return false;
                        }
                  }
              }

              Code:
              #region ConverterStuff
                  
                  public class MyXConverter: StrategyBaseConverter
                  {
                      public override PropertyDescriptorCollection GetProperties(ITypeDescriptorContext context, object component, Attribute[] attrs)
                      {
                          MyXConverterStrat [B]strategy[/B]= component as MyXConverterStrat; // need the same name as the Class name
              
                          PropertyDescriptorCollection propertyDescriptorCollection = base.GetPropertiesSupported(context)
                                                                                      ? base.GetProperties(context, component, attrs)
                                                                                      : TypeDescriptor.GetProperties(component, attrs);
              
                          if (strategy == null || propertyDescriptorCollection == null)
                              return propertyDescriptorCollection;
                              
              
                          PropertyDescriptor UpSoundFile            = propertyDescriptorCollection["UpSoundFile"];
                          
                              
                          // remove removable properties first
                          
                          propertyDescriptorCollection.Remove(UpSoundFile);
              
                          // Add back in if...
                                      
                          if ([B]strategy[/B].MyX())
                          {
                              propertyDescriptorCollection.Add(UpSoundFile);                                
                          }
                      
                          return propertyDescriptorCollection;
                      }
                      
                      // Important:  This must return true otherwise the type convetor will not be called
                      public override bool GetPropertiesSupported(ITypeDescriptorContext context)
                      { return true; }
                  }        
                  #endregion
              }​
              Last edited by PaulMohn; 08-22-2024, 01:29 PM.

              Comment


                #8
                NinjaTrader_ChelseaB

                I'm getting this compile error
                NinjaScript File Error Code Line Column
                MyXConverterStrat.cs 'NinjaTrader.NinjaScript.Strategies.MyXConverterSt rat.MyX()​' is inaccessible due to its protection level CS0122 9241 18

                From this line:

                if (strategy.MyX())

                I checked this but the callable method is a boolean method (no static signature):


                What's causing this error and what's the fix?

                Fix:


                namespace NinjaTrader.NinjaScript.Strategies
                {
                [TypeConverter("NinjaTrader.NinjaScript.Strategies.MyXConverter")]​

                public class MyXConverterStrat : Strategy
                {​

                public bool MyX()
                {
                if(Cond0())
                {
                return true;
                }

                return false;
                }
                }
                }​

                For access from separate class
                I'm still quite new to coding in general, and while this simple program is only meant to be a test to learn how constructors work, I'd still like to know why I'm getting this error. using System; ...
                Last edited by PaulMohn; 08-22-2024, 11:28 PM.

                Comment

                Latest Posts

                Collapse

                Topics Statistics Last Post
                Started by NullPointStrategies, Yesterday, 05:17 AM
                0 responses
                71 views
                0 likes
                Last Post NullPointStrategies  
                Started by argusthome, 03-08-2026, 10:06 AM
                0 responses
                143 views
                0 likes
                Last Post argusthome  
                Started by NabilKhattabi, 03-06-2026, 11:18 AM
                0 responses
                76 views
                0 likes
                Last Post NabilKhattabi  
                Started by Deep42, 03-06-2026, 12:28 AM
                0 responses
                47 views
                0 likes
                Last Post Deep42
                by Deep42
                 
                Started by TheRealMorford, 03-05-2026, 06:15 PM
                0 responses
                51 views
                0 likes
                Last Post TheRealMorford  
                Working...
                X