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

Templates for AddOns

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

    Templates for AddOns

    Hello Add-On Development Forum,

    I'm working on an AddOn with a variety of settings that I would like preserved with the Workspace so the AddOn is setup the way I left it if I close the AddOn or NT8.

    I've tried adding some properties to preserve the settings I want, but I'm finding they are not being serialized or recovered when the AddOn is created with a new instance or after an NT restart.

    Thanks!
    daqu40
    NinjaTrader Ecosystem Vendor - QTradez

    #2
    Hello daqu40,

    Thank you for your post.

    You would need to look into the IWorkspacePersistence interface at the following link: https://ninjatrader.com/support/help..._interface.htm

    You can find an example of using the IWorkspacePersistence interface to save options in the AddOnFramework example at the following link: https://ninjatrader.com/support/help...t_overview.htm

    Please let me know if you have any questions.

    Comment


      #3
      Thanks Patrick,

      Of course I found this code in the AddOn Framework after making this post.

      I should be good, but will post back here if I have any more questions.

      Thanks!
      daqu40
      NinjaTrader Ecosystem Vendor - QTradez

      Comment


        #4
        I'm back. Something seems amiss here.

        I've worked with the example of AddOn_Framework_NinjaScript_Basic. In the examples you can see here, the only thing it is saving is the selected instrument.

        Configured pic: http://prntscr.com/m49fmh
        After close and open AddOn Framework: http://prntscr.com/m49ftj

        I've attempted to intercept the Save and Restore methods of both the NTTabPage and NTWindow classes with Visual Studio and the breakpoints are never hit. The code clearly shows that at least the instrument and account should be saved and restored. The instrument part works, but not the account.

        Code:
                
        // NTTabPage member. Required for storing elements to workspace
                protected override void Save(XElement element)
                {
                    if (element == null)
                        return;
        
                    // Save the currently selected account
                    if (accountSelector != null && !string.IsNullOrEmpty(accountSelector.DesiredAccount))
                        element.Add(new XElement("Account") { Value = accountSelector.DesiredAccount });
        
                    // Save the currently selected instrument
                    if (Instrument != null)
                        element.Add(new XElement("Instrument") { Value = Instrument.FullName });
                }
        So I'm puzzled as to what is being called that saves the instrument, but doesn't save the account. If wish to save several other controls/properties in my AddOn I need to know which methods to add/edit to get the results.

        If someone could update the AddOn_Framework... example so it is able to save the account and a few other properties, I'm sure the whole community would benefit.

        Thanks!
        daqu40
        NinjaTrader Ecosystem Vendor - QTradez

        Comment


          #5
          Hello daqu40,

          Thank you for the reply.

          I wanted to better understand your expectation and goal here. You noted
          "After close and open AddOn Framework".
          Are you saying that you are closing the window and reopening a new window?

          There is a difference between closing the addon window and saving it with the workspace, the IWorkspacePersistence interface is specifically for saving values in the workspace which I see working on my end using breakpoints. This happens only when saving a workspace that has changes or loading a non-open workspace. Closing the window and reopening the window will not trigger these events as IWorkspacePersistence is not a template or preset system.

          Are you looking for something to save as a template or defaults for the tab when you reopen a new window?

          I look forward to being of further assistance.
          JesseNinjaTrader Customer Service

          Comment


            #6
            Thanks Jesse,

            After more work I noticed the same behavior.

            So YES, I would like to save save the properties of the AddOn in a template or something similar. I see methods within the NTTabPage for Save and Restore. These are triggered when the Workspace is saved or opened. Are the events when the NTTabPage is opened or closed that can be used to trigger these methods?

            daqu40
            NinjaTrader Ecosystem Vendor - QTradez

            Comment


              #7
              Hello daqu40,

              As far as I am aware there is nothing documented for this kind of use that I could suggest. There is currently no native "preset" or "template" control system that is exposed to NinjaScript use. You would likely need to save/load your own file for the overall addon or each tab if you wanted to do this.

              Depending on how you wanted to approach this type of loading, you would likely need to make this part of the tab factory or the tab items constructor for loading settings. For saving you could add a button similar to the indicator preset save/load buttons to define a new default. It would also depend if you wanted general settings for the tabs or individual settings for each tab.



              I look forward to being of further assistance.

              JesseNinjaTrader Customer Service

              Comment


                #8
                Thanks Jesse,

                I'll try the approach of saving my own file for the last state of the tab.

                One last question for myself and the benefit of anyone following this thread. Are there any events that fire as a new NTTabPage is constructed or destroyed that would be better for loading/saving my properties than the NTTabPage constructor or the CleanUp?
                daqu40
                NinjaTrader Ecosystem Vendor - QTradez

                Comment


                  #9
                  Hello daqu40,

                  I am unable to see any other NinjaTrader events that would be called here that would be better for the use case. This would likely need to happen around the same time when you construct your xaml so you could apply settings in addition to loading the UI. Cleanup would likely be the best place to save as the platform calls this override for all platform necessary events.

                  I look forward to being of further assistance.
                  JesseNinjaTrader Customer Service

                  Comment


                    #10
                    Thanks Jesse,

                    I'll use the constructor and CleanUp.
                    daqu40
                    NinjaTrader Ecosystem Vendor - QTradez

                    Comment

                    Latest Posts

                    Collapse

                    Topics Statistics Last Post
                    Started by Christopher_R, Today, 12:29 AM
                    0 responses
                    6 views
                    0 likes
                    Last Post Christopher_R  
                    Started by sidlercom80, 10-28-2023, 08:49 AM
                    166 responses
                    2,235 views
                    0 likes
                    Last Post sidlercom80  
                    Started by thread, Yesterday, 11:58 PM
                    0 responses
                    3 views
                    0 likes
                    Last Post thread
                    by thread
                     
                    Started by jclose, Yesterday, 09:37 PM
                    0 responses
                    7 views
                    0 likes
                    Last Post jclose
                    by jclose
                     
                    Started by WeyldFalcon, 08-07-2020, 06:13 AM
                    10 responses
                    1,415 views
                    0 likes
                    Last Post Traderontheroad  
                    Working...
                    X