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!
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
NinjaTrader
Running a function when NT quits
Collapse
X
-
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,Tags: None
-
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
-
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
-
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
-
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); } }
Code:'NinjaTrader.NinjaScript.Indicators.Indicator.Foo' is a 'field' but is used like a 'type'
Comment
-
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 andrewtrades, Today, 04:57 PM
|
1 response
5 views
0 likes
|
Last Post Today, 05:02 PM | ||
Started by chbruno, Today, 04:10 PM
|
0 responses
3 views
0 likes
|
Last Post
by chbruno
Today, 04:10 PM
|
||
Started by josh18955, 03-25-2023, 11:16 AM
|
6 responses
436 views
0 likes
|
Last Post
by Delerium
Today, 03:42 PM
|
||
Started by FAQtrader, Today, 03:35 PM
|
0 responses
7 views
0 likes
|
Last Post
by FAQtrader
Today, 03:35 PM
|
||
Started by rocketman7, Today, 09:41 AM
|
5 responses
19 views
0 likes
|
Last Post Today, 03:33 PM |
Comment