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

Combining indicators?

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

    Combining indicators?

    Hello everyone, I am very new to NinjaTrader. I managed to put together a simple indicator that plots up and down arrows on the chart when the stochastic indicator crosses its top or bottom zones. My trouble is that I want these arrows to plot only if a candle also goes above or below bollinger bands. What would be the best way to go about this? I don’t understand how to combine the ninjascript from two seperate indicators. I started working on this using the stochastic code. From what I can gather, I may be able to call info from another indicator via the ninjascript... but I think it would be best to combine two indicators together since I will eventually make them transparent so that only the arrows actually appear on the chart. Any help would be appreciated, thanks!

    #2
    Hello augustfay,

    Thanks for your post and welcome to the Ninjatrader forums!

    You can call the method (Bollinger) directly in your code if you wish. I would suggest looking at the examples in the help guide here: https://ninjatrader.com/support/help...nger_bands.htm

    As you can see, you can call the Bollinger directly with Bollinger(2, 20).Upper[0]; the 2 & 20 relate to the inputs of the Bollinger which are the number of standard deviations and the period. The Bollinger indicator offers three plots and in the example, it is using the Upper plot and the index of [0] is the current value of the upper band. You can also access the Middle band and the Lower band, like this: Bollinger(2.20).Middle[0] Bollinger(2,20).Lower[0].

    You can also do the same thing with the Stochastics as well, here is the help guide link: https://ninjatrader.com/support/help...tochastics.htm please check the examples show.

    Here would be a general idea of putting them together:

    if (Stochastics(3, 14, 7).K[0] > 70 && Close[0] > Bollinger(2, 20).Upper[0]) If the K line is greater than 70 and the close price is greater than the Bollinger upper band.
    {
    // do something
    }

    Paul H.NinjaTrader Customer Service

    Comment


      #3
      Hello augustfay,

      Thanks for your reply.

      Taking my example and yours then:

      if (CrossAbove(Stochastics(3, 6, 3).K, Stochastics(3, 6, 3).D, 1) && Close[0] > Bollinger(2, 20).Upper[0]))

      I was showing the close price of the bar, you may want to use High[0].

      Regarding errors, something to keep in mind is that when you compile, you are actually compiling all scripts (strategies, indicators, etc), so an error in any file would prevent it from compiling and the error messages displayed below the file you are working on may not be from the file you are working on. Always check the left column of the error messages as that identifies the source file that the error messages relate to. Reference: https://ninjatrader.com/support/help...ile_errors.htm
      Paul H.NinjaTrader Customer Service

      Comment


        #4
        Thank you Paul, I realized I was overcomplicating it, I thought I had to put the Bollinger(2, 20).Upper[0]; elsewhere in the Ninjascript instead of simply dropping it as part of the condition. Really simple.

        My trouble now is that I am getting an arrow plotting on every single candle. Any idea why?


        if (Stochastics(7, 14, 3).K[0] > 80 && Close[0] > Bollinger(2,20).Upper[0]);

        {

        Draw.ArrowUp(this, "upArrow" + CurrentBar, true, 0, Low[0] - 2 * TickSize, Brushes.Green);

        }

        Comment


          #5
          Hello augustfay,

          Thanks for your reply.

          Ninjascript are methods and properties that are written in C# programming language so the C# syntax rules apply to your Ninjascriopt code.

          When you write an if statement that has one or more actions you use the {} to bracket all of the actions to perform. The if statement has a semicolon at the end which terminates the if statement so the condition below the if statement would be executed on every OnBarUpdate(). Just remove the semi colon from .Upper[0]); and you should be good!
          Paul H.NinjaTrader Customer Service

          Comment


            #6
            Wow thank you for such a detailed and informative response. It's getting there now, I've been tweaking it and trying to calibrate it, adding in crossovers and whatnot for the k and d, etc. Probably going to take a while to get right. There's one more thing I'm unsure on how to do. Is there a simple way to specify that I only want the arrow to plot on a bullish, or bearish candle? Or perhaps say, a bull candle that closed with a body less than 30% of its overall height or something... some sort of additional conditions involving candles. Thank you!

            Comment


              #7
              Okay I figured out that to create an up bar it is: (Open[0] > Close[0]) I'm still unsure of how to create something that specifies, up bars and down bars of a certain percentage.

              I'm now also trying to add a horizontal line extending to the right, to the top or bottom of the candle, but nothing is plotting here when I use this code. I must be confused about the numerical values.

              { Draw.HorizontalLine(this,"tag1" + CurrentBar, Brushes.Gray, DashStyleHelper.Dot, 2);


              }
              Last edited by augustfay; 07-17-2020, 06:29 AM.

              Comment


                #8
                Hello augustfay,

                Thanks for your replies.

                As you have observed, Close>Open = Green bar, Close< Open = Red bar.

                Regarding, "...a bull candle that closed with a body less than 30% of its overall height or something". The "body" of a candle is defined by the Close to Open value. You can compare the absolute value of the Close[0]-Open[0] to the Range()[0] of the bar (The range of the bar is the same as the High - Low). Reference: https://ninjatrader.com/support/help...nt8/?range.htm

                Anytime a script is not functioning as expected, a good place to check is the "Log" tab of the control center. When an indicator does not appear on the chart that it has been applied to it likely has a run time error which would be noted in the log.

                The Draw.Horizontal line statement you show does not provide a "y" value. The Y value is the "price" that you want to draw the line at.
                For example:
                Draw.HorizontalLine(this,"tag1" + CurrentBar, true, Low[0], Brushes.Gray, DashStyleHelper.Dot, 2)
                Reference: https://ninjatrader.com/support/help...zontalline.htm
                Paul H.NinjaTrader Customer Service

                Comment


                  #9
                  Appreciate all the help Paul!

                  Comment

                  Latest Posts

                  Collapse

                  Topics Statistics Last Post
                  Started by morrnel, Today, 06:07 PM
                  1 response
                  8 views
                  0 likes
                  Last Post NinjaTrader_Manfred  
                  Started by thumper57, Yesterday, 04:30 PM
                  6 responses
                  20 views
                  0 likes
                  Last Post NinjaTrader_BrandonH  
                  Started by sastrades, 05-10-2024, 09:59 AM
                  3 responses
                  54 views
                  0 likes
                  Last Post rc5781
                  by rc5781
                   
                  Started by guyonabuffalo, Yesterday, 10:01 PM
                  2 responses
                  22 views
                  0 likes
                  Last Post guyonabuffalo  
                  Started by reynoldsn, 05-10-2024, 07:04 PM
                  5 responses
                  27 views
                  0 likes
                  Last Post NinjaTrader_BrandonH  
                  Working...
                  X