Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

DrawRegion() Problem

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

    DrawRegion() Problem

    Hi!

    I can't make the DrawRegion() method work properly. I provide an "as simple as possible" example that I thought would work, but doesn't, and I can't figure out why. Can you help?

    Code:
    namespace NinjaTrader.Indicator
    {
        [Description("")]
        public class DrawRegionTest : Indicator
        {
            #region Variables
            // PARAMETERS
            double trendThreshold    = 25.0;
            
            // Helper Variables
            private int trendStartBar     = 0;
            private int trendInstance     = 0;
            private BoolSeries trend;
            #endregion
    
                    
            #region Initialize()
            protected override void Initialize()
            {            
                trend            = new BoolSeries(this);
                            
                Add(new Plot(Color.Lime, PlotStyle.Dot, "ADX(14)"));
                Plots[0].Pen.Width          = 1;
                Plots[0].Pen.DashStyle     = DashStyle.Dot;
                
                Add(new Line(Color.Magenta, trendThreshold, "TrendThreshold"));
                Lines[0].Pen.Width         = 1;
                Lines[0].Pen.DashStyle     = DashStyle.Dot;
                
                            
                Overlay             = false;
                PriceTypeSupported     = false;
                DrawOnPricePanel     = true;
                PaintPriceMarkers    = false;
                CalculateOnBarClose = true;
            }
            #endregion
            
            protected override void OnBarUpdate()
            {
                
                Values[0].Set(ADX(14)[0]);
                trend.Set(false);        // Set inital value
                
                if ( CurrentBar < 15 ) return; // ADX period + 1
                        
                // ADX(14) above trendThreshold and positive slope
                if ( Values[0][0] > trendThreshold && Slope(Values[0], 1, 0) > 0.0)
                {
                    trend.Set(true);
                    PlotColors[0][0] = Color.Blue;
                    
                    // Color region between ADX(14) and trendThreshold
                    if ( trend[1] == false) // First bar in the new trend
                    {
                        trendStartBar = CurrentBar;
                        trendInstance += 1;
                    }
                    
                    [COLOR=Red]DrawRegion("trendInstance" + trendInstance, CurrentBar - trendStartBar, 0, Values[0], trendThreshold, Color.LightGray, Color.Blue, 7);[/COLOR]
                }
                
                //Trouble Shooting
                
                Print("");
                Print("CurrentBar: " + CurrentBar);
                Print("Time[0]: " + Time[0]);
                Print("trend[1]: " + trend[1]);
                Print("trendStartBar: " + trendStartBar);
                Print("trendInstance: " + trendInstance);
                Print("CurrentBar - trendStartBar: " + (CurrentBar - trendStartBar));
                Print("Values[0][0]: " + Values[0][0]);
            }
    
                    
            #region Properties
            #endregion
        }
    }
    /Regards
    Attached Files
    Last edited by poseidon_sthlm; 01-26-2011, 11:51 AM.

    #2
    Hello,

    Your issue is here:

    DrawOnPricePanel = true;

    Therefor the region is drawing on the main price panel which is out of the visable range so you dont see the Region.

    Set this to False here.

    Let me know if I can be of further assistance.

    BrettNinjaTrader Product Management

    Comment


      #3
      Thanks! That did it.

      Comment

      Latest Posts

      Collapse

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