Thanks
Announcement
Collapse
No announcement yet.
Partner 728x90
Collapse
NinjaTrader
Best Practices When Using Indicator Values
Collapse
X
-
Best Practices When Using Indicator Values
I'm developing a strategy that uses values from a custom indicator for entries/exits etc. I notice that in most of the samples, outside the strategy indicators are referenced inline each time a value is needed. That is, if we are using the value of an EMA at various points within our code you will see EMA(xxx)[x] in every spot it is needed. Is this the preferred technique? The reason I ask is that I went down the road of making an internal data series within the strategy, setting it equal to the external indicator once, and then using it internally for all calculations. Is this any more efficient or am I just adding extra code for no reason?
ThanksTags: None
-
Hello RandomTask,
Thanks for your post!
The best practice would be to create an instance of an indicator and assign that instance of that indicator to an indicator call with the parameters you need in State.DataLoaded or State.Historical. The instance of the indicator can then be accesses for historical values just like you can with another Series<double> object.
This best practice and others can be publicly referenced here: https://ninjatrader.com/support/help...tm#PerformanceCode:private SMA mySma; protected override void OnStateChange() { // when the indicator begins processing // save an instance of the SMA indicator with the desired input if (State == State.Historical) { mySma = SMA(20); } } protected override void OnBarUpdate() { // use the referenced mySMA throughout the lifetime of the script if (Close[0] > mySma[0]) { Print(mySma[0]); EnterLongLimit(mySma[0]); Draw.Dot(this, Time[0].ToString(), false, 0, mySma[0], Brushes.DarkGreen); } }
Please let us know if we can be of further assistance.
-
-
It seems that when I try this with a custom indicator I get the following error in the compiler:
private MyCustomIndicator myInd;
'NinjaTrader.NinjaScript.Strategies.Strategy.MyCus tomIndicator(double, double, int)' is a 'method' but is used like a 'type'
Comment
-
That one works just fine.
It ended up being a namespace issue. My custom indicators are in a custom namespace and so in order for the variable declaration to work I needed to do this:
private NinjaTrader.NinjaScript.Indicators.MyCustomNamespa ce.MyCustomIndicator myInd;
Thank you.
Comment
Latest Posts
Collapse
| Topics | Statistics | Last Post | ||
|---|---|---|---|---|
|
Started by NullPointStrategies, Yesterday, 05:17 AM
|
0 responses
71 views
0 likes
|
Last Post
|
||
|
Started by argusthome, 03-08-2026, 10:06 AM
|
0 responses
143 views
0 likes
|
Last Post
by argusthome
03-08-2026, 10:06 AM
|
||
|
Started by NabilKhattabi, 03-06-2026, 11:18 AM
|
0 responses
76 views
0 likes
|
Last Post
|
||
|
Started by Deep42, 03-06-2026, 12:28 AM
|
0 responses
47 views
0 likes
|
Last Post
by Deep42
03-06-2026, 12:28 AM
|
||
|
Started by TheRealMorford, 03-05-2026, 06:15 PM
|
0 responses
51 views
0 likes
|
Last Post
|

Comment