- 5-min (BarsInProgress == 0)
- 1-min (BarsInProgress == 1)
One indicator is added to the strategy, and it has a DataSeries as a member.
In OnBarUpdate() of the strategy, the day-of-the-month is calculated, and the indicator’s DataSeries member set to this value.
The value should remain constant during a given day, i.e. on July 1st, it should be "1". On July 2nd, it should be "2"....
All works as expected for historical data.
But for the first real-time bar, the value of the indicator’s DataSeries member is incorrect. It changes, but should not.
Please see screenshot.
Any ideas what is happening or how to correct?
So that you can verify this behaviour yourself, here is the code:
STRATEGY:
[standard Using declarations] namespace NinjaTrader.Strategy { public class JHanTest : Strategy { protected override void Initialize() { Add(jHanTestIndy()); Add(PeriodType.Minute, 1); CalculateOnBarClose = true; } protected override void OnBarUpdate() { if (BarsInProgress != 0) return; this.jHanTestIndy().Ds[0] = Time[0].Day; this.jHanTestIndy().Update(); } } }
[standard Using declarations] namespace NinjaTrader.Indicator { public class jHanTestIndy : Indicator { #region Variables private DataSeries ds = null; #endregion protected override void Initialize() { Add(new Plot(Color.FromKnownColor(KnownColor.Orange), PlotStyle.Line, "Plot0")); Overlay = false; this.ds = new DataSeries(this); } protected override void OnBarUpdate() { if (Ds[0] != null) Plot0[0] = Ds[0]; else Plot0.Reset(); } #region Properties [Browsable(false)] [XmlIgnore()] public DataSeries Plot0 { get { return Values[0]; } } [Browsable(false)] [XmlIgnore()] public DataSeries Ds { get { return this.ds; } set { this.ds = value; } } #endregion } }
Comment