Hi All!
Thank you for taking the time to read this. It's a question regarding what seems to be a minor implementation difference between the TrueRange indicator and the AverageTrueRange indicator when calculating the inital True Range value of a time series.
The former will set the first value to 0.0 if there is no previous bar. The latter will set the first value to High-Low of the current bar if there is no previous bar.
TrueRange.cs [line 66]:
protected override decimal ComputeNextValue(IBaseDataBar input)
{
if (!IsReady)
{
_previousInput = input;
return 0m;
}
vs AverTruerange.cs [line 103]:
public static decimal ComputeTrueRange(IBaseDataBar previous, IBaseDataBar current)
{
var range1 = current.High - current.Low;
if (previous == null)
{
return range1;
}
The differences are minor in resulting values, however, there exist edge cases where one versus the other will generate different resulting actions. Of course, this is noise, and no trading system should be that sensitive.
The challenge is that it makes debugging / replicating results in Excel, external frameworks, etc. a bit of a challenge.
Does it make sense to make the two indicators produce the same values? If so, I'm assuming I can generate a pull request for TrueRange.cs?
Thank you,
Corvin
Corvin Codirla
PS
The initial value is set to 0 in the AverageDirectionalIndex.cs as well [line 176]:
Fred Painchaud
Hi Corvin,
Yeah, totally see what you point out.
However, of note, TrueRange takes 2 bars to be ready:
public override bool IsReady => Samples > 1;
And AverageTrueRange uses another way of calculating TrueRange, not the TrueRange class:
So see? It starts with High-Low.
With TrueRange, you should not use the data if it is not ready… Well you should never use data from an indicator which is not ready.
Fred
Corvin Codirla
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!