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

    Expandable Object Params in Strategy Analyser

    Hey there.

    I wonder if someone can help me with a small issue with ExpandableObject properties in the Strategy Analyzer.

    I've made a spike of the design pattern I've come up with for composable Strategy settings, comprising a Strategy and two indicators which I have attached.

    Each indicator has a settings model, which is the sole Ninjascript Property for the indicator, meaning the indicator can be instantiated like: Indicator(new IndicatorSettings()) rather than a massive parameter list.

    The strategy settings model contains the Models of two indicators. I love this method - the time I've wasted copying and pasting parameters between indicators and strategies before now. This is loads better.

    Anyway it is working great on the strategies Dialog. However the Strategy Analyser is not working as expected. The properties do appear there; however I am unable to specify the Optimiser parameters Min/Max/Increment e.g. "8;55;1". How can I make the strategy Analyser recognise these for the optimiser?

    Thanks

    Kevin
    Attached Files

    #2
    A follow-on issue with this...

    I'm using the System.Web Json Serializer for persistence in the spike strategy. I find its the easiest Serializer to work with in .NET as it was built for serializing objects.

    However the strategy Analyzer is moaning that the XML is wrong.

    There is an infinite number of ways that something can be serialized. Is there any sample code of the actual Serialization format that Ninjatrader expects? I've only seen code for brushes and fonts, and assumed that any string format would suffice, but clearly that's not the case.
    Attached Files

    Comment


      #3
      I am investigating your first question. However to your second question regarding serialization, it is the case that the output must fit inside of a well formed XML document. This does not exclude JSON per-se, but any characters such as <, >, non-ASCII 0x20-0x7F, and the like may cause the serializer not to work. This publicly available link has more information.

      W3Schools offers free online tutorials, references and exercises in all the major languages of the web. Covering popular subjects like HTML, CSS, JavaScript, Python, SQL, Java, and many, many more.


      As a reference I am giving you a code sample which is known to work for a completely different purpose, which you can use as a starting point toward outputting JSON that can fit inside a well formed XML document.

      I will be replacing this sample with one tailored to your use case, and will be making a recommendation that our documentation be updated, after I have done more research.

      Code:
      [FONT=Courier New]
              /// <summary>
              /// http://ninjatrader.com/support/helpGuides/nt8/en-us/working_with_brushes.htm
              /// </summary>
              [XmlIgnore]
              [Display (
                  ResourceType = typeof(Custom.Resource),
                  Name = "TestColor",
                  GroupName = "NinjaScriptParameters",
                  Order = 0
                  )]
              public Brush TestColor
              { get; set; }
       
              /// <summary>
              /// http://ninjatrader.com/support/helpGuides/nt8/en-us/working_with_brushes.htm
              /// </summary>
              [Browsable(false)]
              [NinjaScriptProperty]
              public string TestColorSerialize
              {
                  get { return GetColorName(((SolidColorBrush) TestColor).Color); }
       
                  /// <summary>
                  /// From this publicly available link
                  /// http://stackoverflow.com/questions/372693/convert-string-to-brushes-brush-color-name-in-c-sharp
                  /// <summary>
                  set { TestColor = (SolidColorBrush) new BrushConverter().ConvertFromString(value); }
              }
       
       
              /// <summary>
              /// From this publicly available link
              /// http://stackoverflow.com/questions/3934747/system-windows-media-color-to-color-name
              /// <summary>
              public static string GetColorName(System.Windows.Media.Color color)
              {
                  Type colors = typeof(System.Windows.Media.Colors);
                  foreach(var prop in colors.GetProperties())
                  {
                      if(((System.Windows.Media.Color)prop.GetValue(null, null)) == color)
                          return prop.Name;
                  }
       
                  throw new Exception("The provided Color '" + color.ToString() + "' is not named.");
              }[/FONT]
      Last edited by NinjaTrader_JessicaP; 06-01-2017, 03:05 PM.
      Jessica P.NinjaTrader Customer Service

      Comment


        #4
        Thanks Jess! Good thinking, I never thought about encoding. I will get on that now! Cheers

        Comment


          #5
          I have some more information regarding this.

          I am attaching a series of indicators I am using for testing, as a tool that I can make immediately available to you. If you are in doubt as to whether an ASCII character will cause serialization to fail simply attach the test indicator with the ordinal matching your ascii character to a chart, save your workspace, close Ninja, and reopen your workspace. If it's serializable, your chart will come up with your indicator attached. This publicly available reference can help you match characters to ordinal values.

          http://www.asciitable.com/index/asciifull.png

          When I am in the office again on Monday I will address your question regarding optimizing using the strategy analyzer and your design pattern.
          Attached Files
          Jessica P.NinjaTrader Customer Service

          Comment


            #6
            Thanks Jessica.

            I found a potential bug related to presistence of Nested Properties. I've attached a Spike.

            Steps to reproduce:

            - Open Ninjascript Output window and add the NestedSettingsPersistance Indicator to a chart
            - Note the output of the default string values for Local and nested values
            - Open Indicator settings and change values to "Other Nested String" and "Other local string",
            - save presets
            - push ok
            - observe the new values in the output as expected
            - remove indicator from chart and re-add
            - observe that the values "other nested" and "other local" have been retrieved, indicating that "save presets" has worked and the values were persisted correctly.
            - Rebuild Ninjascript
            - right click the chart and "reload Ninjascript"
            - Observe in the output window that the nested value is back to "default" - the persistence, which previously worked, has now failed after a rebuild.
            - Comment out "Browsable(false)" attribute from the NestedSettingsSerializable property and repeat the above tests.
            - By removing this property the persistence works as expected even after a rebuild. However the serialized string appears in the property browser which is not ideal.
            Attached Files

            Comment


              #7
              This behavior was confirmed on our end. We will be investigating this further. Please keep an eye on the NinjaTrader 8 Release Notes page for updates and bugfixes.





              Tracking ID:NTEIGHT-11779
              Attached Files
              Jessica P.NinjaTrader Customer Service

              Comment


                #8
                Hey Jess,

                Did you find out any further information about my Original Query in Post #1 below?

                Comment


                  #9
                  Due to the way I reported some things, I left this ticket in a state that was difficult for our tracking software to manage, and as a result have not put more effort into making the sorts of inputs you mentioned in post #1 vulnerable to the optimizer. I apologize for this. I am reviewing this now and will come back when I have more information.
                  Jessica P.NinjaTrader Customer Service

                  Comment


                    #10
                    I was unable to compile and run the spike you created in your first post. I received the attached errors. If the compile time errors are the question being asked, the reason for these is that the NinjaTrader compiler generates code automatically, and the code as written is incompatible with the generator. If there are special compiling instructions please let me know.
                    Attached Files
                    Jessica P.NinjaTrader Customer Service

                    Comment


                      #11
                      Hey Jess,

                      Try the attached. I think the Ninjascript code at the bottom had the Namespaces out of sync. If this doesn't work try deleting the Ninjascript code at the bottom and letting it regenerate.

                      Let me know if it works. I can send you a version without the Namespaces if necessary.

                      Kevin.
                      Attached Files

                      Comment


                        #12
                        Attached is a code sample that should do something like what you are describing. 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


                          #13
                          Hey Jess, thanks for the response. That works pretty well, I was hoping it would just pick up the nested properties, but your solution works for me!!

                          Thanks again

                          Kevin

                          Comment


                            #14
                            Originally posted by NinjaTrader_JessicaP View Post
                            Attached is a code sample that should do something like what you are describing. 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.
                            Hi Jessica,

                            I have tested the sample that you have attached, running the indicator with NT 8.0.7.1 Unfortunately, the sample does not work as expected.

                            When the indicator is applied to any chart with changed parameter settings, it will revert back to default settings as soon as NinjaTrader compiles.

                            The parameter values are correctly serialized when being saved as part of a chart template, but the indicator fails to keep its settings on an open chart during a recompile.

                            We had that identical problem with enums (see #ID 11504) until the release NT 8.0.7.0 fixed it.

                            Is there any solution available for this problem?

                            Comment


                              #15
                              Thank you for your interest Harry. The code I provided was designed to resolve reach4thelaser's query in post #1, and not the confirmed behavior in post #7 (NTEIGHT-11779) which you are referring to, with regard to recompiling.

                              However I am glad you have responded, as I have not followed up in this thread yet with regard to NTEIGHT-11779 .

                              If you would like persistance through recompiles, the missing piece here is writing a custom CopyTo method for class properties. This is not supported out-of-the-box, and is the user's responsibility to create. Without this method, Ninja's default behavior will be to reset custom class properties rather than waiting for any serialization I/O, which in turn only occurs as you create an instance of your NinjaScript object through a chart, after State.SetDefaults has occurred. In light of this situation, we have updated our documents and reference samples. I especially recommend reviewing our help guide documentation on cloning.



                              Jessica P.NinjaTrader Customer Service

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by Mindset, 05-06-2023, 09:03 PM
                              10 responses
                              262 views
                              0 likes
                              Last Post NinjaTrader_BrandonH  
                              Started by michi08, 10-05-2018, 09:31 AM
                              5 responses
                              741 views
                              0 likes
                              Last Post NinjaTrader_ChelseaB  
                              Started by The_Sec, Today, 02:29 PM
                              0 responses
                              2 views
                              0 likes
                              Last Post The_Sec
                              by The_Sec
                               
                              Started by tsantospinto, 04-12-2024, 07:04 PM
                              4 responses
                              62 views
                              0 likes
                              Last Post aligator  
                              Started by sightcareclickhere, Today, 01:55 PM
                              0 responses
                              1 view
                              0 likes
                              Last Post sightcareclickhere  
                              Working...
                              X