I keep getting this error message when I try to add this indicator to a chart (it won't plot) but it complies fine and the weird thing is I have these same lines of code (at the bottom just below the comment "//shading the region between the keltnerchannels")
in another one of my indicators and it works fine. Here's the message...
Error on calling 'OnBarUpdate' method for indicator 'KeltnerChannelRiseFallShade' on bar 0: KeltnerChannelRiseFallShade.DrawRegion: startBarsAgo out of valid range 0 through 0, was 1.
I just cut and pasted NinjaTraders KeltnerChannel indicator and am modifying it.
Any help will, I assure you, will be greatly appreciated.
public class KeltnerChannelRiseFallShade : Indicator { #region Variables private int period = 21; private double offsetMultiplier = 2.5; private DataSeries diff; private int opacitylevel =2; private int wmaperiod = 200; private bool shading = true; #endregion /// <summary> /// This method is used to configure the indicator and is called once before any bar data is loaded. /// </summary> protected override void Initialize() { Add(new Plot(Color.DarkGray, "Midline")); Add(new Plot(Color.Blue, "Upper")); Add(new Plot(Color.Blue, "Lower")); diff = new DataSeries(this); Overlay = true; CalculateOnBarClose =false; } /// <summary> /// Called on each bar update event (incoming tick). /// </summary> protected override void OnBarUpdate() { diff.Set(High[0] - Low[0]); double wmashading = WMA(Typical,wmaperiod)[0]; double middle = SMA(Typical, Period)[0]; double offset = SMA(diff, Period)[0] * offsetMultiplier; double upper = middle + offset; double lower = middle - offset; Midline.Set(middle); Upper.Set(upper); Lower.Set(lower); if (Rising(Midline)) { PlotColors[0][0] = Color.Green; } else if (Falling(Midline)) { PlotColors[0][0] = Color.Red; } else { PlotColors[0][0] = Color.Yellow; } //shading the region between the keltnerchannels if (shading && Close[0] > wmashading) { DrawRegion("shade" + CurrentBar, 1, 0, Upper, Lower, Color.Empty, Color.PaleGreen, opacitylevel); } else if (shading && Close[0] < wmashading) { DrawRegion("shade" + CurrentBar, 1, 0, Upper, Lower, Color.Empty, Color.LightPink, opacitylevel); }
Comment