Skip to content

McClellanOscillator adds two warm-up periods that share a bar #9711

Description

@mkzung

Expected Behavior

WarmUpPeriod is the number of data points an indicator needs before IsReady turns true.

Actual Behavior

McClellanOscillator reports 41 and is ready on bar 40. McClellanSummationIndex delegates
WarmUpPeriod to it and reports the same.

WarmUpPeriod => EMASlow.WarmUpPeriod + ADDifference.WarmUpPeriod   // 39 + 2 = 41
IsReady      => EMASlow.IsReady

EMASlow is ADDifference.EMA(slowPeriod), and IndicatorExtensions.EMA passes
waitForFirstToReady = true, so EMASlow receives its first input on the bar ADDifference
becomes ready rather than the bar after it. The two periods share that bar, and adding them
counts it twice.

Potential Solution

EMASlow.WarmUpPeriod + ADDifference.WarmUpPeriod - 1. That changes no value the indicator
reports: at 40 bars the oscillator is 0 and the summation index is 60, the same as at 41, and
Samples is WarmUpPeriod * 3 either way.

Reproducing the Problem

var indicator = new McClellanOscillator(19, 39);
indicator.Add(Symbols.AAPL);
indicator.Add(Symbols.MSFT);
indicator.Add(Symbols.GOOG);

var reference = DateTime.Today;
for (var i = 1; i <= indicator.WarmUpPeriod - 1; i++)
{
    indicator.Update(new TradeBar { Symbol = Symbols.AAPL, Close = i, Volume = 1, Time = reference.AddMinutes(i) });
    indicator.Update(new TradeBar { Symbol = Symbols.MSFT, Close = i, Volume = 1, Time = reference.AddMinutes(i) });
    indicator.Update(new TradeBar { Symbol = Symbols.GOOG, Close = i, Volume = 1, Time = reference.AddMinutes(i) });
}
Console.WriteLine(indicator.IsReady);  // True, one bar before WarmUpPeriod

Both fixtures override WarmsUpProperly and assert IsTrue(IsReady) after WarmUpPeriod
bars without asserting it was false before, so being ready early passes.

System Information

master at d865a40.

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