Skip to content

Clear SuperTrend._previousClose on reset - #9688

Merged
Martin-Molinero merged 1 commit into
QuantConnect:masterfrom
mkzung:bug-9685-supertrend-reset-previous-close
Aug 12, 2026
Merged

Clear SuperTrend._previousClose on reset#9688
Martin-Molinero merged 1 commit into
QuantConnect:masterfrom
mkzung:bug-9685-supertrend-reset-previous-close

Conversation

@mkzung

@mkzung mkzung commented Aug 12, 2026

Copy link
Copy Markdown
Contributor

Description

SuperTrend.Reset() did not clear _previousClose.

Related Issue

Fixes #9685.

Motivation and Context

ComputeNextValue assigns _previousClose on the early return it takes while the ATR warms up, so at ordinary periods the stale value is overwritten before anything reads it. A period of one leaves the ATR ready on the first update, that early return never runs, and the trailing-band comparison reads the close carried over from before the reset.

Across 400 random series: 400 of 400 diverge at period 1, 2815 of 24000 samples. Period 2 and period 10 give 0 of 400, which is why this survived until the period was varied.

Requires Documentation Change

No.

How Has This Been Tested?

ResetsProperlyWithPeriodOne builds SuperTrend(1, ...), feeds it, resets, replays, and compares against a fresh instance. It fails on master and passes with the fix.

SuperTrendTests on a clean checkout of this branch: 13 passed. Full QuantConnect.Tests.Indicators with all three reset fixes applied: 2770 passed, 0 failed, 5 skipped.

Not changed here: BasicUpperBand, BasicLowerBand, CurrentTrailingUpperBand and CurrentTrailingLowerBand also survive Reset() holding values from the previous run. They never feed back into Current.Value, so the indicator's output is unaffected and clearing them is a wider change than this one line. Noted on the issue.

Types of changes

  • Bug fix (non-breaking change which fixes an issue)

Checklist:

  • My code follows the code style of this project.
  • I have read the CONTRIBUTING document.
  • I have added tests to cover my changes.
  • All new and existing tests passed.
  • My branch follows the naming convention bug-<issue#>-<description>

ComputeNextValue assigns _previousClose on the early return it takes
while the average true range warms up. A period of one leaves the average
true range ready on the first update, so that early return never runs and
the trailing band comparison reads the close carried over from before the
reset.
@Martin-Molinero
Martin-Molinero merged commit d2c3659 into QuantConnect:master Aug 12, 2026
7 of 8 checks passed

@Martin-Molinero Martin-Molinero left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @mkzung!

@mkzung mkzung mentioned this pull request Aug 13, 2026
11 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

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

2 participants