Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

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.

    Comment


      #3
      Thanks! That did it.

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by Segwin, 05-07-2018, 02:15 PM
      10 responses
      1,768 views
      0 likes
      Last Post Leafcutter  
      Started by Rapine Heihei, 04-23-2024, 07:51 PM
      2 responses
      30 views
      0 likes
      Last Post Max238
      by Max238
       
      Started by Shansen, 08-30-2019, 10:18 PM
      24 responses
      943 views
      0 likes
      Last Post spwizard  
      Started by Max238, Today, 01:28 AM
      0 responses
      10 views
      0 likes
      Last Post Max238
      by Max238
       
      Started by rocketman7, Today, 01:00 AM
      0 responses
      7 views
      0 likes
      Last Post rocketman7  
      Working...
      X