Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Region Fill Not Working as Expected

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

    Region Fill Not Working as Expected

    I am trying to bring over an indicator I have in NT7 to NT8, but the RegionFill command is apparently not working the same as it does in NT7. The code I wrote is intended to color a region between a faster moving average line and a lower moving average line, cyan if fast line if above slow line, and light pink if fast line is below line. Here is the code that is supposed to do that:
    // private Series<double> mid;

    AddPlot(Brushes.Chartreuse, "H_Avg");
    AddPlot(Brushes.OrangeRed, "L_Avg");
    AddPlot(Brushes.Aqua, "Max");
    AddPlot(Brushes.DarkMagenta, "Min");
    AddPlot(Brushes.Yellow, "MidLine");
    AddPlot(Brushes.Black, "TrendLine");
    }
    else if (State == State.Configure)
    {
    max = MAX(High, Period_M);
    min = MIN(Low, Period_M);
    mid = new Series<double>(this);
    }
    }

    protected override void OnConnectionStatusUpdate(ConnectionStatusEventArgs connectionStatusUpdate)
    {

    }

    protected override void OnMarketData(MarketDataEventArgs marketDataUpdate)
    {

    }

    protected override void OnBarUpdate()
    {
    if(CurrentBar < Period_B)
    return;

    double max0 = max[0];
    double min0 = min[0];
    mid[0] = (((max0-min0) * 0.5 )+ min0);

    H_Avg[0] = SMA(EMA(High, Period_B), Period_S)[0];
    L_Avg[0] = SMA(EMA(Low, Period_B), Period_S)[0];
    Max[0] = max0;
    Min[0] = min0;
    MidLine[0] = SMA(mid, Period_S)[0];
    TrendLine[0] = EMA(Median, 2*Period_M)[0];

    if(MidLine[0] > TrendLine[0])
    {
    Draw.Region(this, "Cloud1" + CurrentBar, CurrentBar, 0, MidLine, TrendLine, null, Brushes.Cyan, 30);
    }
    else if(MidLine[0] <= TrendLine[0])
    {
    Draw.Region(this, "Cloud1" +CurrentBar, CurrentBar, 0, MidLine, TrendLine, null, Brushes.LightPink, 30);
    }
    }
    I've also attached a screen shot to show you what it actually is doing.
    What am I doing wrong in the code?
    DaveN
    Attached Files

    #2
    Been a whole day and no one has responded to this message. Is there an issue with the way I posted it?

    Comment


      #3
      hello daven,

      Thanks for your post and patience.

      I am reviewing and will respond later today.

      Comment


        #4
        Hello daven,

        Thanks for your patience.

        The issue is the use of CurrentBar as the startbars ago value. Because CurrentBar is the bar count the farther you go to the right edge the larger the CurrentBar value is. So in Draw.Region you are telling it to start coloring basically from the beginning and the consequence is that you are constantly overlaying the regions.

        I'm not sure what you wanted to do but if you use 1 as the start bars ago and 0 as the endbars ago then the regions will paint as expected relative to the direction of the lines.

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by Geovanny Suaza, 02-11-2026, 06:32 PM
        0 responses
        670 views
        0 likes
        Last Post Geovanny Suaza  
        Started by Geovanny Suaza, 02-11-2026, 05:51 PM
        0 responses
        379 views
        1 like
        Last Post Geovanny Suaza  
        Started by Mindset, 02-09-2026, 11:44 AM
        0 responses
        111 views
        0 likes
        Last Post Mindset
        by Mindset
         
        Started by Geovanny Suaza, 02-02-2026, 12:30 PM
        0 responses
        575 views
        1 like
        Last Post Geovanny Suaza  
        Started by RFrosty, 01-28-2026, 06:49 PM
        0 responses
        582 views
        1 like
        Last Post RFrosty
        by RFrosty
         
        Working...
        X