Announcement
Collapse
No announcement yet.
Partner 728x90
Collapse
NinjaTrader
Most effective way to call indicator?
Collapse
X
-
Most effective way to call indicator?
I need to read the value of an indicator on every single bar update. What is the most effective way to do this? Right now, I have a line such as: "double dVal = IndicatorName(x,y,z).Series[0]" in OnBarUpdate(). Is there a way to initialize the indicator once, and then use its value? If so, how?Tags: None
-
Hello trader2be,
This approach should be fine. The biggest impact on resources could be seen if you were running the strategy with CalculateOnBarClose = false and only needed the indicator calculation once per bar. This sample can help combine both logic so you're not unnecessarily calculating the indicator every tick.
Ryan M.NinjaTrader Customer Service
-
It's possible to add the indicator to the strategies Initialize() method. Please see here for help with this. The main reason to do this is to do this is to see the indicators on the chart.
You can also declare the indicator as a variable and there is a potential for small performance increase with this practice. Most users wouldn't see a difference here, but it relates to how many total instances of indicators you're running. If you use a named variable for your indicator, it does not have to iterate through all the cached indicators and this can lead to improved efficiency.
You can also conditionally call your indicator, but if you need a value once per bar this doesn't offer any advantages.Last edited by NinjaTrader_RyanM1; 01-04-2011, 05:39 PM.Ryan M.NinjaTrader Customer Service
Comment
-
Ok, thanks again. My goal is really performance improvement in calling indicator values, so if you tell me that my original implementation in OnBarUpdate() is optimal, I will just stick with that.
I don't know if it's available but I would be very interested in any tips/tricks to improve NinjaScript performance. I am not a seasoned C# programmer and therefore I would appreciate guidance. Has anyone written anything on this for NT?
Comment
-
An update to this thread - My previous response was incorrect and is corrected above.Ryan M.NinjaTrader Customer Service
Comment
-
Could you show me an example of how to declare the indicator as a variable?Originally posted by NinjaTrader_RyanM View PostIt's possible to add the indicator to the strategies Initialize() method. Please see here for help with this. The main reason to do this is to do this is to see the indicators on the chart.
You can also declare the indicator as a variable and there is a potential for small performance increase with this practice. Most users wouldn't see a difference here, but it relates to how many total instances of indicators you're running. If you use a named variable for your indicator, it does not have to iterate through all the cached indicators and this can lead to improved efficiency.
You can also conditionally call your indicator, but if you need a value once per bar this doesn't offer any advantages.
Comment
Latest Posts
Collapse
| Topics | Statistics | Last Post | ||
|---|---|---|---|---|
|
Started by Geovanny Suaza, 02-11-2026, 06:32 PM
|
0 responses
649 views
0 likes
|
Last Post
|
||
|
Started by Geovanny Suaza, 02-11-2026, 05:51 PM
|
0 responses
370 views
1 like
|
Last Post
|
||
|
Started by Mindset, 02-09-2026, 11:44 AM
|
0 responses
109 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
573 views
1 like
|
Last Post
|
||
|
Started by RFrosty, 01-28-2026, 06:49 PM
|
0 responses
576 views
1 like
|
Last Post
by RFrosty
01-28-2026, 06:49 PM
|

Comment