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

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.


    JesseNinjaTrader Customer Service

    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.
        JesseNinjaTrader Customer Service

        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:	451
Size:	73.4 KB
ID:	1193006Click image for larger version

Name:	Main & new panel.png
Views:	398
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

            JesseNinjaTrader Customer Service

            Comment


              #7
              That works, thanks.

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by alifarahani, Today, 09:40 AM
              6 responses
              31 views
              0 likes
              Last Post alifarahani  
              Started by Waxavi, Today, 02:10 AM
              1 response
              17 views
              0 likes
              Last Post NinjaTrader_LuisH  
              Started by Kaledus, Today, 01:29 PM
              5 responses
              14 views
              0 likes
              Last Post NinjaTrader_Jesse  
              Started by Waxavi, Today, 02:00 AM
              1 response
              12 views
              0 likes
              Last Post NinjaTrader_LuisH  
              Started by gentlebenthebear, Today, 01:30 AM
              3 responses
              17 views
              0 likes
              Last Post NinjaTrader_Jesse  
              Working...
              X