Thanks
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
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.
Code: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.JimNinjaTrader Customer Service
-
-
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 Brevo, Today, 01:45 AM
|
0 responses
6 views
0 likes
|
Last Post
by Brevo
Today, 01:45 AM
|
||
Started by aussugardefender, Today, 01:07 AM
|
0 responses
3 views
0 likes
|
Last Post Today, 01:07 AM | ||
Started by pvincent, 06-23-2022, 12:53 PM
|
14 responses
242 views
0 likes
|
Last Post
by Nyman
Today, 12:47 AM
|
||
Started by TraderG23, 12-08-2023, 07:56 AM
|
9 responses
384 views
1 like
|
Last Post
by Gavini
Today, 12:29 AM
|
||
Started by oviejo, Today, 12:28 AM
|
0 responses
6 views
0 likes
|
Last Post
by oviejo
Today, 12:28 AM
|
Comment