I want to save the instrument name from the indicator to a variable and use it when initializing an add-on. The problem now is that the OnStateChange() method is called by the add-on before setting the variables, and it is therefore "null" if it is to be used in the add-on. I need the instrument name that is loaded by the indicator so that the same instrument is used when loading the add-on from the indicator. The goal is to load the indicator in the chart as usual. This loads the add-on in the background with the same instrument that executes the OnMarketData and sends the values obtained in it back to the indicator.
Announcement
Collapse
No announcement yet.
Partner 728x90
Collapse
NinjaTrader
Use shared value from Indicator in Addon (OnStateChange)
Collapse
X
-
Use shared value from Indicator in Addon (OnStateChange)
Hi, I have the following problem:
I want to save the instrument name from the indicator to a variable and use it when initializing an add-on. The problem now is that the OnStateChange() method is called by the add-on before setting the variables, and it is therefore "null" if it is to be used in the add-on. I need the instrument name that is loaded by the indicator so that the same instrument is used when loading the add-on from the indicator. The goal is to load the indicator in the chart as usual. This loads the add-on in the background with the same instrument that executes the OnMarketData and sends the values obtained in it back to the indicator.
Tags: None
-
Hello sidlercom80,
Small disclaimer, using static classes is not officially supported and not documented, and using these can cause unexpected behavior.
That said, try using State.Active instead. (See "Active States vs Data Processing States" in the help guide)
Are you planning to open a new window in the addon? Below is a link to an example that submits the indicator instance to the addon class, so that static classes do not have to be used.
https://ninjatrader.com/support/foru...548#post774548Chelsea B.NinjaTrader Customer Service
-
Hi _ChelseaB, thank you very much for your reply. Unfortunately, no variable value can be set in Status.Active, not even the print statement is executed. So that doesn't help me ;-)
My idea would be to have an addon that runs the OnMarketData() once for all the indicators that the market data needs. If an indicator needs market data, the instrument name is given to the addon when called and the addon starts in the background with the calculations in OnMarketData and returns these values to the indicator. The addon does not have to be visible in a window, but should perform the calculations in the background.
Comment
-
Hello sidlercom80,
Does the variable have to be static?
Can you make a public variable in the addon, and then assign this from the indicator?
new MyAddon() { MyInstrument = Instrument }
This would be similar to how my example supplies the host instance to the addon.Chelsea B.NinjaTrader Customer Service
Comment
-
Hi _ChelseaB, no it does not have to be a static variable. If I follow your example, it is no problem to solve everything via a Windows (NTWindow). But I don't want an extra window. Only when loading the indicator, additionally load an addon that executes OnMarketData. The addon should receive the instrument from the indicator.
Comment
-
Hello sidlercom80,
Our development has let me know that addonbase classes only have the OnStateChange called at NinjaTrader startup or compile and not when a new instance of a class is made.
In this case, create a public method, and trigger this method from the host script.
public void InstanceStart()
{
Code.Output.Process(MyInstrument.ToString(), PrintTo.Tab1);
}
From the host script:
MyAddon myAddy = new MyAddon() { MyInstrument = Instrument };
myAddy.InstanceStart();Last edited by NinjaTrader_ChelseaB; 09-08-2021, 07:11 AM.Chelsea B.NinjaTrader Customer Service
Comment
-
Hi _ChelseaB, thanks for the tip, I'll try it out
Comment
Latest Posts
Collapse
| Topics | Statistics | Last Post | ||
|---|---|---|---|---|
|
Started by Geovanny Suaza, 02-11-2026, 06:32 PM
|
0 responses
558 views
0 likes
|
Last Post
|
||
|
Started by Geovanny Suaza, 02-11-2026, 05:51 PM
|
0 responses
324 views
1 like
|
Last Post
|
||
|
Started by Mindset, 02-09-2026, 11:44 AM
|
0 responses
101 views
0 likes
|
Last Post
by Mindset
02-09-2026, 11:44 AM
|
||
|
Started by Geovanny Suaza, 02-02-2026, 12:30 PM
|
0 responses
545 views
1 like
|
Last Post
|
||
|
Started by RFrosty, 01-28-2026, 06:49 PM
|
0 responses
547 views
1 like
|
Last Post
by RFrosty
01-28-2026, 06:49 PM
|

Comment