Skip to content

AdvanceDeclineIndicator.Reset leaves the period watermark set, so it silently drops every later bar #9683

Description

@mkzung

Expected Behavior

After Reset(), an indicator produces the same values on a replay as a fresh instance fed the same bars.

Actual Behavior

AdvanceDeclineIndicator.Reset() clears _advanceDeclineDictionary and _previousPeriodValues but leaves _currentPeriodTime (line 34) holding the last period it processed. Enqueue (lines 165 and 176) only files a bar whose Time reaches that watermark, so after a reset every bar earlier than the old watermark is dropped without a warning and the indicator stays unready for the rest of the replay.

Measured over 60 daily periods across 3 symbols, comparing a reset-and-replayed instance against a fresh one: 162 of 180 updates differ in value and 171 of 180 differ in IsReady. Minute resolution behaves the same.

This also affects AdvanceDeclineDifference, AdvanceDeclineRatio, AdvanceDeclineVolumeRatio, McClellanOscillator and McClellanSummationIndex, which all build on it.

Potential Solution

Clear _currentPeriodTime in Reset() alongside the two dictionaries.

Reproducing the Problem

ComparesAgainstExternalDataAfterReset does not catch this. TestHelper.AssertIndicatorHasExternalDataAfterReset skips its assertion while the indicator is not ready, and on master the second pass of that test asserts 0 of 756 rows for all three A/D indicators — the reset leaves the indicator permanently unready, so every row is skipped and the test passes vacuously. With _currentPeriodTime cleared it asserts 753 of 756.

A direct test: feed the indicator a set of bars, call Reset(), feed the same bars again, and compare each Current.Value against a fresh instance fed the same bars once.

System Information

macOS, .NET 9, master at f0e339c.

Checklist

  • I have completely filled out this template
  • I have confirmed that this issue exists on the current master branch
  • I have confirmed that this is not a duplicate issue by searching issues
  • I have provided detailed steps to reproduce the issue

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions