I tried to write an indicator which plots a 25-hourly SMA and a 8-daily EMA on any lower timeframe chart. This is what I came up with, but for whatever reasons nothing is showing up on the chart
namespace NinjaTrader.NinjaScript.Indicators { public class AbcMovAvg : Indicator { protected override void OnStateChange() { if (State == State.SetDefaults) { Description = @"Plot the 25 hourly SMA and the 8 daily EMA on any chart"; Name = "AbcMovAvg"; 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; } else if (State == State.Configure) { AddDataSeries(Data.BarsPeriodType.Minute, 60); AddDataSeries(Data.BarsPeriodType.Day, 1); AddPlot(Brushes.HotPink, "MovAvg1"); AddPlot(Brushes.Blue, "MovAvg2"); } } protected override void OnBarUpdate() { // Ensures that the plot is drawn on the primary data series if (BarsInProgress == 0) { double d_MA1 = SMA(BarsArray[1], 25)[0]; double d_MA2 = EMA(BarsArray[2], 8)[0]; MovAvg1[0] = d_MA1; MovAvg2[0] = d_MA2; } } #region Properties [Browsable(false)] [XmlIgnore] public Series<double> MovAvg1 { get { return Values[0]; } } [Browsable(false)] [XmlIgnore] public Series<double> MovAvg2 { get { return Values[1]; } } #endregion } }
Comment