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
9 changes: 6 additions & 3 deletions Indicators/NewHighsNewLows.cs
Original file line number Diff line number Diff line change
Expand Up @@ -233,9 +233,12 @@ private bool HasMissingCurrentPeriodValue()

private bool HasSufficientPreviousDataForComputation()
{
return _trackedAssets.All(asset =>
asset.RollingPreviousHigh.IsReady
&& asset.RollingPreviousLow.IsReady);
// All() holds over an empty set, so without this the indicator reports itself
// ready before any asset is tracked
return _trackedAssets.Any()
&& _trackedAssets.All(asset =>
asset.RollingPreviousHigh.IsReady
&& asset.RollingPreviousLow.IsReady);
}

private void UpdatePreviousValues(TrackedAsset asset, IBaseDataBar bar)
Expand Down
19 changes: 19 additions & 0 deletions Tests/Indicators/NewHighsNewLowsTestsBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -162,5 +162,24 @@ public override void AcceptsVolumeRenkoBarsAsInput()
ibmRenkoConsolidator.Dispose();
}
}

[Test]
public void IsNotReadyWithoutTrackedAssets()
{
var indicator = CreateNewHighsNewLowsIndicator();

Assert.IsFalse(indicator.IsReady);
}

[Test]
public void IsNotReadyOnceTheLastTrackedAssetIsRemoved()
{
var indicator = CreateNewHighsNewLowsIndicator();
indicator.Add(Symbols.AAPL);
indicator.Remove(Symbols.AAPL);

Assert.IsFalse(indicator.IsReady);
}

}
}
Loading