joshuaulrich / TTR

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

RSI result differs if leaving out maType compared to add maType="EMA" #82

Closed toolbox1972 closed 5 years ago

toolbox1972 commented 5 years ago

Description

RSI indicator, below combination gives different RSI results: [n = 14, wilder = FALSE] [n = 14, maType="EMA", wilder = FALSE]

Expected behavior

Expect that [maType="EMA"] should be default, if not adding [maType]. The below lines should return the same RSI result.

Minimal, reproducible example

rsi_result_no_wilder_but_maType_defined <- RSI(price, n = 14, maType= "EMA", wilder = FALSE)

rsi_result_no_wilder_but_maType_not_defined <- RSI(price, n = 14, wilder = FALSE)


Results (no_wilder, maType defined):
2019-07-16 16:21:00 74.28571
2019-07-16 16:22:00 79.20711
2019-07-16 16:23:00 84.38090
2019-07-16 16:24:00 84.38090
2019-07-16 16:25:00 63.38348
2019-07-16 16:26:00 69.26639
2019-07-16 16:26:00 63.39070
2019-07-16 16:27:00 53.01310
2019-07-16 16:28:00 53.01310
2019-07-16 16:29:00 61.42149
2019-07-16 16:30:00 58.29205

Results (no_wilder, maType not defined):
2019-07-16 16:21:00 74.28571
2019-07-16 16:22:00 77.00680
2019-07-16 16:23:00 80.36347
2019-07-16 16:24:00 80.36347
2019-07-16 16:25:00 68.72735
2019-07-16 16:26:00 71.67215
2019-07-16 16:26:00 68.21343
2019-07-16 16:27:00 61.79091
2019-07-16 16:28:00 61.79091
2019-07-16 16:29:00 65.55243
2019-07-16 16:30:00 63.79396

Session Info

> sessionInfo()
R version 3.6.1 (2019-07-05)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Ubuntu 18.04.2 LTS

Matrix products: default
BLAS:   /usr/lib/x86_64-linux-gnu/blas/libblas.so.3.7.1
LAPACK: /usr/lib/x86_64-linux-gnu/lapack/liblapack.so.3.7.1

locale:
 [1] LC_CTYPE=en_US.UTF-8       LC_NUMERIC=C               LC_TIME=sv_SE.UTF-8        LC_COLLATE=en_US.UTF-8     LC_MONETARY=sv_SE.UTF-8    LC_MESSAGES=en_US.UTF-8   
 [7] LC_PAPER=sv_SE.UTF-8       LC_NAME=C                  LC_ADDRESS=C               LC_TELEPHONE=C             LC_MEASUREMENT=sv_SE.UTF-8 LC_IDENTIFICATION=C       

attached base packages:
[1] graphics  grDevices utils     datasets  stats     methods   base     

other attached packages:
[1] TTR_0.23-4   xts_0.11-2   zoo_1.8-5    R6_2.4.0     jsonlite_1.6 httr_1.4.0  

loaded via a namespace (and not attached):
[1] compiler_3.6.1  tools_3.6.1     curl_3.3        grid_3.6.1      lattice_0.20-38
joshuaulrich commented 5 years ago

Thanks for the report! I can confirm this behavior, and agree that it's a bug. I will fix.

joshuaulrich commented 5 years ago

Note that this would also happen with ADX and ATR.