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 algospoke, Yesterday, 06:40 PM
      2 responses
      19 views
      0 likes
      Last Post algospoke  
      Started by ghoul, Today, 06:02 PM
      3 responses
      14 views
      0 likes
      Last Post NinjaTrader_Manfred  
      Started by jeronymite, 04-12-2024, 04:26 PM
      3 responses
      45 views
      0 likes
      Last Post jeronymite  
      Started by Barry Milan, Yesterday, 10:35 PM
      7 responses
      20 views
      0 likes
      Last Post NinjaTrader_Manfred  
      Started by AttiM, 02-14-2024, 05:20 PM
      10 responses
      181 views
      0 likes
      Last Post jeronymite  
      Working...
      X