Skip to content

Commit

Permalink
Fix addMACD() when user specifies 'col' argument
Browse files Browse the repository at this point in the history
Calling addMACD(col = ...) would throw the error below.

  R$ chartSeries(x)
  R$ addMACD(col = c("#FF0000", "#008000", "#BBBBBB","#FF0000"))
  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

'col' was being set to NULL if it wasn't missing because there was no
'else' in the ternary-style if statement.

Thanks to @nvalueanalytics for the report.

Fixes #321.
  • Loading branch information
joshuaulrich committed Jan 2, 2021
1 parent 6b3c44e commit ff1f990
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
6 changes: 6 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
### Changes in 0.4-18.1 (2021-mm-dd)

1. Fix `addMACD()` when `col` is specified. Thanks to @nvalueanalytics for the
report!
[#321](https://github.com/joshuaulrich/quantmod/issues/321)

### Changes in 0.4-18 (2020-11-29)

1. Fix issues handling https:// in `getSymbols.yahooj()`. Thanks to @lobo1981
Expand Down
5 changes: 3 additions & 2 deletions R/addTA.R
Original file line number Diff line number Diff line change
Expand Up @@ -947,8 +947,9 @@ function(x) {
chobTA <- new("chobTA")
chobTA@new <- TRUE

col <- if(missing(col)) col <- c('#999999','#777777',
'#BBBBBB','#FF0000')
if(missing(col)) {
col <- c('#999999','#777777', '#BBBBBB','#FF0000')
}

xx <- if(is.OHLC(x)) {
Cl(x)
Expand Down

0 comments on commit ff1f990

Please sign in to comment.