Skip to content

SuperTrend.Reset leaves _previousClose set, which changes the output when period is 1 #9685

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

SuperTrend.Reset() does not clear _previousClose. ComputeNextValue assigns it on the early return it takes while the ATR warms up, so at ordinary periods the stale value is overwritten before it can be read. At period == 1 the ATR is ready on the first update, that early return never runs, and the trailing-band comparison reads the close carried over from before the reset.

Measured over 400 random series: 400 of 400 diverge at period 1 (2815 of 24000 samples). Period 2 and period 10 give 0 of 400.

Potential Solution

Set _previousClose = 0m in Reset().

Reproducing the Problem

Construct SuperTrend(1, ...), feed it bars, call Reset(), replay the same bars, and compare Current.Value against a fresh instance.

Related: BasicUpperBand, BasicLowerBand, CurrentTrailingUpperBand and CurrentTrailingLowerBand also survive Reset() holding values from the previous run. They never feed back into Current.Value, so they do not change the indicator's output, but a caller reading them after a reset sees stale numbers.

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

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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