I'm trying to build a very simple indicator that will visually print a line indicating the open price of the current (or at the time, current) month on a chart.
The problem I'm having is that the current month line is correct but the line for the previous month's don't represent the then current month's open but rather the prior month's open. To say it another way, if I put this indicator on a current live chart, the line for today properly shows today's open which is also the month open but yesterday's line isn't last month's open but rather January's.
Code so far below. Would appreciate any help!
namespace NinjaTrader.NinjaScript.Indicators { public class Monthly_Open : Indicator { private double monthOpenPrice; protected override void OnStateChange() { if (State == State.SetDefaults) { Description = @"Enter the description for your new custom Indicator here."; Name = "Monthly_Open"; Calculate = Calculate.OnPriceChange; IsOverlay = true; DisplayInDataBox = true; DrawOnPricePanel = false; 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; AddPlot(new Stroke(Brushes.LightGray, 1), PlotStyle.Line, "Monthly_Open"); } else if (State == State.Configure) { AddDataSeries(BarsPeriodType.Month, 1); } } protected override void OnBarUpdate() { if (BarsInProgress == 1) { monthOpenPrice = Open[0]; } if (BarsInProgress == 0) { Monthly_Open[0] = monthOpenPrice; } } #region Properties [Browsable(false)] [XmlIgnore] public Series<double> Monthly_Open { get { return Values[0]; } } #endregion } }
Comment