diff --git a/Indicators/AdvanceDeclineIndicator.cs b/Indicators/AdvanceDeclineIndicator.cs index 30937b446353..b51ce601753b 100644 --- a/Indicators/AdvanceDeclineIndicator.cs +++ b/Indicators/AdvanceDeclineIndicator.cs @@ -150,6 +150,7 @@ public override void Reset() { _currentPeriod[key] = null; } + _currentPeriodTime = null; base.Reset(); } diff --git a/Tests/Indicators/AdvanceDeclineDifferenceTests.cs b/Tests/Indicators/AdvanceDeclineDifferenceTests.cs index da8b75abb893..d8c2a716c752 100644 --- a/Tests/Indicators/AdvanceDeclineDifferenceTests.cs +++ b/Tests/Indicators/AdvanceDeclineDifferenceTests.cs @@ -83,6 +83,26 @@ public virtual void ShouldIgnoreRemovedStocks() Assert.AreEqual(0m, adDifference.Current.Value); } + [Test] + public void ProducesTheSameValuesAfterReset() + { + var indicator = CreateIndicator(); + var reference = System.DateTime.Today; + + UpdateStocks(indicator, reference.AddMinutes(1), 1m, 1m, 1m); + UpdateStocks(indicator, reference.AddMinutes(2), 2m, 0.5m, 3m); + var expected = indicator.Current.Value; + Assert.AreNotEqual(0m, expected); + + UpdateStocks(indicator, reference.AddMinutes(3), 3m, 1m, 2m); + indicator.Reset(); + + UpdateStocks(indicator, reference.AddMinutes(1), 1m, 1m, 1m); + UpdateStocks(indicator, reference.AddMinutes(2), 2m, 0.5m, 3m); + + Assert.AreEqual(expected, indicator.Current.Value); + } + [Test] public virtual void IgnorePeriodIfAnyStockMissed() { @@ -295,6 +315,13 @@ public override void IndicatorShouldHaveSymbolAfterUpdates() } } + private static void UpdateStocks(IndicatorBase indicator, System.DateTime time, decimal aapl, decimal ibm, decimal goog) + { + indicator.Update(new TradeBar() { Symbol = Symbols.AAPL, Close = aapl, Volume = 100, Time = time }); + indicator.Update(new TradeBar() { Symbol = Symbols.IBM, Close = ibm, Volume = 100, Time = time }); + indicator.Update(new TradeBar() { Symbol = Symbols.GOOG, Close = goog, Volume = 100, Time = time }); + } + protected override string TestFileName => "arms_data.txt"; protected override string TestColumnName => "A/D Difference"; diff --git a/Tests/Indicators/McClellanOscillatorTests.cs b/Tests/Indicators/McClellanOscillatorTests.cs index 9b11e368e3f6..90d7811a3f62 100644 --- a/Tests/Indicators/McClellanOscillatorTests.cs +++ b/Tests/Indicators/McClellanOscillatorTests.cs @@ -151,10 +151,7 @@ public TestMcClellanOscillator() : base() Add(symbol); } - // Set to the first EMA values to account for past A/D Difference values that we don't have access Reset(); - EMAFast.Update(new DateTime(2022, 6, 30), -209.85m); - EMASlow.Update(new DateTime(2022, 6, 30), -186.41m); } public void TestUpdate(IndicatorDataPoint input) @@ -189,6 +186,10 @@ public override void Reset() { _symbols[symbol] = 0m; } + + // Set to the first EMA values to account for past A/D Difference values that we don't have access + EMAFast.Update(new DateTime(2022, 6, 30), -209.85m); + EMASlow.Update(new DateTime(2022, 6, 30), -186.41m); } } } diff --git a/Tests/Indicators/McClellanSummationIndexTests.cs b/Tests/Indicators/McClellanSummationIndexTests.cs index 159731e879b3..919babcdd987 100644 --- a/Tests/Indicators/McClellanSummationIndexTests.cs +++ b/Tests/Indicators/McClellanSummationIndexTests.cs @@ -150,12 +150,7 @@ public TestMcClellanSummationIndex() : base() Add(symbol); } - // Set to the first EMA values to account for past A/D Difference values that we don't have access Reset(); - Summation.Time = new DateTime(2022, 6, 30); - Summation.Value = -606.25m; - McClellanOscillator.EMAFast.Update(new DateTime(2022, 6, 30), -209.85m); - McClellanOscillator.EMASlow.Update(new DateTime(2022, 6, 30), -186.41m); } public void TestUpdate(IndicatorDataPoint input) @@ -190,6 +185,12 @@ public override void Reset() { _symbols[symbol] = 0m; } + + // Set to the first EMA values to account for past A/D Difference values that we don't have access + Summation.Time = new DateTime(2022, 6, 30); + Summation.Value = -606.25m; + McClellanOscillator.EMAFast.Update(new DateTime(2022, 6, 30), -209.85m); + McClellanOscillator.EMASlow.Update(new DateTime(2022, 6, 30), -186.41m); } } }