Description
When explicitly passing colors to addMACD an error occurs (see examples below).
After a bit of research I think the issue is with the vectorized function "ifelse" which evaluates the difference between the MACD line and the signal line.
cols <- ifelse((macd[,1]-macd[,2]) > 0, col[1],col[2])
What is not clear to me is why, if I specify histogram = F no lines are generated either
Expected behavior
I should be able to specify custom colors (or other parameters) without affecting the function
Minimal, reproducible example
This
MACD = addMACD(col = c("#FF0000", "#008000", "#BBBBBB","#FF0000"))
plot(MACD)
or this
MACD = addMACD(histogram = T, col = c("#FF0000", "#008000", "#BBBBBB","#FF0000"))
plot(MACD)
cause the following
Error in ans[ypos] <- rep(yes, length.out = len)[ypos] :
replacement has length zero
In addition: Warning message:
In rep(yes, length.out = len) : 'x' is NULL so the result will be NULL
However when using
MACD = addMACD(histogram = F, col = c("#FF0000", "#008000", "#BBBBBB","#FF0000"))
plot(MACD)
No error is generated. But also no lines in the chart
Session Info
R version 4.0.2 (2020-06-22)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Ubuntu 18.04.5 LTS
Matrix products: default
BLAS: /usr/lib/x86_64-linux-gnu/openblas/libblas.so.3
LAPACK: /usr/lib/x86_64-linux-gnu/libopenblasp-r0.2.20.so
locale:
[1] LC_CTYPE=C.UTF-8 LC_NUMERIC=C LC_TIME=C.UTF-8 LC_COLLATE=C.UTF-8 LC_MONETARY=C.UTF-8
[6] LC_MESSAGES=C.UTF-8 LC_PAPER=C.UTF-8 LC_NAME=C LC_ADDRESS=C LC_TELEPHONE=C
[11] LC_MEASUREMENT=C.UTF-8 LC_IDENTIFICATION=C
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] rmarkdown_2.3 googledrive_1.0.1 RobinHood_1.4 base64enc_0.1-3 httr_1.4.2
[6] forecast_8.13 BatchGetSymbols_2.6.1 dplyr_1.0.1 rvest_0.3.6 xml2_1.3.2
[11] curl_4.3 jsonlite_1.7.0 stringi_1.4.6 quantmod_0.4.18 TTR_0.24.2
[16] xts_0.12-0 zoo_1.8-8 pacman_0.5.1
loaded via a namespace (and not attached):
[1] tidyselect_1.1.0 xfun_0.16 listenv_0.8.0 purrr_0.3.4 urca_1.3-0 lattice_0.20-41
[7] colorspace_1.4-1 vctrs_0.3.2 generics_0.0.2 htmltools_0.5.0 utf8_1.1.4 rlang_0.4.7
[13] pillar_1.4.6 glue_1.4.1 lifecycle_0.2.0 timeDate_3043.102 munsell_0.5.0 gtable_0.3.0
[19] future_1.21.0 codetools_0.2-16 evaluate_0.14 knitr_1.29 tseries_0.10-48 lmtest_0.9-38
[25] parallel_4.0.2 fansi_0.4.1 Rcpp_1.0.5 scales_1.1.1 parallelly_1.22.0 fracdiff_1.5-1
[31] ggplot2_3.3.2 digest_0.6.25 grid_4.0.2 cli_2.0.2 quadprog_1.5-8 tools_4.0.2
[37] magrittr_1.5 tibble_3.0.3 crayon_1.3.4 pkgconfig_2.0.3 ellipsis_0.3.1 lubridate_1.7.9
[43] assertthat_0.2.1 rstudioapi_0.11 R6_2.4.1 globals_0.14.0 nnet_7.3-14 nlme_3.1-147
[49] compiler_4.0.2
Description
When explicitly passing colors to addMACD an error occurs (see examples below).
After a bit of research I think the issue is with the vectorized function "ifelse" which evaluates the difference between the MACD line and the signal line.
cols <- ifelse((macd[,1]-macd[,2]) > 0, col[1],col[2])What is not clear to me is why, if I specify
histogram = Fno lines are generated eitherExpected behavior
I should be able to specify custom colors (or other parameters) without affecting the function
Minimal, reproducible example
This
or this
cause the following
However when using
No error is generated. But also no lines in the chart
Session Info