I was a professional programmer for years (decades ago, things have changed) but it appears that every time my hosting indicator instantiates my hosted indicator, all the work has to be repeated. Do I have that right?
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
Does a hosted indicator reload the chart every time the hosting indicator calls it?
Collapse
X
-
Does a hosted indicator reload the chart every time the hosting indicator calls it?
I'm looking for information on the lifecycle of indicators to try to understand the most efficient way for hosted/hosting indicators to work together. Can anyone point me in the right direction?
I was a professional programmer for years (decades ago, things have changed) but it appears that every time my hosting indicator instantiates my hosted indicator, all the work has to be repeated. Do I have that right?Tags: None
-
Hello bsmith,
Calling an indicator won't cause the chart to reload, it would only cause the indicator you are calling to be calculated.
You can see an example of calling an indicator from another indicator by viewing the KelterChannel. As long as your code is similar to that the indicator would be calculated once along with your primary indicator.JesseNinjaTrader Customer Service
-
Thank you Jesse,
If I may post a follow-up question using the KeltnerChannel.cs example:
If my first call to KeltnerChannel is on the update of Bar 200, asking for Midline, it calculates and returns Values[0], which would be the Midline values for the first 200 bars on the chart.
If I then call it again on the update of Bar 205, does it:
a. know that it has already calculated the first 200, and now just calculate values for 201-205?
or
b. recalculate all the values from bar 1-205?
Comment
-
Hello bsmith,
You generally wouldn't call an indicator like that, in most situations you would want to call it on every bar so its calculating with the host. For example on bar 0 the indicator is processed and then the host is processed, then on bar 1-205 it would be the same process. You don't need to use the value until you need it but it would be suggested to call the indicator from OnBarUpdate so it can process each bar and calculate correctly. That won't cause any additional overhead and is a normal part of how calling indicators works in NinjaScript.
JesseNinjaTrader Customer Service
Comment
-
Thank you Jesse,
I've figured out the source of my confusion & why it's not a problem. I'm going to spell it out for any other experienced programmers who may have similar confusion and come across this thread.
In OnBarUpdate, we instantiate an object (in this case, it's an indicator). In normal programming, when you instantiate an object within a code block (like OnBarUpdate), the object completely disappears at the end of the code block, as if the object had never existed. This is why I expected that all data would have to be reloaded, and values recalculated on every execution of the code block. Because that's what happens in "normal" programming.
There is a very special exception here (according to a book I found on writing NinjaScript).
The NinjaTrader engineers have created a feature that keeps indicators "alive" after the first instantiation, even after the code block has closed. This is why the chart does not get reloaded, and the historic indicator values don't need to be recalculated.
Comment
Latest Posts
Collapse
Topics | Statistics | Last Post | ||
---|---|---|---|---|
Started by inanazsocial, Today, 01:15 AM
|
1 response
6 views
0 likes
|
Last Post Today, 02:18 AM | ||
Started by rocketman7, Today, 02:12 AM
|
0 responses
10 views
0 likes
|
Last Post
by rocketman7
Today, 02:12 AM
|
||
Started by dustydbayer, Today, 01:59 AM
|
0 responses
2 views
0 likes
|
Last Post
by dustydbayer
Today, 01:59 AM
|
||
Started by trilliantrader, 04-18-2024, 08:16 AM
|
5 responses
23 views
0 likes
|
Last Post Today, 12:32 AM | ||
Started by Davidtowleii, Today, 12:15 AM
|
0 responses
3 views
0 likes
|
Last Post
by Davidtowleii
Today, 12:15 AM
|
Comment