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
Using existing indicator value in custom indicator
Collapse
X
-
Zachary G.,
Thanks for your help, it worked like a charm!!!!
Surprisingly, I figured out how to use the standard deviation and period as a user defined variable.
Thanks again, it turned out exactly as expected.
-
Hello ActiveTrader09,
Please take a look at the following overloads for MAX() and MIN():
Code:MAX(IDataSeries input, int period); MIN(IDataSeries input, int period);
You will need to replace your code within OnBarUpdate() with:
Code:Value.Set((MAX(Bollinger(2, 20).Upper, Period)[0] + MIN(Bollinger(2, 20).Lower, Period)[0]) / 2); Upper.Set(MAX(Bollinger(2, 20).Upper, Period)[0]); Lower.Set(MIN(Bollinger(2, 20).Lower, Period)[0]);
Please, let us know if we may be of further assistance.
Leave a comment:
-
I replaced the code with the following and still get errors on compile. Like I said I am a complete newbie when it comes to coding anything. I attached the .cs file for reference. Thanks.
Code:public class DonchianBands : Indicator { #region Variables private int period = 20; #endregion /// <summary> /// This method is used to configure the indicator and is called once before any bar data is loaded. /// </summary> protected override void Initialize() { Add(new Plot(Color.Orange, "Mean")); Add(new Plot(Color.Blue, "Upper")); Add(new Plot(Color.Blue, "Lower")); Overlay = true; } /// <summary> /// Called on each bar update event (incoming tick) /// </summary> protected override void OnBarUpdate() { Value.Set((MAX(Bollinger(2, 20).Upper[0], Period)[0] + MIN(Bollinger(2, 20).Lower[0], Period)[0]) / 2); Upper.Set(MAX(Bollinger(2, 20).Upper[0], Period)[0]); Lower.Set(MIN(Bollinger(2, 20).Lower[0], Period)[0]); }
Originally posted by NinjaTrader_ChelseaB View PostHello ActiveTrader09,
The Bollinger() indicator cannot be called outside of a method.
The line:
double upperValue = Bollinger(2, 20).Upper[0];
will not compile.
Try the following instead:
Value.Set((MAX(Bollinger(2, 20).Upper[0], Period)[0] + MIN(Bollinger(2, 20).Lower[0], Period)[0]) / 2);
Or you can continue using the variables, but set these in OnBarUpdate on each bar before they are used.Attached Files
Leave a comment:
-
Hello ActiveTrader09,
The Bollinger() indicator cannot be called outside of a method.
The line:
double upperValue = Bollinger(2, 20).Upper[0];
will not compile.
Try the following instead:
Value.Set((MAX(Bollinger(2, 20).Upper[0], Period)[0] + MIN(Bollinger(2, 20).Lower[0], Period)[0]) / 2);
Or you can continue using the variables, but set these in OnBarUpdate on each bar before they are used.
Leave a comment:
-
Using existing indicator value in custom indicator
I am trying modify the existing Donchian Channel indicator so it uses the upper and lower Bollinger Band for the upper and lower channels. Right now I am using an indicator of an indicator for the upper and lower channels. I want one indicator to do what depicted in the attached chart. Thanks.
I have no scripting knowledge. I cut and pasted the following from other coding examples.
Code:public class DonchianBands : Indicator { #region Variables private int period = 20; double upperValue = Bollinger(2, 20).Upper[0]; double lowerValue = Bollinger(2, 20).Lower[0]; #endregion /// <summary> /// This method is used to configure the indicator and is called once before any bar data is loaded. /// </summary> protected override void Initialize() { Add(new Plot(Color.Orange, "Mean")); Add(new Plot(Color.Blue, "Upper")); Add(new Plot(Color.Blue, "Lower")); Overlay = true; } /// <summary> /// Called on each bar update event (incoming tick) /// </summary> protected override void OnBarUpdate() { Value.Set((MAX(upperValue, Period)[0] + MIN(lowerValue, Period)[0]) / 2); Upper.Set(MAX(upperValue, Period)[0]); Lower.Set(MIN(lowerValue, Period)[0]); }
Tags: None
Latest Posts
Collapse
Topics | Statistics | Last Post | ||
---|---|---|---|---|
Started by WHICKED, Today, 12:45 PM
|
2 responses
16 views
0 likes
|
Last Post
by WHICKED
Today, 03:36 PM
|
||
Started by GussJ, 03-04-2020, 03:11 PM
|
15 responses
3,272 views
0 likes
|
Last Post Today, 03:15 PM | ||
Started by Tim-c, Today, 02:10 PM
|
1 response
8 views
0 likes
|
Last Post Today, 02:52 PM | ||
Started by Taddypole, Today, 02:47 PM
|
0 responses
2 views
0 likes
|
Last Post
by Taddypole
Today, 02:47 PM
|
||
Started by chbruno, 04-24-2024, 04:10 PM
|
4 responses
51 views
0 likes
|
Last Post
by chbruno
Today, 02:38 PM
|
Leave a comment: