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
Create a WMA of a custom slope indicator
Collapse
X
-
Create a WMA of a custom slope indicator
I created an indicator that calculates / plots the slope of the HMA called HMAslope. I would like to calculate and plot the WMA of the HMAslope. Do I need to define the HMAslope as a series before I can use it in the WMA function? I have attached my code for the HMAslope custom indicator.
Tags: None
-
Hello herbnderby, thanks for writing in.
You are assigning the Slope value to the Value array which is already a Series<double> object, so you can use that series in the WMA e.g.
Value[0] = Slope(HMA(Period), StartBarsAgo, EndBarsAgo);
double myValue = WMA(Value, 20)[0];
Kind regards,
-ChrisLChris L.NinjaTrader Customer Service
-
-
Hi herbnderby, thanks for your reply.
You will need to call AddPlot() one more time, then access the second plot, e.g.
Value[0][0] = Slope(HMA(Period), StartBarsAgo, EndBarsAgo); //first plot
Values[1][0] = WMA(Value, Period)[0]; //second plot
Best regards,
-ChrisLChris L.NinjaTrader Customer Service
Comment
-
Okay, I modified my code as shown above but I received the error message "Cannot apply indexing with [] to an expression of type "double".
So I modified the code to this:
Values[0][0] = Slope(HMA(PeriodHMA), 1, 0); //first plot
Values[1][0] = WMA(Values[0], PeriodWMA)[0]; //second plot
I don't get any errors after compiling but the indicator still doesn't plot anything.
Comment
-
Hi herbnderby,
I added a CurrentBar check at the top to ensure there are enough bars to process and all the plots show up:
Code:protected override void OnBarUpdate() { if(CurrentBar < 20) return; Values[0][0] = Slope(HMA(20), 1, 0); //first plot Values[1][0] = WMA(Values[0], 20)[0]; //second plot }
-ChrisLChris L.NinjaTrader Customer Service
Comment
-
Latest Posts
Collapse
Topics | Statistics | Last Post | ||
---|---|---|---|---|
Started by WHICKED, 03-27-2024, 12:33 PM
|
4 responses
41 views
0 likes
|
Last Post Today, 12:28 AM | ||
Started by f.saeidi, Today, 12:12 AM
|
0 responses
3 views
0 likes
|
Last Post
by f.saeidi
Today, 12:12 AM
|
||
Started by Conall, Today, 12:06 AM
|
0 responses
5 views
0 likes
|
Last Post
by Conall
Today, 12:06 AM
|
||
Started by proptradingshop, 03-21-2024, 09:50 AM
|
6 responses
27 views
0 likes
|
Last Post Today, 12:02 AM | ||
Started by mly916, Yesterday, 09:48 PM
|
1 response
12 views
0 likes
|
Last Post Yesterday, 11:54 PM |
Comment