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

Adding a highlighted region to an indicator in the lower indicator panel

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

    Adding a highlighted region to an indicator in the lower indicator panel

    Hello,
    Thank you in advance for any help on this.

    I'm wanting to add a highlighted Y-horizontal) region to the RSI indicator (ninja script) from 45 up to 55.
    I've tried a few different ways by looking at another indicator but I have had no luck in getting the region to plot.

    If anyone can help with it would be greatly appreciated.
    Click image for larger version

Name:	Screenshot_1.png
Views:	236
Size:	11.5 KB
ID:	1260397

    #2
    Hello laoshr,

    You could do this by making a copy of the indicator and adding a region to its code. the region highlight y would be the easiest way to do that for this indicator.


    https://ninjatrader.com/support/help...ub=region+high light

    Draw.RegionHighlightY(this, "tag1", 45, 55, Brushes.Yellow);

    JesseNinjaTrader Customer Service

    Comment


      #3
      Thank you Jesse for your quick response.
      I tried to add the DrawRegion (see below) but it doesn't plot.

      if (State == State.SetDefaults)
      {
      Name = "TOTrmi";
      Description = "TOTrmi";
      AddPlot(Brushes.Blue, "TOTrimi");



      AddLine(Brushes.Red, 70, "Upper");

      AddLine(Brushes.Black, 50, "Center");

      AddLine(Brushes.Green, 30, "Lower");

      Draw.RegionHighlightY(this, "tag1", 45, 55, Brushes.Yellow);​

      Comment


        #4
        Hello laoshr,

        SetDefaults is only for setting default values, you can't place any bar related code in there. You need to move that to OnBarUpdate.
        JesseNinjaTrader Customer Service

        Comment


          #5
          Thanks, Jesse,
          I have been working to understand the ninja script. I do my best copying and pasting. LOL
          At best I'm a complete novice. Can you possibly show me an example of how it would be added to the OnBarUpdate?
          Thanks again for your time.
          James

          Comment


            #6
            Hello laoshr,

            Because this is just being drawn between two numbers you typed in you can just place this as the first line of OnBarUpdate:

            protected override void OnBarUpdate()
            {
            Draw.RegionHighlightY(this, "tag1", 45, 55, Brushes.Yellow);​
            JesseNinjaTrader Customer Service

            Comment


              #7
              Thanks for the example Jesse,
              I did try putting on the first line and it will not plot. I don't get any errors though.

              protected override void OnBarUpdate()
              {
              Draw.RegionHighlightY(this, "tag1", 45, 55, Brushes.Yellow);​


              double amountUp = 0;
              double amountDown = 0;
              double rmi = 0;

              if (CurrentBar ==0)
              {
              avgUp[0] = 0;
              avgDown[0] = 0;

              return;​

              Comment


                #8
                Hello laoshr,

                You would need DrawOnPricePanel = false for this if you use this in any indicator in a sub panel. Also please make sure you Compile by pressing F5 after editing the code and then re applying the indicator to the chart. The DrawOnPricePanel goes in State.SetDefaults like shown in the following help guide article.

                JesseNinjaTrader Customer Service

                Comment


                  #9
                  Jesse,
                  I do have DrawOnPricePanel = false under if (State == State.SetDefaults).
                  I'm not sure what's next.
                  Thanks for your time.
                  James

                  Comment


                    #10
                    Hello laoshr,

                    Is the indicator value between 45 and 55? The object does not have autoscale on so it would only be displayed if the indicators scale is showing the prices between 45 and 55. I see that code working on my end when using a scale that includes 45-55. Also make sure you are re applying the indicator and not pressing F5 to reload it, if you made changes to State.SetDefaults you won't see those changes without re applying the indicator.

                    JesseNinjaTrader Customer Service

                    Comment


                      #11
                      This is what it looks like. I've reloaded the indicator and double-checked but I'm sure I'm missing something simple.

                      protected override void OnStateChange()
                      {
                      if (State == State.SetDefaults)
                      {


                      Name = "TOTrmi";
                      Description = "TOTrmi";
                      AddPlot(Brushes.Blue, "TOTrimi");

                      DrawOnPricePanel = false; // Draw objects now paint on the indicator panel itself

                      AddLine(Brushes.Red, 90, "xUpper");
                      AddLine(Brushes.Red, 80, "Upper");
                      AddLine(Brushes.Black, 70, "RSC High");
                      AddLine(Brushes.Black, 50, "Center");
                      AddLine(Brushes.Black, 30, "RSC Low");
                      AddLine(Brushes.Green, 20, "Lower");
                      AddLine(Brushes.Green, 10, "xLower");

                      }
                      else if (State == State.DataLoaded)
                      {
                      avgUp = new Series<double>(this);
                      avgDown = new Series<double>(this);
                      }
                      }

                      protected override void OnBarUpdate()

                      {​​

                      Draw.RegionHighlightY(this, "tag1", 45, 55, Brushes.Yellow);​

                      double amountUp = 0;
                      double amountDown = 0;
                      double rmi = 0;

                      if (CurrentBar ==0)
                      {
                      avgUp[0] = 0;
                      avgDown[0] = 0;

                      return;

                      }

                      if (CurrentBar < (Period + shift))
                      {
                      return;
                      }
                      else if (CurrentBar == (Period + shift))
                      {
                      double sumUp = 0;
                      double sumDown = 0;

                      for (int barsAgo = 0; barsAgo < Period; barsAgo++)
                      {
                      amountUp = Input[barsAgo] - Input[barsAgo + shift];
                      if (amountUp >= 0)
                      {
                      amountDown = 0;
                      }
                      else
                      {
                      amountDown = -amountUp;
                      amountUp = 0;
                      }
                      sumUp = sumUp + amountUp;
                      sumDown = sumDown + amountDown;
                      }
                      avgUp[0] = sumUp / Period;
                      avgDown[0] = sumDown / Period;
                      }
                      else
                      {
                      amountUp = Input[0] - Input[shift];
                      if (amountUp >= 0)
                      {
                      amountDown = 0;
                      }
                      else
                      {
                      amountDown = -amountUp;
                      amountUp = 0;
                      }
                      avgUp[0] = (avgUp[1] * (Period - 1) + amountUp) / Period;
                      avgDown[0] = (avgDown[1] * (Period - 1) + amountDown) / Period;
                      }

                      if ((avgUp[0] + avgDown[0]) != 0)
                      {
                      rmi = 100 * avgUp[0] / (avgUp[0] + avgDown[0]);
                      }
                      else rmi = 0;


                      Value[0] = rmi;




                      }​

                      Comment


                        #12
                        Hello laoshr,

                        if you right click the chart and go to drawing tools -> click Drawing objects do you see the drawing object in the window?
                        JesseNinjaTrader Customer Service

                        Comment


                          #13
                          Jesse,
                          Yes, there is a drawing object in the window.

                          Comment


                            #14
                            Hello laoshr,

                            If there is an object being drawn but you cant see it that indicates the scale is not within that range. If you have the same settings as I had shown you should see a yellow region between 45 and 55 if you scale those prices in the panel. If the indicator is not producing values within the range of 45 and 55 you won't see the object, it will be beyond the scale.
                            JesseNinjaTrader Customer Service

                            Comment


                              #15
                              Jesse,
                              The values when I look at the drawing object properties have 55/45.

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by LiamTwine, Today, 08:10 AM
                              0 responses
                              2 views
                              0 likes
                              Last Post LiamTwine  
                              Started by Balage0922, Today, 07:38 AM
                              0 responses
                              5 views
                              0 likes
                              Last Post Balage0922  
                              Started by JoMoon2024, Today, 06:56 AM
                              0 responses
                              6 views
                              0 likes
                              Last Post JoMoon2024  
                              Started by Haiasi, 04-25-2024, 06:53 PM
                              2 responses
                              19 views
                              0 likes
                              Last Post Massinisa  
                              Started by Creamers, Today, 05:32 AM
                              0 responses
                              6 views
                              0 likes
                              Last Post Creamers  
                              Working...
                              X