Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Indicators/AdvanceDeclineIndicator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ public override void Reset()
{
_currentPeriod[key] = null;
}
_currentPeriodTime = null;

base.Reset();
}
Expand Down
27 changes: 27 additions & 0 deletions Tests/Indicators/AdvanceDeclineDifferenceTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
{
Expand Down Expand Up @@ -295,6 +315,13 @@ public override void IndicatorShouldHaveSymbolAfterUpdates()
}
}

private static void UpdateStocks(IndicatorBase<TradeBar> 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";
Expand Down
7 changes: 4 additions & 3 deletions Tests/Indicators/McClellanOscillatorTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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);
}
}
}
11 changes: 6 additions & 5 deletions Tests/Indicators/McClellanSummationIndexTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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);
}
}
}
Loading