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

HMA - Odd numbers are not working #76

Closed dragie closed 3 years ago

dragie commented 5 years ago

hma <- function(data, n){ hmaout <- HMA(data, n ) }

when I call this function with n <- 3,5,7,9,11,etc it is not working, but it is working fine for even numbers like 2,4,6,8,10,etc

joshuaulrich commented 3 years ago

Here's a reproducible example:

R> HMA(1:10, 2)
 [1]        NA        NA  3.333333  4.333333  5.333333  6.333333  7.333333
 [8]  8.333333  9.333333 10.333333
R> HMA(1:10, 3)
Error in WMA(x, n = n/2, ...) : 
  Length of 'wts' must equal the length of 'x' or 'n'

We need to truncate the value for n in the first WMA() call: WMA(x, n = trunc(n/2), ...)