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

Expandable Object Params in Strategy Analyser

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

    #16
    Jessica,

    Thank you for your answer. I have read the documentation, in particular about cloning, but it is next to empty.

    Would you have any example for a custom CopyTo method for class properties?

    Comment


      #17
      I will follow up to see if there are any ways we can make our documentation more clear. Essentially the situation is

      * Every time you recompile, we reinsert a new NinjaTrader.Custom.dll
      * Every definition in this new dll is a new thing; an SMA object in the old dll is not an SMA object in the new dll
      * To work around this, we use reflection and a component model which has publicly available documentation here

      * While this works well with built-in types - and we can even perform some translation if say your new SMA has a property which became a short when your old one was an integer - anything that itself could have been redefined between .dlls (such as enums and classes that are written by you and compiled) must have explicit cloning instructions
      * We can handle this explicit cloning ourselves with enums, as we know exactly what an enum is and how to clone it; this was handled in NTEIGHT-11504
      * A user type you created, however, can only be explicitly handled by you

      Fortunately there is some sample code already on your system in which we demonstrate exactly this kind of handling. Please review the code for Documents\NinjaTrader 8\bin\Custom\ShareServices\@Facebook.cs . In the version of NinjaTrader I am running on, the CopyTo method which preserves Facebook.OAuth_Token, Facebook.FacebookUserId, and Facebook.UserName, can be found starting on line 41 .
      Last edited by NinjaTrader_JessicaP; 07-19-2017, 04:19 PM.
      Jessica P.NinjaTrader Customer Service

      Comment


        #18
        I have taken that piece of code from the Facebook Shared Services and added it to my custom indicator. However, the properties still do not persist after a recompile.

        If you look at the basic sample below ... which properties would need to be set in the CopyTo method

        - the single property of the indicator class
        - or the three properties of the subclass?

        I have tried both, but without success.

        Do I need to serialize/deserialize the ExampleClass property?
        Attached Files

        Comment


          #19
          While I am working on preparing an example, I need to mention that your ExampleClass is not supported usage for our goal, since it's nested inside an indicator. Please see this forums post for more information regarding NTEIGHT-11645 and why this is the case.



          Post 14 is where we mention why this is the case.
          Last edited by NinjaTrader_JessicaP; 07-20-2017, 02:59 PM.
          Jessica P.NinjaTrader Customer Service

          Comment


            #20
            Jessica,

            Your help is much appreciated.

            I had not moved that class into the indicator namespace, as it is only used by a single indicator for the purpose of creating expanded properties.

            I am waiting for your version with patience...

            Comment


              #21
              The attached script implements both the CopyTo example I mentioned in the Facebook script, and the Clone advice in the help guide mentioned previously, to enable your custom properties to persist compiles. While I have not moved your nested class to the top level you are advised to do so at your earliest convenience.

              Code samples we provide are for educational purposes, and are not intended for live trading, and are not guaranteed to accomplish any user goal or to be maintained.
              Attached Files
              Jessica P.NinjaTrader Customer Service

              Comment


                #22
                Jessica,

                Thank you very much for your efforts. I believe that it should work, but unfortunately it does not.

                I have applied your modified sample to a chart and then recompiled another indicator that I had edited in the NinjaScript Editor. When refreshing the chart, the behavior of the indicator was similar to the case observed with the old sample.

                Error messages in the log file:

                2017-07-20 23:38:29:074|3|4|Error on getting/setting property 'ExampleClassVariable' for NinjaScript 'Sample public class property': Object of type 'NinjaTrader.NinjaScript.Indicators.SamplePublicCl assProperty+ExampleClass' cannot be converted to type 'NinjaTrader.NinjaScript.Indicators.SamplePublicCl assProperty+ExampleClass'.
                2017-07-20 23:38:29:076|3|4|Unable to create instance of NinjaScript 'Sample public class property'. Most likely either the implementation no longer exists, there is no default constructor defined, the default constructor does not work correctly, or the 'OnStateChange' implementation for State=SetDefaults is flawed: System.InvalidOperationException: 'DrawHorizontalGridLines' cannot be set from this state. Please see the Help Guide article on 'DrawHorizontalGridLines' for more information. at NinjaTrader.NinjaScript.IndicatorBase.set_DrawHori zontalGridLines(Boolean value) at NinjaTrader.NinjaScript.IndicatorBase.CopyTo(Ninja Script ninjaScript) at NinjaTrader.Gui.NinjaScript.IndicatorRenderBase.Co pyTo(NinjaScript ninjaScript) at NinjaTrader.NinjaScript.Indicators.SamplePublicCla ssProperty.CopyTo(NinjaScript ninjaScript) at NinjaTrader.NinjaScript.NinjaScript.Clone()
                2017-07-20 23:38:29:076|3|16|Failed to restore Indicator 'NinjaTrader.NinjaScript.Indicators.SamplePublicCl assProperty'. Most likely (a) the implementation changed or (b) one or more properties have been renamed or removed or (c) the custom assembly which implements this Indicator no longer is there.

                Comment


                  #23
                  I'm glad we were able to resolve your query related to presets. The relevant text from the message you sent me is the plus sign in this line between SamplePublicClassProperty and ExampleClass. This is related to the advice I gave you previously regarding NTEIGHT-11645 and the linked forums thread I mentioned in post 19.

                  Code:
                  [FONT=Courier New]Time    Category    Message
                  20/07/2017 16:06:17    Default    Error on getting/setting property 'ExampleClassVariable' for NinjaScript 'Sample public class property': Object of type 'NinjaTrader.NinjaScript.Indicators.SamplePublicClassProperty+ExampleClass' cannot be converted to type 'NinjaTrader.NinjaScript.Indicators.SamplePublicClassProperty+ExampleClass'.[/FONT]
                  One of my colleagues will be able to help you out with more information regarding this. I encourage you to experiment moving ExampleClass outside of your Indicator so it is no longer subclassed in the meantime.
                  Jessica P.NinjaTrader Customer Service

                  Comment


                    #24
                    IMPORTANT NOTE: This will still not operate. A separate behavior not yet discussed in this thread was revealed. This post is only to help you understand the importance of NTEIGHT-11645 since there is not yet documentation available regarding this.

                    I've consulted with my colleagues and I am working with the responsible teams to update the helpguide. For the time being please treat the forums post I linked to earlier as a canonical reference regarding NTEIGHT-11645 . For convenience that page is here,



                    While I understand

                    Originally posted by Harry
                    I had not moved that class into the indicator namespace, as it is only used by a single indicator for the purpose of creating expanded properties.
                    Failing to do so will result in the log message you saw. I have attached a copy of your script where I have done this.
                    Attached Files
                    Last edited by NinjaTrader_JessicaP; 07-21-2017, 03:13 PM.
                    Jessica P.NinjaTrader Customer Service

                    Comment


                      #25
                      If you try to compile and run the script I sent in Post #24 you will receive a new message in your logs. That message looks like

                      Code:
                      [FONT=Courier New]+-----------+------------+-----------------------------------------------------+
                      |   Time    |  Category  |                     Message                         |
                      +-----------+------------+-----------------------------------------------------+
                      | 7/21/2017 | 2:35:42 PM | Default Error on getting/setting property           |
                      |           |            | 'ExampleClassVariable' for NinjaScript 'Sample      |
                      |           |            | public class property': Object of type              |
                      |           |            | 'NinjaTrader.NinjaScript.ExampleClass' cannot be    |
                      |           |            | converted to type                                   |
                      |           |            | 'NinjaTrader.NinjaScript.ExampleClass'.             |
                      +-----------+------------+-----------------------------------------------------+[/FONT]
                      To address this separate behavior we are modifying the help guide once more. The advice will ultimately be to set [Browseable(false)] so this property is not cloned, or making a new full NinjaScript object and using IndicatorBaseConverter or StrategyBaseConverter.

                      For more information on using these prefab converters please review this page.



                      Please let us know if there are any other ways we can help.
                      Last edited by NinjaTrader_JessicaP; 07-21-2017, 03:10 PM.
                      Jessica P.NinjaTrader Customer Service

                      Comment


                        #26
                        Jessica,

                        Thank you for your answer.

                        Primarily I was looking for a way to make the custom sample work.

                        Currently it stills resets to default values when I compile NinjaTrader.

                        This means that I am still stuck with the original problem.


                        When I include [Browsable [false)], the child properties for which the class was built can no longer be accessed. This does not help.

                        What would I need to do to make the expandable properties persistent in case of a recompile?

                        The link that you posted does not show any solution for this specific case.
                        Last edited by Harry; 07-29-2017, 09:52 AM.

                        Comment


                          #27
                          You are correct that [Browseable(false)] will prevent child properties from being accessed. This was suggested to show the limitations of the built-in support for properties. For more robust support the easiest way will, again, be to implement IndicatorBaseConverter or StrategyBaseConverter .

                          This said, since the limitation is with the built-in support (which we have now thoroughly explored), we can now discuss working around the built-in support completely and allowing you to implement your own serialization handling.

                          Recently we have developed an update to one of our code samples that may provide a complete work-around giving you exactly what you are after. This code has not passed code review, and is therefore being provided as an educational aid only. However, if you examine the way use case #5 has been implemented, you will see that this gives you full control and allows you to take full responsibility for serializing your code.

                          When the attached code passes internal code review I will update this thread with a link to the canon download site for this code sample. In the meantime, as it is meant to teach a method, while its performance and correctness are not guaranteed at this time, I will be happy to answer any questions I can about use case #5
                          Attached Files
                          Last edited by NinjaTrader_JessicaP; 07-31-2017, 08:45 AM.
                          Jessica P.NinjaTrader Customer Service

                          Comment


                            #28
                            Harry like I already told you in another post. If you use the readonly attribute rather than browsable false, it will persist the property and will not reset on a rebuild. Unfortunately you can see the serialised string in the properties list but it's the best solution I have found for this.

                            Comment


                              #29
                              We have updated the sample at http://ninjatrader.com/support/forum...ad.php?t=97919 . This displays a list to a user that can persist through compiles, and through saving / restoring presets, reliably.
                              Jessica P.NinjaTrader Customer Service

                              Comment


                                #30
                                So far I have not been successful to implement a solution to serialize a public class property.

                                Is there any hope that you may supply an example how to achieve this?

                                I am seeing others waiting for this as well.



                                The SamplePublicClassProperty.cs from post #24 does not work, as it reverts back to default settings after every recompile of an indicator.

                                For the SampleIndicatorTypeConverter.cs from post #27 I simply do not understand how to apply it to the problem of serializing an element of a public class.


                                Any help please? I have really no idea how to fix it, and I am not the only one.

                                Thank you.

                                Comment

                                Latest Posts

                                Collapse

                                Topics Statistics Last Post
                                Started by DJ888, 04-16-2024, 06:09 PM
                                4 responses
                                12 views
                                0 likes
                                Last Post DJ888
                                by DJ888
                                 
                                Started by terofs, Today, 04:18 PM
                                0 responses
                                11 views
                                0 likes
                                Last Post terofs
                                by terofs
                                 
                                Started by nandhumca, Today, 03:41 PM
                                0 responses
                                7 views
                                0 likes
                                Last Post nandhumca  
                                Started by The_Sec, Today, 03:37 PM
                                0 responses
                                3 views
                                0 likes
                                Last Post The_Sec
                                by The_Sec
                                 
                                Started by GwFutures1988, Today, 02:48 PM
                                1 response
                                9 views
                                0 likes
                                Last Post NinjaTrader_Clayton  
                                Working...
                                X