Skip to content

MidPrice does not reset its rolling maximum and minimum #9693

Description

@mkzung

MidPrice holds a Maximum and a Minimum and never overrides Reset(), so both keep the previous run's window. The first bars after a reset are computed from data that is no longer in scope.

Steps to reproduce, four bars, period 3:

var mid = new MidPrice(3);
// High/Low: 110/100, 111/101, 112/102, 105/95
// first run:   105, 105.5, 106, 103.5
mid.Reset();
// after reset: 103.5, 103, 106, 103.5

Expected the second pass to repeat the first. The first period - 1 values are wrong, after which the stale window has rolled out: 1 value at period 2, 2 at period 3, 4 at period 5, 9 at period 10. MidPrice(5) is what MidPriceTests constructs.

Reset() does clear the public surface, Samples is 0, IsReady is false and Current.Value is 0, which is why TestHelper.AssertIndicatorIsInDefaultState passes. It recurses into public sub-indicator properties, and these two are private fields.

Behaviour outside a reset is unaffected. Feeding Tests/TestData/spy_midprice.txt matches all 496 expected MIDPRICE_5 values both before and after the fix.

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