Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Add-on persistence not working, also Mutexes

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

    Add-on persistence not working, also Mutexes

    Hello Ninjatrader Support,

    1) I've written a lot of indicators and strategies. But this weekend I took on the challenge of writing my first add-on. I used as a model the AddonShellExample.cs code, which was written by someone at Ninjatrader. I got a lot done and have a working prototype. There are a couple of problems. One is that, the property persistence code doesn't work. It doesn't even work in the example. Try it yourself. Change one of the properties, close the window and reopen it. The value of the property will revert to the original value. I'm not using tabs, so I'm trying to use the window properties. But they don't get saved, but the tab properties didn't, either, Save() and Restore() for both don't even get called. What's missing?

    2) I want only one instance of my add-on window to appear. I've tried semaphores and mutexes, but haven't had much success. What is the best way to make sure for when a user tries to open another copy of the add-on, it does not open and even sends focus to the already existing instance?

    As always, thanks for your help.
    Last edited by gbourque; 08-19-2024, 01:13 PM.

    #2
    Hello gbourque,

    The AddonShellExample is not designed to save values but the other sample is. Here is a description: https://forum.ninjatrader.com/forum/...447#post790447

    Please try the AddonShellNoTabs_NT8 in the same use case and see if you are having any problems.

    Regarding the singular window, that would be a difficult concept in NinjaTrader with the code that is used to instantiate the window class. The only two ways that I could think may work would be to use a static class with a static property to hold an instance of the window, check if the variable is null or not to know if its open or not. That will fail though when a compile happens, that instance will be cleared so that would really only work if you are not doing compiles. An alternative would be to write to a file when the window is open and then check if that file exists before trying to open a new window, if it exists loop through the AllWindows collection and bring the window to the front. If the window is closed delete the file. That would persist through compiles.

    Comment


      #3
      Thanks for the advice on the single instance problem. As to the property persistence, my issue is Save and Restore are never getting called at all. So I don't think the code within them matters much in that case. Why aren't they getting called?

      Comment


        #4
        The implication in the documentation is that these are called by the base class. I don't see anything in the documentation that says that my code should call them, nor what values it should pass to them if it did. The documentation on writing add-ons is pretty sparse. But I know there are commercial add-ons that save property values. So I would just like to know how to do it. If you point me to a thread, please tell me which post in the thread and which link in the post are relevant.

        Comment


          #5
          Hello gbourque,

          Are you testing the file from this link specifically? https://forum.ninjatrader.com/forum/...830#post759830

          I just tried it and see both save and restore are called when saving the workspace and the values of the inputs are retained. Those methods only get called during saving and loading workspaces.

          Comment


            #6
            Okay, so I have to save the workspace while the add on is active. Is that what you are saying? With indicators and strategies that's not necessary.

            Comment


              #7
              Hello gbourque,

              Correct, that works the same as any other windows in the workspace. If you dont save the workspace the windows and their settings are not saved. Indicators and strategies are the same way, if your workspace had a chart open when you load it without anything applied, then you apply items and do not save the workspace the next time you load it they will be gone. Indicators and strategy also have a seperate template system so you can manually load different settings or set defaults for when you apply them.

              Comment


                #8
                Okay, when I saved the workspace my Save was called. But when does Restore get called? I closed the addon window and re-opened it and Restore wasn't called and the property value was not restored.

                Comment


                  #9
                  Hello gbourque,

                  Restore is only called when loading a workspace. Closing and re opening the window is unrelated to save and restore, those are specifically for the workspace. The name of this inheritance is the IWorkspacePersistence which relates directly to the workspace.

                  Comment

                  Latest Posts

                  Collapse

                  Topics Statistics Last Post
                  Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                  0 responses
                  646 views
                  0 likes
                  Last Post Geovanny Suaza  
                  Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                  0 responses
                  367 views
                  1 like
                  Last Post Geovanny Suaza  
                  Started by Mindset, 02-09-2026, 11:44 AM
                  0 responses
                  108 views
                  0 likes
                  Last Post Mindset
                  by Mindset
                   
                  Started by Geovanny Suaza, 02-02-2026, 12:30 PM
                  0 responses
                  570 views
                  1 like
                  Last Post Geovanny Suaza  
                  Started by RFrosty, 01-28-2026, 06:49 PM
                  0 responses
                  573 views
                  1 like
                  Last Post RFrosty
                  by RFrosty
                   
                  Working...
                  X