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

Error using NinjaScriptProperty with Properties removed using IndicatorBaseConverter

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

    Error using NinjaScriptProperty with Properties removed using IndicatorBaseConverter

    I am using code that dynamically turn some properties of, based on value of other properties using RefreshProperties.All, and a code I wrote which include propertyDescriptorCollection.Remove. See my code below, which works fine.

    On Indicator there is no issues, but when the same code is used by Strategy, if the property that was removed is set as NinjaScriptProperty, I get an error message:

    There was a problem installing "MyStratgey", Selecting next valid strategy.
    Code:
    public void ToggleProperties(string[] toggleProperties, bool toggleCondition,
    PropertyDescriptorCollection propertyDescriptorCollection)
    {
            // NinjaTrader internal logic determines for a given strategy
    PropertyDescriptor[] toggles = new PropertyDescriptor[toggleProperties.Count()];
    for (int i=0; i < toggleProperties.Count(); i++)
    {
    toggles[i] = propertyDescriptorCollection[toggleProperties[i]];
               propertyDescriptorCollection.Remove(toggles[i]);
    if (toggleCondition) propertyDescriptorCollection.Add(toggles[i]);
    }
    }
    ​
    The call is outside the class, with the names of the properties to toggle off, and the condition (show/no show).


    #2
    Hello Shai Samuel,

    May I have you provide an export of a reduced copy test script that demonstrates the issue that has all other code removed.

    To export a NinjaTrader 8 NinjaScript so this can be shared and imported by the recipient do the following:
    1. Click Tools -> Export -> NinjaScript Add-on...
    2. Click the 'add' link -> check the box(es) for the script(s) and reference(s) you want to include
    3. Click the 'Export' button
    4. Enter a unique name for the file in the value for 'File name:'
    5. Choose a save location -> click Save
    6. Click OK to clear the export location message
    By default your exported file will be in the following location:
    • (My) Documents/NinjaTrader 8/bin/Custom/ExportNinjaScript/<export_file_name.zip>
    Below is a link to the help guide on Exporting NinjaScripts.
    http://ninjatrader.com/support/helpG...-us/export.htm

    Once exported, please attach the file as an attachment to your reply.​
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Hi Chelsea, thank you for your quick reply. I took the time to create a simple example with the relevant code.
      If you remove the comment // at line 88 to activate the [NinjaScriptProperty], and then reload the strategy, you will see the issue.

      However, I managed to identify the issue with my enum, which had values attached to each item, and these values included negative values, as you can see in S_TimeFrameTypes. This works fine for Indicator properties, but not for Strategy properties.

      I did find a solution, removing these values or changing them to all positive, and in order. I believe this is a bug, and better be fixed.
      Attached Files
      Last edited by Shai Samuel; 03-25-2023, 02:17 PM.

      Comment


        #4
        Hello Shai Samuel,

        I see you have custom logic and a loop in your script that is different than the reference sample.

        Just to narrow down the specific issue and to rule out the custom logic, if you use the reference sample and replace the values with your values in the enum, are you able to reproduce the behavior?

        This removes properties, creates new properties, and adds these to the propertyDescriptorCollection on lines 331 to 350 and does not use a loop.

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

        If you are wanting to use specific integer values, would not make more sense to use an int instead of an enum?

        Below is a link to the reference sample on enums.


        Note the enums in this reference sample are not assigned integer values and are accessed by the definition.
        Chelsea B.NinjaTrader Customer Service

        Comment


          #5
          Thank you Chelsea for your comments. Yes, you are correct the I could just remove the ones with the negative conditions, and saving the add.This works find, and I advise adding it to the core NT as a way to control properties.

          I also wish you will provide a simple way to create sub-properties.

          Comment


            #6
            Hello Shai Samuel,

            Sub-properties, you are meaning a way to hide and show properties based on the value of other properties, without having to use a typeconverter to achieve this?
            Chelsea B.NinjaTrader Customer Service

            Comment


              #7
              Thank you Chelsea, by saying Sub-Properties I mean subgroup at the properties level. Having a simple abilities to split a group of properties to a few sub groups, in the similar simple way the properties are grouped today. For example breaking a "Risk Management" group in a Strategy to subgroups of "Stop Management", "Target Management", "Quantity Management", each subgroup with the ability to expand or fold.

              I know this is doable today, but it looks like much efforts.

              Comment


                #8
                Hello Shai Samuel,

                Yes, this is already possible to do with a class using an ExpandableObjectConverter typeconverter. Below is a link to an example.


                To confirm, you are wanting something easier than a class using this typeconverter?
                Chelsea B.NinjaTrader Customer Service

                Comment


                  #9
                  Yes, I have seen this, but it's quite complex.

                  By the way, I would be happy to share my toggle properties with NT to help make it a standard solution.

                  Comment


                    #10
                    Hello Shai Samuel,

                    To confirm, you are stating the 2 lines of code for declaring a class and using the typeconverter is too complex?

                    An example of the proper code for toggling properties on and off can be found in the help guide linked below.
                    Chelsea B.NinjaTrader Customer Service

                    Comment


                      #11
                      Dear Chelsea, I truly respect your support and efforts to assist us.

                      Thank you for this example. I have used it in my implementation and it is working fine. As far as Toggle option, it is quite simple, and the only thing I claim is it could be done as a standard within NT8 using a single call of a function, with no additional requirements.

                      As far as the secondary grouping level as shown in ExpandableClassPropertyBrushesExample, it is a bit more complex implementation, which I wish could be simplified.

                      Comment


                        #12
                        Hello Shai Samuel,

                        I am happy to submit a feature request for this to be simplified further.

                        However, all that is needed is to put the properties in a class that has the ExpandableObjectConverter applied. Its just two lines of added code..
                        Chelsea B.NinjaTrader Customer Service

                        Comment


                          #13
                          Dear Chelsea, is there a way to change the text on a property based on another property selection?
                          For example, say I have a stop unit, which can be {Ticks, ATR, Price}, I would like the Stop Value to have the unit on it, like: "Stop Value (Ticks)". How can I do that?

                          Comment


                            #14
                            Hello Shai Samuel,

                            You are wanting to change the Name property in the Display attribute?

                            Unfortunately, I do not have a sample of this custom C# I can provide you.

                            It might be easier to have multiple value properties, and hide/show the property with the selected unit in a custom typeconverter.
                            Chelsea B.NinjaTrader Customer Service

                            Comment

                            Latest Posts

                            Collapse

                            Topics Statistics Last Post
                            Started by yertle, Yesterday, 08:38 AM
                            7 responses
                            28 views
                            0 likes
                            Last Post yertle
                            by yertle
                             
                            Started by bmartz, 03-12-2024, 06:12 AM
                            2 responses
                            21 views
                            0 likes
                            Last Post bmartz
                            by bmartz
                             
                            Started by funk10101, Today, 12:02 AM
                            0 responses
                            5 views
                            0 likes
                            Last Post funk10101  
                            Started by gravdigaz6, Yesterday, 11:40 PM
                            1 response
                            9 views
                            0 likes
                            Last Post NinjaTrader_Manfred  
                            Started by MarianApalaghiei, Yesterday, 10:49 PM
                            3 responses
                            11 views
                            0 likes
                            Last Post NinjaTrader_Manfred  
                            Working...
                            X