For some reason, it seems to be missing signals. If I print out the value for each CCI, you can easily see all the values are under -25, but there is no signal bar. How can I get this to work?
See the attached screenshot of the indicator and CCI values. There should be signals for each minute from 22:22 all the way to the first one that actually shows at 22:45, but they are missing.
Here's the code:
namespace NinjaTrader.NinjaScript.Indicators { public class aaMultiCCI : Indicator { private CCI cci0; private CCI cci1; private CCI cci2; private CCI cci3; private CCI cci4; private int shortSignalBar = 0; protected override void OnStateChange() { if (State == State.SetDefaults) { Description = @"aaMultiCCI"; Name = "aaMultiCCI"; Calculate = Calculate.OnBarClose; IsOverlay = false; DisplayInDataBox = true; DrawOnPricePanel = true; DrawHorizontalGridLines = true; DrawVerticalGridLines = true; PaintPriceMarkers = true; ScaleJustification = NinjaTrader.Gui.Chart.ScaleJustification.Right; //Disable this property if your indicator requires custom values that cumulate with each new market data event. //See Help Guide for additional information. IsSuspendedWhileInactive = true; confirmSell = new Series<bool>(this); period = 60; cciOverSoldLevel = -25; AddPlot(new Stroke(Brushes.Red, 3), PlotStyle.Bar, "confirmSellBar"); } else if (State == State.Configure) { AddDataSeries(BarsPeriodType.Minute, 1); AddDataSeries(BarsPeriodType.Minute, 5); AddDataSeries(BarsPeriodType.Minute, 10); AddDataSeries(BarsPeriodType.Minute, 15); AddDataSeries(BarsPeriodType.Minute, 20); } else if (State == State.DataLoaded) { cci0 = CCI(BarsArray[1], period); cci1 = CCI(BarsArray[2], period); cci2 = CCI(BarsArray[3], period); cci3 = CCI(BarsArray[4], period); cci4 = CCI(BarsArray[5], period); } } protected override void OnBarUpdate() { if ( CurrentBars[0] < 30 || CurrentBars[1] < 30 || CurrentBars[2] < 30 || CurrentBars[3] < 30 || CurrentBars[4] < 30 || CurrentBars[5] < 30) { return; } if (BarsInProgress != 1) { return; } // TODO: Adjust timezone. This is Mountain time. if (Bars.GetTime(CurrentBars[0]) > new DateTime(2017, 11, 08, 22, 20, 00) && Bars.GetTime(CurrentBars[0]) < new DateTime(2017, 11, 08, 23, 00, 00) ) { Print("time: " + Bars.GetTime(CurrentBars[0])); Print("cci0: " + cci0[0]); Print("cci1: " + cci1[0]); Print("cci2: " + cci2[0]); Print("cci3: " + cci3[0]); Print("cci4: " + cci4[0]); } if ( cci0[1] < cciOverSoldLevel && cci1[1] < cciOverSoldLevel && cci2[1] < cciOverSoldLevel && cci3[1] < cciOverSoldLevel && cci4[1] < cciOverSoldLevel ) { Values[0][0] = 1; confirmSell[0] = true; shortSignalBar = CurrentBars[0]; } if (CurrentBars[0] != shortSignalBar) { Values[0].Reset(); confirmSell[0] = false; } } #region Properties [Browsable(false)] [XmlIgnore()] public Series<bool> confirmBuy { get; set; } [Browsable(false)] [XmlIgnore()] public Series<bool> confirmSell { get; set; } [Range(1, int.MaxValue), NinjaScriptProperty] [Display(ResourceType = typeof(Custom.Resource), Name = "Period", GroupName = "NinjaScriptParameters", Order = 0)] public int period { get; set; } [Range(int.MinValue, 0), NinjaScriptProperty] [Display(ResourceType = typeof(Custom.Resource), Name = "Over Sold Level", GroupName = "NinjaScriptParameters", Order = 1)] public double cciOverSoldLevel { get; set; } #endregion } }
Comment