Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Add a colour fill in the area above/below the indicator line

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

    Add a colour fill in the area above/below the indicator line

    Hello,

    I am developing an oscillating indicator (similar to RSI) and I want to add a fill colour as below:
    • When indicator is above zero, the area below the indicator and above the zero line will be filled with a green colour
    • When indicator is below zero, the area above the indicator and below the zero line will be filled with a red colour

    Can you please point me in the right direction on how I would achieve this.

    Thanks,

    Neil

    #2
    Hello burtoninlondon,

    That sounds like the Region tool would be a good match for what you described, that colors areas between series.


    The region tool has a parameter set that allows for a Plot and a value so you could for example color between 0 and a plot value.


    Comment


      #3
      NinjaTrader_Jesse , thanks for your response but I'm struggling with understanding the syntax of the DrawRegion() function, can I ask for further help?

      First thing is, where do I place this command? Should I position it in OnStateChange() \ State.SetDefaults? This is where I have my AddPlot for my oscillator.

      Do you have a sample line of code using a data series which I can take a look at? The example in the help guide doesn't refer to a data series.

      I've added my code below...
      AddLine(Brushes.White, 0, "ZLINE");
      AddPlot(Brushes.Orange, "series1");
      Draw.Region(this, "series1", CurrentBar, 0, RRSseries, 0, Brushes.Blue, 50);

      Thanks for your help.

      Neil

      Comment


        #4
        Hello burtoninlondon,

        The Region tool is a drawing tool so that needs to be used from OnBarUpdate.

        When you call a region tool you need to supply the BarsAgo and the series so it knows where to color. You can find an example of coloring between two plots here: https://ninjatraderecosystem.com/use...el-with-color/



        The NinjaTrader Ecosystem website is for educational and informational purposes only and should not be considered a solicitation to buy or sell a futures contract or make any other type of investment decision. The add-ons listed on this website are not to be considered a recommendation and it is the reader's responsibility to evaluate any product, service, or company. NinjaTrader Ecosystem LLC is not responsible for the accuracy or content of any product, service or company linked to on this website.

        Comment


          #5
          NinjaTrader_Jesse, thanks for your continued help.

          I'm still struggling with this...I have stripped back the example you linked so that I could try to understand how it works. In my example I'm trying to fill the zone between a line at 1 and a line at 10. When I add the indicator to the main panel (where the price action is displayed), the region draws as I'd like it to. If I move the indicator to a new panel (where ultimately my indicator will be) separate from the price action main panel the lines for 1 & 10 are drawn in the new panel but the region is drawn in the main panel.

          Click image for larger version

Name:	Main panel.png
Views:	770
Size:	73.4 KB
ID:	1193006Click image for larger version

Name:	Main & new panel.png
Views:	682
Size:	83.1 KB
ID:	1193007

          My code is as below...

          Code:
          protected override void OnStateChange()
          {
          if (State == State.SetDefaults)
          {
          Description = NinjaTrader.Custom.Resource.NinjaScriptIndicatorDe scriptionKeltnerChannel;
          Name = "FillTest";
          IsOverlay = true;
          IsSuspendedWhileInactive = true;
          
          AddPlot(Brushes.DodgerBlue, NinjaTrader.Custom.Resource.NinjaScriptIndicatorUpper);
          AddPlot(Brushes.DodgerBlue, NinjaTrader.Custom.Resource.NinjaScriptIndicatorLower);
          }
          else if (State == State.DataLoaded)
          {
          }
          }
          
          protected override void OnBarUpdate()
          {
          double upper = 58;
          double lower = 54;
          
          Upper[0] = upper;
          Lower[0] = lower;
          
          Draw.Region(this, "FillTest", CurrentBar, 0, Upper, Lower, null, Brushes.RoyalBlue, 40, 0);
          }
          
          #region Properties
          [Browsable(false)]
          [XmlIgnore()]
          public Series<double> Lower
          {
          get { return Values[1]; }
          }
          
          [Browsable(false)]
          [XmlIgnore()]
          public Series<double> Upper
          {
          get { return Values[0]; }
          }
          #endregion
          }
          Any help is appreciated on how I can draw the region in the new panel.

          Thanks,

          Neil

          Comment


            #6
            Hello burtoninlondon,

            Because this is a drawing tool if you want it to draw in the indicator panel you also need to turn off DrawOnPricePanel: https://ninjatrader.com/support/help...sub=pricepanel

            Comment


              #7
              That works, thanks.

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by Geovanny Suaza, 02-11-2026, 06:32 PM
              0 responses
              579 views
              0 likes
              Last Post Geovanny Suaza  
              Started by Geovanny Suaza, 02-11-2026, 05:51 PM
              0 responses
              334 views
              1 like
              Last Post Geovanny Suaza  
              Started by Mindset, 02-09-2026, 11:44 AM
              0 responses
              101 views
              0 likes
              Last Post Mindset
              by Mindset
               
              Started by Geovanny Suaza, 02-02-2026, 12:30 PM
              0 responses
              554 views
              1 like
              Last Post Geovanny Suaza  
              Started by RFrosty, 01-28-2026, 06:49 PM
              0 responses
              551 views
              1 like
              Last Post RFrosty
              by RFrosty
               
              Working...
              X