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!
See more
See less

Partner 728x90

Collapse

Using existing indicator value in custom indicator

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • ActiveTrader09
    replied
    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.

    Leave a comment:


  • NinjaTrader_ZacharyG
    replied
    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 are attempting pass a double value into the parameter that accepts an IDataSeries object.

    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 take a look at the following link on how methods function within C#: http://www.tutorialspoint.com/csharp/csharp_methods.htm

    Please, let us know if we may be of further assistance.

    Leave a comment:


  • ActiveTrader09
    replied
    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 Post
    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.
    Attached Files

    Leave a comment:


  • NinjaTrader_ChelseaB
    replied
    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]);
            }
    Click image for larger version

Name:	example.jpg
Views:	1
Size:	278.3 KB
ID:	904654

Latest Posts

Collapse

Topics Statistics Last Post
Started by WHICKED, Today, 12:45 PM
2 responses
16 views
0 likes
Last Post WHICKED
by WHICKED
 
Started by GussJ, 03-04-2020, 03:11 PM
15 responses
3,272 views
0 likes
Last Post xiinteractive  
Started by Tim-c, Today, 02:10 PM
1 response
8 views
0 likes
Last Post NinjaTrader_ChelseaB  
Started by Taddypole, Today, 02:47 PM
0 responses
2 views
0 likes
Last Post Taddypole  
Started by chbruno, 04-24-2024, 04:10 PM
4 responses
51 views
0 likes
Last Post chbruno
by chbruno
 
Working...
X