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

New tabs in Addons

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

    New tabs in Addons

    Hello

    I have a question. When new tabs are created on addons, do they work with the same variables than the another tab?

    I'd like to know if the new tabs work like a new instance and their variables work separately from the others tabs opened.

    For example, if I have in my addons a variable named entryOrder and I am using it , then if I open a another tab, the new tab would use the same variable that is being used in the first tab opened?

    Thank you for your answer.
    Last edited by jleira; 03-17-2021, 08:48 PM.

    #2
    Hello jleira,

    If you are using the sample addon from the help guide that demonstrates instances or tabs which do not share variables. Each new tab has its own content and variables etc.

    When the new tab button is clicked that will call the AddOnFrameworkWindowFactory and CreateTabPage which generates a new tab page.

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

    Comment


      #3
      Hello

      Thank you very much for solving my question. In fact I have done the test and it seems everything works very well.

      If it is not too much to ask, I would like to know if removing the content of public override void Cleanup () would make the Addons work if I have closed the Addon window or need to do something additional to achieve this functionality. Could you give me a hint or a nudge?

      Thanks in advance

      Comment


        #4
        Hello jleira,

        Generally you will need the Cleanup override in an addon to clean up event handlers, subscriptions or do other tasks. Removing what the sample has in its Cleanup method would prevent it from working right.

        If you are not using anything in the cleanup override it won't hurt anything to just have the override in the script.

        I look forward to being of further assistance.

        JesseNinjaTrader Customer Service

        Comment


          #5
          Thank you NinjaTrader_Jesse

          Actually what I want to know is how I can make the Addons keep running even after closing it.

          Comment


            #6
            Hello jleira,

            An addon already runs in the background by default. Only the window is opened or closed, the actual addon class which adds the menu to the control center is still running. That will be terminated and recreated when a compile happens though.

            If you are trying to make something which runs in the background and also has a UI you would need to make your always running logic in the base addon "public class AddOnFramework : AddOnBase" and then pass whatever is needed to the window/UI as needed through the AddOnFrameworkWindowFactory.

            Because compiles will restart the addon you would need to keep that in mind with whatever you make, it should be able to be restarted as you do compiles.
            JesseNinjaTrader Customer Service

            Comment


              #7
              Ninjatrader_Jesse, If it's not much of a hassle, could you provide me with a simple example to look at the logic and be able to do it myself?

              Excuse me for asking so much ...

              Comment


                #8
                Hello jleira,

                A sample like this would be fairly involved and would generally be pretty specific to what you are trying to create.

                What part of the concept are you having trouble with? Perhaps we can try to cover that directly.

                You mentioned you wanted an always running addon, what is the always running part supposed to be doing?

                Passing something to your addons UI from the background class could be achieved by using the classes constructor. If this is not something you are familiar with I would suggest researching "C# class constructors" online for more details on structuring C# classes and how data can be passed. At a high level it would look like the following:

                Code:
                Core.Globals.RandomDispatcher.BeginInvoke(new Action(() => new AddOnFrameworkWindow([B]someVariableToPassToTheUI[/B]).Sh ow()));
                That would involve modifying the AddOnFrameworkWindow class to have a constructor which takes a parameter. That may also involve modifying the AddOnFrameworkWindowFactory class to accept a parameter using its constructor and then passing it to the window/tab it created.



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

                Comment


                  #9
                  Ohh I understand you.

                  I modified the AddonFramework to copy the trades that are executed in one account to another. For example I added another accountSelector that would be the master selector where the trades would be copied from, create OnOrderUpdate2, OnExecutionUpdate2 and OnPositionUpdate and other things to handle the master account. Also create another series of checkboxes to activate the copy or not and another to choose to manipulate the targets and stops from the master account or not. Everything works like a charm but I would like to be able to open the Addon, change the settings that have to be changed, close it and keep copying and everything in the same way as if the Addon were open but it seems that it will be very difficult to do so. I'll try to learn about constrctors in C #.

                  Click image for larger version

Name:	MyCustomAddon.PNG
Views:	258
Size:	21.7 KB
ID:	1147239


                  Thanks for all your help Jesse

                  Comment


                    #10
                    Hello jleira,

                    Thanks for the reply.

                    Yes in that case you would need to keep your settings in the addon base class and pass anything which is needed to the new window. To be able to set values on properties in the base class you would likely need to use the AddOnFramework as the parameter and just pass the whole addon base "this" as a parameter. You could then access any properties on that base object from the window while its open.

                    Code:
                    Core.Globals.RandomDispatcher.BeginInvoke(new Action(() => new AddOnFrameworkWindow([B]this[/B]).Show()));
                    Passing the addon framewwork would allow you to access any defined properties on that object, for example your settings.
                    Code:
                    private AddOnFramework myFramework;
                    public AddOnFrameworkWindow(AddOnFramework framework)
                    {
                    myFramework = framework;


                    You could then pass myFramework to any new windows being opened. That would be done in the AddOnFrameworkWindow class like the following, keep in mind this requires adding a constructor to the AddOnFrameworkWindowFactory class and then a private variable just like shown in the above example. Those would go in the AddOnFrameworkWindowFactory class.

                    Code:
                    TabControlManager.SetFactory(tc, new AddOnFrameworkWindowFactory(myFramework));
                    I look forward to being of further assistance.
                    JesseNinjaTrader Customer Service

                    Comment

                    Latest Posts

                    Collapse

                    Topics Statistics Last Post
                    Started by geddyisodin, Today, 05:20 AM
                    2 responses
                    16 views
                    0 likes
                    Last Post geddyisodin  
                    Started by hazylizard, Today, 08:38 AM
                    0 responses
                    6 views
                    0 likes
                    Last Post hazylizard  
                    Started by Max238, Today, 01:28 AM
                    5 responses
                    43 views
                    0 likes
                    Last Post Max238
                    by Max238
                     
                    Started by giulyko00, Yesterday, 12:03 PM
                    3 responses
                    13 views
                    0 likes
                    Last Post NinjaTrader_BrandonH  
                    Started by habeebft, Today, 07:27 AM
                    1 response
                    16 views
                    0 likes
                    Last Post NinjaTrader_ChristopherS  
                    Working...
                    X