Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

How to fill two plots with a color

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

    How to fill two plots with a color

    I'm creating an indicator and adding two SMA
    AddPlot(Brushes.Red, "test1");
    AddPlot(Brushes.Green, "test2");

    Is there any way to fill these space and chose a color for it?

    Let's say I have two lines like
    -------------------------------------------
    (I want to fill this with a color)
    -------------------------------------------

    #2
    Hello cmtjoancolmenero,

    Yes, this is possible with Draw.Region().

    Below is a link to the help guide.


    For example:
    Draw.Region(this, "myRegion", CurrentBar, 0, Values[0],Values[1], null, Brushes.Blue, 100);
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Hello ChelseaB,

      Thanks this works, but the thing is I'd need to save the rest of the colors drawn, for instance I have a check for instance
      if(condition)
      {
      PlotBrushes[0][0] = Brushes.Yellow;
      PlotBrushes[1][0] = Brushes.Yellow;​
      }
      else
      {
      PlotBrushes[0][0] = Brushes.Blue;
      PlotBrushes[1][0] = Brushes.Blue;​
      }

      Then I want when changing these plotBrushes, change it's region inside too, but from now is not working I want to draw the region when if (condition) to
      Draw.Region(this, "myRegion", CurrentBar, 0, Values[0], Values[1], null, Brushes.Yellow, 10);
      and in the else would be
      Draw.Region(this, "myRegion", CurrentBar, 0, Values[0], Values[1], null, Brushes.Blue, 10);

      but is not working, I've tried to add a different id but neither, what I'm missing?

      Comment


        #4
        Hello cmtjoancolmenero,

        You would need a new region object with a unique tag name for each region you want as a different color.

        You may find this indicator on the User App Share helpful as it adds a new region object with a different color on each crossover.
        Rewrite of the MACrossBuilder 1) Various Moving averages: DEMA, EMA, LinReg, HMA, SMA, TEMA, TMA, VWMA, WMA, ZLEMA 2) Various indication options 3) Can output to alerts window 4) Can output to Market Analyzer (+1, 0, ‐1 = Cross up, No cross, cross down) 5) Colors region between Moving averages V1.02 Update 10‐31‐17, minor code […]
        Chelsea B.NinjaTrader Customer Service

        Comment


          #5
          Hello ChelseaB, I've tried with unique tag name but still doesn't work, maybe I'm missing something.

          I have two plots and I'm changing its color using
          PlotBrushes[0][0] = Brushes.Lime;
          PlotBrushes[1][0] = Brushes.Lime;​

          And
          PlotBrushes[0][0] = Brushes.Red;
          PlotBrushes[1][0] = Brushes.Red;​

          Now whenever I try to fill this two lines it's only painting in red even if I do this

          if (someCondition)
          {
          PlotBrushes[0][0] = Brushes.Lime;
          PlotBrushes[1][0] = Brushes.Lime;
          Draw.Region(this, "ChannelFilled" + CurrentBar, CurrentBar, 0, Values[0], Values[1], null, Brushes.Lime, 56);
          }
          else
          {
          PlotBrushes[0][0] = Brushes.Red;
          PlotBrushes[1][0] = Brushes.Red;
          Draw.Region(this, "ChannelFilled"+CurrentBar, CurrentBar, 0, Values[0], Values[1], null, Brushes.Red, 56);
          }

          Values[0][0] = MySeriesDouble[0];
          Values[1][0] = MySeriesDouble2[0];

          Doing this, is always painting Brushes.Red, what I'm missing?​​

          Edit
          ------
          I think I know what I was missing on my logic, now I'm storing the startBar I want to start printing depending on the someCondition for example

          condition1StartBar = -1
          condition2StartBar = -1

          if(condition1)
          {
          condition1StartBar= CurrentBar;
          condition2StartBar= -1;
          }
          else {
          condition1StartBar= -1;
          condition2StartBar= CurrentBar;​
          }

          Now, I want to print using this :

          if(condition1) {
          //some logic
          if(condition1StartBar != -1) {
          Draw.Region(this, "example" + condition1StartBar, condition1StartBar, CurrentBar, Values[0], Values[1], null, Brushes.Lime, 56);
          }
          }
          else {
          if(condition2StartBar != -1) {
          Draw.Region(this, "example" + condition2StartBar, condition2StartBar, CurrentBar, Values[0], Values[1], null, Brushes.Lime, 56);
          }​
          }


          But even using this is not working... I want to start printing from the CurrentBar I've stored until the CurrentBar.

          Comment


            #6
            Hello cmtjoancolmenero,

            The example I have provided you demonstrates this.

            On line 570 to 575 the condition is a crossabove. When the condition is true the savedUBar is assigned to the bar number the condition occurred on and sets CrossDetect to 1 to indicate a cross above has occurred.

            On lines 586 to 589, if the CrossDetect is 1, the region is drawn using the bar number of the object as the unique tag, and draws from the number of bars ago the condition was true on (CurrentBar - savedUBar + 1) to 0 bars ago.
            Chelsea B.NinjaTrader Customer Service

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by Geovanny Suaza, 02-11-2026, 06:32 PM
            0 responses
            556 views
            0 likes
            Last Post Geovanny Suaza  
            Started by Geovanny Suaza, 02-11-2026, 05:51 PM
            0 responses
            324 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
            545 views
            1 like
            Last Post Geovanny Suaza  
            Started by RFrosty, 01-28-2026, 06:49 PM
            0 responses
            547 views
            1 like
            Last Post RFrosty
            by RFrosty
             
            Working...
            X