joshuaulrich / TTR

Technical analysis and other functions to construct technical trading rules with R
GNU General Public License v2.0
326 stars 102 forks source link

Why is ATR period fixed to 14 in ADX? #75

Closed SteveBronder closed 1 year ago

SteveBronder commented 5 years ago

Here

https://github.com/joshuaulrich/TTR/blob/master/R/ADX.R#L80

...
  DMIn <- ifelse( dH==dL | (dH< 0 & dL< 0), 0, ifelse( dH <dL, dL, 0 ) )
## HERE
  TR    <- ATR(HLC)[,"tr"]
  TRsum <- wilderSum(TR, n=n)

  DIp <- 100 * wilderSum(DMIp, n=n) / TRsum
...

And pretty much for all of the other functions. Could the n (and whatever else) be passed in with ...?

joshuaulrich commented 1 year ago

n = 14 is the traditional value used for ATR, and therefore is what's used in ADX. I'm not sure whether it makes sense to set ATR(hlc, n = n) or give ADX a new nTrueRange argument. Thoughts?

ethanbsmith commented 1 year ago

think this has come up before. ADX only uses the tr column from the ATR call, so the n doesn't matter. might be worth adding a comment to the source and using n = 1. can also be cleaned up w/ #114

joshuaulrich commented 1 year ago

I've been cleaning up old issues and I just noticed this is a duplicate of #18. There's more dialogue in that issue, so let's keep any new discussion over there.