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 sjsj2732, Yesterday, 04:31 AM
      0 responses
      39 views
      0 likes
      Last Post sjsj2732  
      Started by NullPointStrategies, 03-13-2026, 05:17 AM
      0 responses
      290 views
      0 likes
      Last Post NullPointStrategies  
      Started by argusthome, 03-08-2026, 10:06 AM
      0 responses
      289 views
      0 likes
      Last Post argusthome  
      Started by NabilKhattabi, 03-06-2026, 11:18 AM
      0 responses
      135 views
      1 like
      Last Post NabilKhattabi  
      Started by Deep42, 03-06-2026, 12:28 AM
      0 responses
      96 views
      0 likes
      Last Post Deep42
      by Deep42
       
      Working...
      X