Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Issue with Draw.Region

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

    Issue with Draw.Region

    When I try to draw a Region with a specific color using a Series<double> I created I cannot draw between the lines.

    The relevant code is:
    private Series<double> dSeriesA;
    private Series<double> dSeriesB;

    else if (State == State.DataLoaded)
    {
    dSeriesA = new Series<double>(this);
    dSeriesB = new Series<double>(this);
    }

    Draw.Region(this, "Region", 5, CurrentBar, dSeriesA, dSeriesB, null, Brushes.Green, 50, 0);

    It does not draw / fill the region between dSeriesA and dSeriesB regardless whether dSeriesA > dSeriesB or dSeriesB > dSeriesA.
    I did use the same code but used High and Low respectively and it did draw as expected
    Draw.Region(this, "Region", CurrentBar, 0, Close, Open, null, Brushes.BurlyWood, 50, 0);

    Is there an issue wit how I declared my Series? If so, what it the correct way to declare it?

    #2
    Hello ATMtrader0001,

    Draw.Region() can shade a region between two series.

    Are you setting a value for these series on every bar on the chart?

    If you print the values, do you see these are the expected values?
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      I did forget to post that code. Yes I am assigning a value to each bar and when I print the values it is populated.

      Anything else I can try?

      Comment


        #4
        Here's some basic code to just run a test for filling a Region, which again does not fill in the region.

        namespace NinjaTrader.NinjaScript.Indicators
        {
        public class TestRegionDraw : Indicator
        {
        private Series<double> dLineA;
        private Series<double> dLineB;

        protected override void OnStateChange()
        {
        if (State == State.SetDefaults)
        {
        Description = @"Enter the description for your new custom Indicator here.";
        Name = "TestRegionDraw";
        Calculate = Calculate.OnBarClose;
        IsOverlay = false;
        DisplayInDataBox = true;
        DrawOnPricePanel = true;
        DrawHorizontalGridLines = true;
        DrawVerticalGridLines = true;
        PaintPriceMarkers = true;
        ScaleJustification = NinjaTrader.Gui.Chart.ScaleJustification.Right;
        //Disable this property if your indicator requires custom values that cumulate with each new market data event.
        //See Help Guide for additional information.
        IsSuspendedWhileInactive = true;
        AddPlot(new Stroke(Brushes.Chartreuse, 2), PlotStyle.Line, "dLineA");
        AddPlot(new Stroke(Brushes.DodgerBlue, 2), PlotStyle.Line, "dLineB");
        }
        else if (State == State.Configure)
        {
        }
        else if (State == State.DataLoaded)
        {
        dLineA = new Series<double>(this);
        dLineB = new Series<double>(this);
        }
        }

        protected override void OnBarUpdate()
        {
        //Add your custom indicator logic here.
        dLineA[0] = (High[0] + High[1]) / 2;
        dLineB[0] = (Low[0] + Low[1]) / 2;

        Values[0][0] = dLineA[0];
        Values[1][0] = dLineB[0];
        Print(dLineA[0] + "\t" + dLineB[0]);
        Draw.Region(this, "Region" + Times[0][0].TimeOfDay, 1, 0, dLineB, dLineA, null, Brushes.Red, 50, 0);

        }
        }
        }

        I have tried the Draw.Region with dLineB/dLineA in both positions. Same result. So apparently there is an issue
        with my the way my Series is declared.

        Any thoughts? I would love to get this working.

        Comment


          #5
          Is it because it is a Series and not an ISeries?

          Comment


            #6
            Hello ATMtrader0001,

            No, the issue is not because you are using a Series and not an ISeries. ISeries are no longer used in NinjaTrader 8.

            Have you looked at the Log tab of the Control Center for any errors?

            When instantiating the series, use MaximumBarsLookBack.Infinite so the Draw.Region() call has the full series data.

            dLineA = new Series<double>(this, MaximumBarsLookBack.Infinite);

            From the help guide:
            "3. Should you be drawing regions based on Series<double> objects instead of indicator plots, be sure to create the Series<double> with the MaximumBarsLookBack.Infinite parameter if the region you are drawing would be maintained on the chart for more than 256 bars back."

            Chelsea B.NinjaTrader Customer Service

            Comment


              #7
              I didn't realize that Log tab had runtime related messages, I was looking in the Output window.

              Thanks for that tip. Had I looked there I would have seen that you are right on the Infinite setting.

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by Geovanny Suaza, 02-11-2026, 06:32 PM
              0 responses
              648 views
              0 likes
              Last Post Geovanny Suaza  
              Started by Geovanny Suaza, 02-11-2026, 05:51 PM
              0 responses
              369 views
              1 like
              Last Post Geovanny Suaza  
              Started by Mindset, 02-09-2026, 11:44 AM
              0 responses
              108 views
              0 likes
              Last Post Mindset
              by Mindset
               
              Started by Geovanny Suaza, 02-02-2026, 12:30 PM
              0 responses
              572 views
              1 like
              Last Post Geovanny Suaza  
              Started by RFrosty, 01-28-2026, 06:49 PM
              0 responses
              573 views
              1 like
              Last Post RFrosty
              by RFrosty
               
              Working...
              X