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

Checkbox in the Properties swich off other checkbox

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

    Checkbox in the Properties swich off other checkbox

    Hello everybody.

    I have some conditions in the Propery of Strategy and would like to create three checkboxes which one of each will be swich off other two.
    For example, I have three checkboxes "Both", "Long", "Short" and I would like to choose one of three and when I check one - other two must be swich off.
    I created drop down list with three parameters but interesting to create condition with three checkboxes.


    #2
    Hello vitaly_p,

    Thanks for your post.

    Controlling the behavior of NinjaScript properties would be done using a TypeConverter.

    Please see the reference sample on the help guide page linked below which demonstrates how to customize property grid behavior using a TypeConverter.



    Brandon H.NinjaTrader Customer Service

    Comment


      #3
      Hello Brendon.
      Thank you for information!

      Comment


        #4
        Hello Brandon

        I stydied this Sample Indicator and trying to create dropdown menu. I did it and I have the problem with my next step: I would like to create condition (based on the Case #2) when I choose first position of the dropdown list - my next line (which place below this dropdown list) must be active and when I choose the second of the dropdown list - this next line must be inactive (read only).

        my code:

        ​public enum POStrategy { newStrategy, oldStrategy};

        [TypeConverter(typeof(PositionOpeningStrategyEnumCo nverter))]
        [PropertyEditor("NinjaTrader.Gui.Tools.StringStanda rdValuesEditorKey")]
        [RefreshProperties(RefreshProperties.All)]
        [Display(Name = "Position Opening Strategy", GroupName = "Parameters", Order = 20)]
        public POStrategy OpeningStrategy { get; set; }

        [Range(1, int.MaxValue)]
        [Display(Name = "CCQ", GroupName = "Parameters", Order = 30)]
        public int CCQ { get; set; }


        public class ReversalStrategyConverter : StrategyBaseConverter
        {
        public override PropertyDescriptorCollection GetProperties(ITypeDescriptorContext context, object component, Attribute[] attrs)
        {
        MyRevStrategy strategy = component as MyRevStrategy;

        PropertyDescriptorCollection properties = base.GetProperties(context, component, attrs);

        if (strategy == null || properties == null)
        return properties;

        PropertyDescriptor ccqProperty = properties.Find("CCQ", false);

        if (ccqProperty != null)
        {
        properties.Remove(ccqProperty);
        ccqProperty = new ReadOnlyPropertyDescriptor(ccqProperty, strategy.OpeningStrategy == POStrategy.oldStrategy);
        properties.Add(ccqProperty);
        }

        return properties;
        }

        public override bool GetPropertiesSupported(ITypeDescriptorContext context) => true;
        }

        public class ReadOnlyPropertyDescriptor : PropertyDescriptor
        {
        private readonly PropertyDescriptor _basePropertyDescriptor;
        private readonly bool _isReadOnly;

        public ReadOnlyPropertyDescriptor(PropertyDescriptor basePropertyDescriptor, bool isReadOnly)
        : base(basePropertyDescriptor.Name, null)
        {
        _basePropertyDescriptor = basePropertyDescriptor;
        _isReadOnly = isReadOnly;
        }

        public override bool IsReadOnly => _isReadOnly;

        public override bool CanResetValue(object component) => _basePropertyDescriptor.CanResetValue(component);

        public override Type ComponentType => _basePropertyDescriptor.ComponentType;

        public override object GetValue(object component) => _basePropertyDescriptor.GetValue(component);

        public override Type PropertyType => _basePropertyDescriptor.PropertyType;

        public override void ResetValue(object component) => _basePropertyDescriptor.ResetValue(component);

        public override void SetValue(object component, object value)
        {
        if (!_isReadOnly)
        {
        _basePropertyDescriptor.SetValue(component, value);
        }
        }
        public override bool ShouldSerializeValue(object component) => _basePropertyDescriptor.ShouldSerializeValue(compo nent);

        public override string DisplayName => _basePropertyDescriptor.DisplayName;

        public override string Description => _basePropertyDescriptor.Description;

        public override string Category => _basePropertyDescriptor.Category;

        public override AttributeCollection Attributes => _basePropertyDescriptor.Attributes;
        }

        Please, help me, wher I wrong?

        Thank you​

        Comment


          #5
          Hello vitaly_p,

          Thanks for your notes.

          I understand you would like to toggle a property to be enabled/disabled based on what option is selected in your drop-down menu property

          You would need to make conditions for that in the property descriptor area of the script. The SampleIndicatorTypeConverter reference sample from the help guide has a few samples showing how to toggle properties based on selections. What you want to accomplish would be the same concept with a drop-down menu.

          If you study the MyConverter class, the GetProperties override is what controls this. If you want to hide properties you would remove them first, check the value of the main property as a condition, and then re-add the properties you want to show based on the selection.

          If you want them to be read-only it would be the same concept. The properties would first be removed, then re-add the properties that should be read-only using the ReadOnlyDescriptor.

          The way to check the drop-down menu value would be similar to the if (indicator.ShowHideToggle) condition in the reference sample, you get the property value from the instance and make a condition.

          SampleIndicatorTypeConverter: https://ninjatrader.com/support/help...r_to_custo.htm
          Brandon H.NinjaTrader Customer Service

          Comment


            #6
            Hello Brandon

            Thank you for your answer, I found condition about what you wrote and after that my condition working well on the indicator, but when I create the same condition in the strategy - not working
            I read documentation https://ninjatrader.com/support/help...a_typeconverte r_to_custo.htm and checked my code but can't understand why condition not working...
            What can be different betweenrealization of this logic for indicator and for the strategy?

            I applyed Type converter attribute:
            [TypeConverter("NinjaTrader.NinjaScript.Strategies. MyCustomConverter")]


            this is my class code:
            public class MyCustomConverter : StrategyBaseConverter
            {
            public override PropertyDescriptorCollection GetProperties(ITypeDescriptorContext context, object component, Attribute[] attrs)
            {

            RBOT strategy = component as RBOT;

            PropertyDescriptorCollection propertyDescriptorCollection = base.GetPropertiesSupported(context)
            ? base.GetProperties(context, component, attrs)
            : TypeDescriptor.GetProperties(component, attrs);

            if (strategy == null || propertyDescriptorCollection == null)
            return propertyDescriptorCollection;

            PropertyDescriptor ccq = propertyDescriptorCollection["CCQ"];

            propertyDescriptorCollection.Remove(ccq);

            if (strategy.EnumValue == POSEnum.NewLogic)
            {
            propertyDescriptorCollection.Add(ccq);
            }

            foreach (PropertyDescriptor property in propertyDescriptorCollection)
            {

            NinjaTrader.Code.Output.Process(property.Name, PrintTo.OutputTab1);
            }

            return propertyDescriptorCollection;
            }
            public override bool GetPropertiesSupported(ITypeDescriptorContext context)
            { return true; }
            }

            and part Properties code:

            [TypeConverter(typeof(FriendlyEnumConverter))]
            [PropertyEditor("NinjaTrader.Gui.Tools.StringStanda rdValuesEditorKey")]
            [RefreshProperties(RefreshProperties.All)]
            [Display(Name = "Position Opening Logic", GroupName = "Parameters", Order = 20)]
            public POSEnum EnumValue { get; set; }

            [Range(1, int.MaxValue)]
            [Display(Name = "Confirmation Candle Quantity ", GroupName = "Parameters", Order = 30)]
            public int CCQ { get; set; }​

            Comment


              #7
              Hello vitaly_p,

              Thanks for your notes.

              I do not see anything standing out as incorrect in the code that you provided.

              You could create a simple test script containing only the code demonstrating the behavior you are reporting and share the .cs file of the script so we may see the full code. NinjaScript strategy files will be located in the Documents\NinjaTrader 8\bin\Custom\Strategies folder.

              Please note that the strategy converter only works in a few areas of NinjaTrader such as the Chart or Control Center. It will not work in a backtest or any of the other options in the Strategy Analyzer window.
              Brandon H.NinjaTrader Customer Service

              Comment


                #8
                Hello Brandon

                my Sample file in attachment. I copied just part of the code which working with this two menu conditions
                Attached Files

                Comment


                  #9
                  Hello vitaly_p,

                  Thanks for that information.

                  In the code you shared there are multiple issues that are causing the script to not behave as expected. It seems that you did not follow the structure of the SampleIndicatorTypeConverter reference sample.

                  The type converter needs to go on the class, not on OnStateChange.

                  The class for the type converter is inside the strategy class, which needs to go in the namespace.

                  The enum is defined in the strategy class, which will cause an issue during export. This needs to be placed in a custom namespace and be used like the enum in the SampleIndicatorTypeConverter sample linked on post # 5.

                  Attached is a modified version of the script you shared demonstrating the above notes.


                  Attached Files
                  Brandon H.NinjaTrader Customer Service

                  Comment


                    #10
                    Thank you Brandon!

                    a lot of comments in the Sample code and I lost right structure when read the code, thank you for your help!

                    About custom namespace for enum: when I moved class MyCustomConverter out of the Strategy class - I saw enum error.
                    I understand that our enum is inside the Strategy class. I see that you use : using static NinjaTrader.NinjaScript.Strategies.SampleMenu; for exclude this error.

                    But we can move enum out of the Strategy namespace (and place below usings) and it will be working without using static NinjaTrader.NinjaScript.Strategies.SampleMenu;. Right?

                    Comment


                      #11
                      Hello vitaly_p,

                      Thanks for your notes.

                      You should follow the same structure as seen in the sample code I shared on post # 9. Or the structure seen in the SampleIndicatorTypeConverter reference sample from the help guide.

                      When using namespaces ensure that you use the fully qualified namespace.

                      Creating a user-defined enum reference sample: https://ninjatrader.com/support/help...ned_parame.htm
                      Brandon H.NinjaTrader Customer Service

                      Comment


                        #12
                        Thank you Brandon!

                        Comment

                        Latest Posts

                        Collapse

                        Topics Statistics Last Post
                        Started by fx.practic, 10-15-2013, 12:53 AM
                        5 responses
                        5,404 views
                        0 likes
                        Last Post Bidder
                        by Bidder
                         
                        Started by Shai Samuel, 07-02-2022, 02:46 PM
                        4 responses
                        95 views
                        0 likes
                        Last Post Bidder
                        by Bidder
                         
                        Started by DJ888, Yesterday, 10:57 PM
                        0 responses
                        7 views
                        0 likes
                        Last Post DJ888
                        by DJ888
                         
                        Started by MacDad, 02-25-2024, 11:48 PM
                        7 responses
                        159 views
                        0 likes
                        Last Post loganjarosz123  
                        Started by Belfortbucks, Yesterday, 09:29 PM
                        0 responses
                        8 views
                        0 likes
                        Last Post Belfortbucks  
                        Working...
                        X