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
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
-
Here is a good thread on optimizing NinjaScript.
If you want a dataseries to capture the SMA of the MACD: (Note... MACD12 should have been MyNewMACD) in Variables: private DataSeries myMacdAvg; private bool init = false; private MACD MyNewMACD private SMA SMAofMACD in Initialize(): myMacdAvg = new DataSeries(this); in OnBarUpdate(); if(!init) { MyNewMACD= MACD(12,26,9); SMAofMACD=SMA(MyNewMACD, 7); // 7 period SMA of MACD(12,26,9) init = true; } MyMacdAvg.Set(SMAofMACD[0]); if(MyMacdAvg[0] > 0) // if current value of 7 period SMA of MACD(12,26,9)>0 ( Print("Hello …
Dan
Comment
-
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 samish18, Today, 10:13 AM
|
0 responses
2 views
0 likes
|
Last Post
by samish18
Today, 10:13 AM
|
||
Started by kenz987, Yesterday, 10:20 AM
|
2 responses
12 views
0 likes
|
Last Post
by kenz987
Today, 10:13 AM
|
||
Started by nicthe, 08-23-2023, 07:53 AM
|
7 responses
196 views
0 likes
|
Last Post
by nicthe
Today, 09:26 AM
|
||
Started by nicthe, Today, 09:24 AM
|
0 responses
5 views
0 likes
|
Last Post
by nicthe
Today, 09:24 AM
|
||
Started by stalt, 12-28-2015, 01:36 PM
|
6 responses
1,536 views
0 likes
|
Last Post
by giulyko00
Today, 09:16 AM
|
Comment