Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Drawing a region with a condition

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

    Drawing a region with a condition

    Hello,

    I'm trying to draw a region whose color will depend on whether an indicator line is higher or lower than another indicator line.

    It just keeps giving me the same color, though.

    Could you please tell me what is incorrect with this syntax? I've simplified the issue with the following sample.

    I would be most grateful for your help.


    SAMPLE:
    // If the close of the bar is higher than the open of the bar, the region should be painted blue. If the other way around, painted yellow.

    if (Close[0] > Open[0])
    {
    Draw.Region(this, "BULL", CurrentBar, 0, Close, Open, Brushes.Transparent, Brushes.Blue, 50);
    }

    else if (Close[0] < Open[0])
    {
    Draw.Region(this, "BEAR", CurrentBar, 0, Close, Open, Brushes.Transparent, Brushes.Yellow, 50);
    }


    #2
    Hello catinabag,

    Thanks for your post.

    The Draw.Region() statements look like they will draw from the very first bar in the data series to the current bar and they will draw on top of each other (as you are using the same data series in each) providing a color that is not as Blue or not as Yellow. The last color drawn should be visible on the last bar(s) until the condition changes when the regions are then drawn over again.

    Bottom line is that the code is drawing as expected.

    Can you clarify what you are trying to accomplish? (You might want to provide chart/screenshot that shows what you are looking to do).


    Comment


      #3
      Hi there, thanks for getting back. Here's a picture and some relevant code (at the bottom):

      It's essentially the same as my post above, but there are some lines being calculated that are now "StrategyPlot" and "StrategyPlot2."

      I'm really puzzled by this. Is there something I should be adding here? Thanks in advance for your help.

      SAMPLE CODE:
      if (StrategyPlot[0] > StrategyPlot2[0])
      {
      Draw.Region(this, "BULL", CurrentBar, 0, StrategyPlot, StrategyPlot2, Brushes.Transparent, Brushes.Blue, 50);
      BackBrush = Brushes.DarkGreen;
      }
      else if (StrategyPlot[0] < StrategyPlot2[0])
      {
      Draw.Region(this, "BEAR", CurrentBar, 0, StrategyPlot, StrategyPlot2, Brushes.Transparent, Brushes.Yellow, 50);
      BackBrush = Brushes.DarkRed;
      }

      Comment


        #4
        Hello catinabag,

        Thanks for your reply and screenshot as that clarifies what you want to do.

        As previously advised the Draw.Region() statements are both drawing from the very first bar of the data series to the current bar and each draws their own color when their condition is true.

        Based on your screenshot, when you have a cross condition your want a certain color for the region, when it crosses the other way you want the other color. This means that you cannot draw from the very first bar to the current bar, you have to draw from the bar where the cross occurs to the current bar with the color applicable to the condition. This also means that for each cross you will have to create a unique tag name as otherwise the previously drawn region with the same tag name would be removed.

        You can see an example of the type of coding to allow different colored regions in this indicator in the NT user apps: https://ninjatraderecosystem.com/use...plestate_v4-2/ Please note: 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
          Thank you for your helpful reply. I got it. (Great code, by the way. I presume it is your creation, NinjaTrader_Paul seems close to your forum handle!)

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by Geovanny Suaza, 02-11-2026, 06:32 PM
          0 responses
          580 views
          0 likes
          Last Post Geovanny Suaza  
          Started by Geovanny Suaza, 02-11-2026, 05:51 PM
          0 responses
          335 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
          552 views
          1 like
          Last Post RFrosty
          by RFrosty
           
          Working...
          X