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?
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 } }
Comment