Announcement
Collapse
No announcement yet.
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():
You are attempting pass a double value into the parameter that accepts an IDataSeries object.Code:MAX(IDataSeries input, int period); MIN(IDataSeries input, int period);
You will need to replace your code within OnBarUpdate() with:
Please take a look at the following link on how methods function within C#: http://www.tutorialspoint.com/csharp/csharp_methods.htmCode: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 CarlTrading, 03-31-2026, 09:41 PM
|
1 response
131 views
1 like
|
Last Post
|
||
|
Started by CarlTrading, 04-01-2026, 02:41 AM
|
0 responses
74 views
1 like
|
Last Post
by CarlTrading
04-01-2026, 02:41 AM
|
||
|
Started by CaptainJack, 03-31-2026, 11:44 PM
|
0 responses
117 views
2 likes
|
Last Post
by CaptainJack
03-31-2026, 11:44 PM
|
||
|
Started by CarlTrading, 03-30-2026, 11:51 AM
|
0 responses
111 views
1 like
|
Last Post
by CarlTrading
03-30-2026, 11:51 AM
|
||
|
Started by CarlTrading, 03-30-2026, 11:48 AM
|
0 responses
89 views
0 likes
|
Last Post
by CarlTrading
03-30-2026, 11:48 AM
|

Leave a comment: