Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

AddOns folder

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

    AddOns folder

    I have a question about the use of the AddOns folder. To help explain I need to review a couple of things you probably already know to make sure I’m understanding it correctly, then I can ask my question.

    Two things:

    First:

    I’m looking into how to write an AddOn and for learning I’m using the NT8 help and the example AddOnFramework

    Code:
            // Will be called as a new NTWindow is created. It will be called in the thread of that window
    		protected override void OnWindowCreated(Window window)
    		{
                // We want to place our AddOn in the Control Center's menus
    			ControlCenter cc = window as ControlCenter;
    			if (cc == null)
    				return;
    
                /* Determine we want to place our AddOn in the Control Center's "New" menu
                Other menus can be accessed via the control's "Automation ID". For example: toolsMenuItem, workspacesMenuItem, connectionsMenuItem, helpMenuItem. */
    			existingMenuItemInControlCenter = cc.FindFirst("ControlCenterMenuItemNew") as NTMenuItem;
    			if (existingMenuItemInControlCenter == null)
    				return;
    I can see that it’s the AddOn’s responsibility for actually adding the menu item and this code shows how to do it.

    When I imported AddOnFramework NT said that it detected a new AddOn and it then “installed” it. This example AddOnFramwork adds a menu item to the NT control center window:

    I’m also assuming that the OnStateChange handler is called during this “discovery, load and install phase”.

    Code:
            // Same as other NS objects. However there's a difference: this event could be called in any thread
    		protected override void OnStateChange()
    		{
    			if (State == State.SetDefaults)
    			{
    				Description = "Example AddOn demonstrating some of the framework's capabilities";
    				Name        = "AddOn Framework";
    			}
    		}
    It's especially noteworthy that the OnStateChange could be called on any thread.


    Second:

    I’ve written on this forum previously about my use of the AddOns folder for “general” purpose code to support indicators and strategies



    And I’ve concluded from that exchange that the AddOns folder is really not intended for general purpose code but rather just AddOns.
    And now coming to my question..
    It appears from studying this AddOn that NT may scan the AddOns folder and look for code to load. If it’s doing this it may try to load parts of my ninjascript support code in there.

    Is this a possibility and is it a concern? If it is scanning, when does it do that? I've been adding items to that folder from within Visual Studio and they are not always necessarily ready to be run even if they compile. Could NT be trying to load and run code as I'm developing because it's in the AddOns folder?

    #2
    Hello Brillo,

    Thank you for your post.

    I will check with development on this.

    Comment


      #3
      There is a FileSystemWatcher in place when the NinjaScript Editor is open. You can find information on this at the following link: https://msdn.microsoft.com/en-us/lib...v=vs.110).aspx

      So as you are developing with the NinjaScript Editor open any files added to the folders would be compiled.

      Comment


        #4
        Indicators, Strategies, AddOns exporting Importing

        Originally posted by NinjaTrader_PatrickH View Post
        There is a FileSystemWatcher in place when the NinjaScript Editor is open. You can find information on this at the following link: https://msdn.microsoft.com/en-us/lib...v=vs.110).aspx

        So as you are developing with the NinjaScript Editor open any files added to the folders would be compiled.
        Thank you Patrick.

        My questions are not about when it's compiled but rather when an AddOn is installed ( meaning it's menu items have been added to NT), how its installed ( roles of NT and the AddOn itself ) and potentially how other files the AddOns folder ( that are not "AddOns" ) could behave.

        It appears to me from the sample AddOn that the AddOn itself is being run as part of the installation.
        1. Is that correct?

        This means our code plays a role in the installation itself.

        2. What triggers it to run ( for the purpose of installing)? is it when the user imports it using the Control Center? Or is it after it's compiled?

        2.1 If it's only run/installed when importing then how are we expected to get it installed during development for testing? I expect we can export it and import it but is that what's expected?

        3. Depending on the answer to #2 I would suspect some issues with putting other code in the AddOns folder that's not actually part of ANY AddOn. I do this for reasons explained in the post that I shared a link to earlier in this thread ( in short, I need to be able to export that code along with Indicators and Strategies, yet that code is general purpose supporting code for both Indicators and Strategies and consequently I don't want to put it in the Indicators or Strateges folder... instead I put it in the AddOns folder as it's the only other folder that I can export from ).

        3.1 As a consequence of putting some supporting code in the AddOns folder I'm able to export it with my indicators and strategies. BUT when I import this into another NinjaTrader, NT prompts the user that says (paraphrasing here): "NinjaTrader has detected an AddOn..." At first I thought it was just calling my indicator/strategy and AddOn but I'm now realizing it thinks that my indicator is an AddOn to extend NT rather than just an indicator/strategy. The likely reason is that it's because there's an AddOns folder in the zip file along with some supporting code in it. All of this observation and theory is fuel for my request for NT to provide another folder, not an AddOn folder, that we can put code in that's not categorized as indicator or strategy or Addon. It's just supporting code AND provide that this folder ( and subfolders ) may be exported / imported along with our Indicators, Strategies and AddOns.

        5. BTW, I didn't ask before but How is uninstalling handled?

        Finally, if I missed it I'm sorry but a guide in the help system should be provided that addresses all of these questions about the AddOns.

        Comment


          #5
          Hello Brillo,

          Thank you for your response.

          The Add On is "installed" when NinjaTrader compiles. Should also require a restart of NinjaTrader for it to appear in the Menu you assign it to.

          1. Once compiled the Add On is added to the CS project for NinjaTrader.
          2. It's when it's compiled and added to the project.
          3. Doesn't matter what folder you put the code in. Once it's compiled it's added to the project.
          4. Uninstalling is handled in the same manner. The object is removed from the folders and then NinjaTrader will need to compile.

          On the final note it does not matter what object it is, all objects must compile to be added to the project.

          Please let me know if you have any questions.

          Comment


            #6
            Hi Patrick,
            I know that my last post was lengthy and I try to avoid asking so many questions at once but this time it was unavoidable as it is all related and I can’t explain just one part without the other. I'm afraid that I must continue to be verbose to try and align our thinking. Please take your time in digesting and I will patiently wait your response.

            About your answers to my questions:


            Originally posted by NinjaTrader_PatrickH View Post
            The Add On is "installed" when NinjaTrader compiles. Should also require a restart of NinjaTrader for it to appear in the Menu you assign it to.
            I don’t see that happening and I’m not at all surprised about that. First, let’s define “installed”. I’m not talking about its addition to the NinjaTrader.Custom project file. I’m talking about it being installed so that NinjaTrader is showing any menu items the AddOn has added in order to launch the AddOn. From what I see in the example, the AddOn MUST RUN at least once, in order to add its own menu item. This bootstrapping happens in the example’s OnWindowCreated method. That will not run on completion of compilation or addition to the NinjaTrader.Custom project file. I confirmed this. I wrote a simple AddOn ( basically made another copy of the sample AddOnFramework and changed the names of the menu it’s adding in the OnWindowCreated method). It compiles. I restarted NT. But it did not add its own menu item. By comparison, when I installed the AddOnFramework sample, I did so using the NT import NinjaScript utility. At that time NT prompted to me with a dialog box asking me to confirm my acceptance of this new AddOn being added. I expect that upon agreeing that NT then compiled the AddOn and launched it so that it could run the OnWindowCreated method that adds the menu item to the Control Center.

            Originally posted by NinjaTrader_PatrickH View Post
            1. Once compiled the Add On is added to the CS project for NinjaTrader.
            1. Yes I see that it's added to the CS project but it's not added to the NinjaTrader GUI after compiling. Even after restarting NT.

            Originally posted by NinjaTrader_PatrickH View Post
            2. It's when it's compiled and added to the project.
            2. No it's not. See #1.

            Originally posted by NinjaTrader_PatrickH View Post
            3. Doesn't matter what folder you put the code in. Once it's compiled it's added to the project.
            3/ Yes I see that happening. However it DOES matter what folder it’s in if one wants to make the code available for exporting. This is a secondary issue to this thread that I only swept in as it may have some consequence for our discussion. And so let's put that aside.

            Originally posted by NinjaTrader_PatrickH View Post
            4. Uninstalling is handled in the same manner. The object is removed from the folders and then NinjaTrader will need to compile.
            4. I don't think so but let's put this aside for now. ( Again, it's my contention that the AddOn MUST run in order for it to install so then it MUST run for it to be unistalled... with code that is not included in the sample provided ).


            I can't confirm that your answers to my questions #1 and #2 are correct and I'm not surprised by that. The AddOn code MUST RUN and compiling does not run it.

            Comment


              #7
              Hello Brillo,

              Thank you for your response.

              OnWindowCreated would be called when any window is created. If the window you are looking to add the Add On to is found and your code confirms it then your Add On is created.

              So are you asking when OnWindowCreated and OnWindowsDestroyed are called to instigate the creation of your Add On?

              Comment


                #8
                AddOn installing and UnInstalling

                Originally posted by NinjaTrader_PatrickH View Post
                ..are you asking when OnWindowCreated and OnWindowsDestroyed are called to instigate the creation of your Add On?
                Yes.

                I would also like to know how an AddOn can be uninstalled.

                Based on my current understanding...

                1. To install I would
                a) Write code in OnWindowCreated to add the AddOn ( like the sample ).
                b) export the AddOn
                c) import it.( In order to trigger it to be run for the first time at which time it adds it's menu

                2. To UNInstall:
                All the same as #1 except that the code in step "a" would need to be changed to something that removes the menu item.

                These steps seem a little bit cumbersome for developers ( for development and testing ) as well as customers ( To uninstall then have to import another AddOn? Seems odd ).
                Last edited by Brillo; 11-10-2016, 10:28 AM. Reason: provide title

                Comment


                  #9
                  Hello Brillo,

                  Thank you for your response.

                  NinjaTrader does not run whatever file is added to the folder. When the Custom .dll is compiled it will look for any type of the AddOnBase and add it to the Add Ons collection. It will then set the state of the object to active at which point the OnWindowCreated method runs. If any object is not of type AddOnBase it will not run in the same manner. So you could have an IndicatorBase object in the folder and it would not run in this manner.

                  Uninstalling would be the opposite. The object is removed, NinjaTrader compiles, and the object is removed from the collection and thus no longer State.Active.

                  Comment


                    #10
                    Hi Patrick.
                    I think this clears it up for me. I'm presently wrestling with some other issues but at least I was able to get an AddOn added to the Control Center w/out importing. I had to restart NT8 but that was due to some other issues. I was hoping to confirm that it would run after being compiled. That will have to wait.
                    Thank you for explaining.
                    Tim

                    Comment

                    Latest Posts

                    Collapse

                    Topics Statistics Last Post
                    Started by jclose, Today, 09:37 PM
                    0 responses
                    5 views
                    0 likes
                    Last Post jclose
                    by jclose
                     
                    Started by WeyldFalcon, 08-07-2020, 06:13 AM
                    10 responses
                    1,413 views
                    0 likes
                    Last Post Traderontheroad  
                    Started by firefoxforum12, Today, 08:53 PM
                    0 responses
                    11 views
                    0 likes
                    Last Post firefoxforum12  
                    Started by stafe, Today, 08:34 PM
                    0 responses
                    11 views
                    0 likes
                    Last Post stafe
                    by stafe
                     
                    Started by sastrades, 01-31-2024, 10:19 PM
                    11 responses
                    169 views
                    0 likes
                    Last Post NinjaTrader_Manfred  
                    Working...
                    X