Hi! I've found some strange code in DonchianChannel indicator.
protected override decimal ComputeNextValue(IBaseDataBar input)
{
if (_previousInput != null)
{
UpperBand.Update(_previousInput.Time, _previousInput.High);
LowerBand.Update(_previousInput.Time, _previousInput.Low);
}
_previousInput = input;
return (UpperBand.Current.Value + LowerBand.Current.Value) / 2;
}
In “ComputeNextValue(IBaseDataBar input)” method we can see that “UpperBand” Maximum and “LowerBand” Minimum indicators are updated from the previous input. Does it means that indicator value is not actual and off by one DataBar? Is this a bug, or I misunderstood this part of code?
Fred Painchaud
Hi Sava,
Yeah it also looks strange to me. You have:
So the warmup period is +1 over the period but even, the data that is being averaged is one bar behind…
I may be missing something but I believe this is a bug - I can't see why one would want to use _previousInput and all…
You might want to report it to support@quantconnect.com and report back here.
Fred
Alexandre Catarino
Hi Sava Lifanov,
Thank you for the report.
QuantConnect/Lean indicators are tested against third-party software so we are very confident that the formulas are right. Here is one source that explains why the calculation of the maximum and minimum doesn't consider the current bar:
Donchian Channel Formula
Best regards,
Alex
Fred Painchaud
Oh yes indeed Alex!
Totally forgot that Donchian was a comparative indicator (comparing the current state with a “measure of a number of past states”).
I've actually seen many comparative indicators elsewhere where the current state was compared to the previous few, but the previous few actually included the current so then, the comparison is not as correct.
Thanks. It's now engraved I guess 😊
Fred
Sava Lifanov
The material on this website is provided for informational purposes only and does not constitute an offer to sell, a solicitation to buy, or a recommendation or endorsement for any security or strategy, nor does it constitute an offer to provide investment advisory services by QuantConnect. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. QuantConnect makes no guarantees as to the accuracy or completeness of the views expressed in the website. The views are subject to change, and may have become unreliable for various reasons, including changes in market conditions or economic circumstances. All investments involve risk, including loss of principal. You should consult with an investment professional before making any investment decisions.
To unlock posting to the community forums please complete at least 30% of Boot Camp.
You can continue your Boot Camp training progress from the terminal. We hope to see you in the community soon!