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

Storing dynamically changes xml setting variable, back into xml file as current

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

    Storing dynamically changes xml setting variable, back into xml file as current

    Hello,

    I have some settings in the standard indicator NinjaScriptProperty section, which can be either dynamically changed by the indicator itself, or by the user, via a separate window. These are not stored on exit. Is there a simple supported way to tell Ninjatrader 8 to store the setting for future use, as if the user had gone into the indicator settings and changed the setting?

    Thanks.

    #2
    Hello pjsmith,

    Yes, if that object is also easily converted to a string (like bools, ints, doubles, strings). Or if you can convert the information to a string that string can be saved.

    See the article on serializing brush inputs for an example of converting an object to string
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Hi,

      Sorry, I think I have not explained myself correctly.

      Example -

      I have bool thisVar = false; as a setting in the NinjaScriptProperty properties section. The code (not the user) changes this to 'true' when the indicator is run. I want the setting stored as true for the next time the indicator loads. This, without the user going into the indicator properties and changing it. Save stetting state on exit, as it were.

      make sense?

      Thanks.

      Comment


        #4
        Hello pjsmith,

        If a public input is changed in real-time, that change will reflect in the Indicator window.

        If you change an input value with logic, the parameters in the Indicator Window will also change. If a template or workspace is saved after this point, the template or workspace will also save that change.

        (If the object is being saved in Xml or is properly serialized)
        Last edited by NinjaTrader_ChelseaB; 03-11-2019, 08:21 AM.
        Chelsea B.NinjaTrader Customer Service

        Comment


          #5
          OK - Thanks. I surely have missed something then. I will double check the code....

          Is it possible to save the setting without the user saving the workspace/template?

          Comment


            #6
            Originally posted by pjsmith View Post
            OK - Thanks. I surely have missed something then. I will double check the code....

            Is it possible to save the setting without the user saving the workspace/template?
            A public, serialized property will always have the value of the last value it had when it was serialized, regardless how that property value was changed at any time before that.

            Comment


              #7
              Hello pjsmith,

              Indicators and strategy instances are saved in the workspace or chart / script template.

              You could write something to file so save a value if you don't want this value saved in the workspace.

              The property will initialize with whatever is saved in the workspace. But you could overwrite that value from something read from file if you wanted.

              I'm not quite clear on what you trying to accomplish by saving an input value without saving the entire script instance with all of its properties in the workspace.

              Can you clarify what you are wanting to achieve?
              Chelsea B.NinjaTrader Customer Service

              Comment


                #8
                Sure - I have some indicator properties that can be set by the user when installing the indicator (normal xml settings). These settings however, are automatically optimised by the indicator during the time it runs. Those new settings should be used on the next start of the indicator (to prevent all that optimisation time being lost). So, if it's added to a chart, the internal settings may change over the course of the day. The user (me) is not aware of this. The platform may be quit (unexpectedly), or shut down and not saved. The new setting should therefore be updated in near real-time. There is also a separate window that appears allowing the user to change indicator setting on the fly without having to do it via ninjatrader indicator settings window and reloading the chart etc. These should be stored when changed.

                I realise I can fudge a probably 'unsupported' way, by re-writing the xml, but I was hoping there was a simpler and supported way to do change and save an indicator xml setting from within the indicator itself, on demand?

                Does that make sense?

                Comment


                  #9
                  Hello pjsmith,

                  I'm not understanding the issue.

                  If the user runs the script and the property values are updated in real-time by the script and the user saves their workspace, those updated values done by the script will be saved and will be what is used when the user restarts NinjaTrader. Please let me know if you would like a video demonstrating this.

                  Can you further clarify why this is insufficient for your needs?
                  Chelsea B.NinjaTrader Customer Service

                  Comment


                    #10
                    Originally posted by NinjaTrader_ChelseaB View Post
                    • and the user saves their workspace

                    A step I wish to avoid, because, 1, NT will crash, 2, user might not save workspace...

                    Comment


                      #11
                      Hello pjsmith,

                      Below are links to reference samples that demonstrate using StreamWriter and StreamReader in C#.

                      Chelsea B.NinjaTrader Customer Service

                      Comment


                        #12
                        Thank you. I do know how to use these, I was just trying to avoid that direct approach, else I fall down the 'unsupported' rabbit hole... If there is no supported function to tell NT to store a variable and use it's own routines, I will simply update the XML file directly. Thanks.

                        Comment

                        Latest Posts

                        Collapse

                        Topics Statistics Last Post
                        Started by inanazsocial, Today, 01:15 AM
                        1 response
                        5 views
                        0 likes
                        Last Post NinjaTrader_Jason  
                        Started by rocketman7, Today, 02:12 AM
                        0 responses
                        10 views
                        0 likes
                        Last Post rocketman7  
                        Started by dustydbayer, Today, 01:59 AM
                        0 responses
                        1 view
                        0 likes
                        Last Post dustydbayer  
                        Started by trilliantrader, 04-18-2024, 08:16 AM
                        5 responses
                        23 views
                        0 likes
                        Last Post trilliantrader  
                        Started by Davidtowleii, Today, 12:15 AM
                        0 responses
                        3 views
                        0 likes
                        Last Post Davidtowleii  
                        Working...
                        X