Closed yogat3ch closed 3 years ago
only the tr
value is used from the call to ATR
. the n
parameter is only used to calculate the average on the tr
and should not impact the value of raw tr
output column.
I think this has come up before. might we worth just adding a comment on this line in the code
@ethanbsmith Ah, I see, indeed the n
does not impact the tr
values.
Any ideas why the C code for ema
errors when there's just enough values for n
?
TTR::ATR(data.frame(h = rnorm(8), l = rnorm(8), c = rnorm(8)), n = 7)
Error in EMA(c(NA, 0.685597607387481, 0.409541520808519, 0.223128827893709, : not enough non-NA values
Any ideas why the C code for ema errors when there's just enough values for n?
Probably an off-by-one error in the NA check. I can investigate tomorrow.
Your question about ATR
is a duplicate of #75, so I closed this with the fix to EMA
(and ZLEMA
).
Hi @joshuaulrich, Hope this finds you well - I've happened across an error while running ADX as described in the title.
The reprex is simple:
This can be remedied by passing on the
n
value supplied toADX
toATR
instead of taking the default of14
. I feel like this would be expected behavior and the odd values I've been getting for the ADX for quite some time now might be explained by the fact that no matter then
value passed to ADX, theATR
values it uses are based on a window of14
periods.Here's the line 79.
Here's a pull request for the change.
I submitted it and seconds later realized I submitted it to master instead of a branch, but hopefully it's minor enough where that shouldn't matter.
Edit 2020-09-05T16:06:35: It looks like this introduces an error of the same nature at line 23 where the second call of
EMA
does not have sufficient data. I'm not sure how best to remedy this for non-standard values ofn
smaller than the default and achieve accurate values for the ADX as it seems like theC
code forema
might need to be adapted. Your expertise will be appreciated as to how best to go about this.Update 2020-09-05T16:22:01: It looks like changing the maType to
TTR::SMA
after making the modification to line 79 such thatn
is passed toATR
gives a result without error. This would suggest that the underlying implementation forema
might indeed need to be adjusted.Thanks for your time!
My sessionInfo jic: