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

Running a function when NT quits

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

    Running a function when NT quits

    Is there any way for an Indicator to be notified when the user has decided to quit? I am creating a licensing system for my indicators and it would be nice if, upon user exit, I could send a message to my server to release all licenses for the user so he could use them on another machine. Thanks,

    #2
    Hello swcooke,

    You can trigger an action when the Control Center is closing in the OnWindowDestroyed override.

    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Thanks Chelsea. I have added a Print Message to the code example you referenced just to test (see below). Where do I put this? I tried putting this inside my Indicator class and got an error that "The name OnMenuItemClick does not exist in the current context."

      Code:
      public class MyWindowAddOn : AddOnBase
      {
          private NTMenuItem myMenuItem;
          private NTMenuItem existingMenuItem;
          protected override void OnStateChange()
          {
              if (State == State.SetDefaults)
               {
                    Description = "Our custom MyWindow add on";
                    Name        = "MyWindow";
               }
          }
          // Will be called as a new NTWindow is destroyed. It will be called in the thread of that window
          protected override void OnWindowDestroyed(Window window)
          {
              if (myMenuItem != null && window is ControlCenter)
              {
                  if (existingMenuItem != null && existingMenuItem.Items.Contains(myMenuItem))
                      existingMenuItem.Items.Remove(myMenuItem);
      
                  myMenuItem.Click -= OnMenuItemClick;
                  myMenuItem = null;
                  Print("NT is Closing");
              }
          }
      }

      Comment


        #4
        Hello swcooke,

        The OnMenuItemClick event method handler would need to be declared if you were planning to add menu items..



        That code removes the method event handler from the menu item from the Control Center New menu.. (and then removes the menu item from the New menu)
        Is this what you are trying to achieve?

        (I had assumed you were trying to put custom code in OnWindowDestroyed when the Control Center closes. Are you also adding menu items?)
        Chelsea B.NinjaTrader Customer Service

        Comment


          #5
          I have no interest in adding menu items. I was just looking for a way to run a function from an indicator upon the user exiting NT. Is there a way?

          Comment


            #6
            Hello swcooke,

            The OnWindowDestroyed() method will run when any window closes as I have previously suggested. You can choose to trigger an action when the Control Center is closed as NinjaTrader will be shutting down.

            You don't have add or remove menu items in this method. But if you do, declare them before calling them.
            Chelsea B.NinjaTrader Customer Service

            Comment


              #7
              Thanks, I have it working. One more question, how do I access my Indicator Variables inside of this override? For example, I have a simple variable called 'Foo' like this that is throwing the error below:

              Code:
                      public class MyWindowAddOn : AddOnBase
                      {
                          protected override void OnWindowDestroyed(Window window)
                          {
                              Print(Foo);    
                          }
                      }
              I get this error:

              Code:
              'NinjaTrader.NinjaScript.Indicators.Indicator.Foo' is a 'field' but is used like a 'type'

              Comment


                #8
                Hello swcooke,

                Unfortunately, currently there is not a supported means to call an indicator from an AddOn as these type of scripts do not have a synchronized primary series. Indicators can only be called from NinjaScript Strategies, Indicators, SuperDOM columns, and Market Analyzer Columns.

                Instead, you would need to explicitly write the logic of the indicator into the Addon code.

                A BarsRequest can be used to call unsynchronized data in an addon script that has no primary series.

                Below is a link to the help guide.



                Also, as a tip, indicators are called like methods with parenthesis.. e.g. VOL()
                Chelsea B.NinjaTrader Customer Service

                Comment

                Latest Posts

                Collapse

                Topics Statistics Last Post
                Started by wzgy0920, 04-20-2024, 06:09 PM
                2 responses
                26 views
                0 likes
                Last Post wzgy0920  
                Started by wzgy0920, 02-22-2024, 01:11 AM
                5 responses
                32 views
                0 likes
                Last Post wzgy0920  
                Started by wzgy0920, Yesterday, 09:53 PM
                2 responses
                49 views
                0 likes
                Last Post wzgy0920  
                Started by Kensonprib, 04-28-2021, 10:11 AM
                5 responses
                192 views
                0 likes
                Last Post Hasadafa  
                Started by GussJ, 03-04-2020, 03:11 PM
                11 responses
                3,234 views
                0 likes
                Last Post xiinteractive  
                Working...
                X