Question

I am new to R and quantmod , thanks for any help. I want to change the colour of mace graph in quantmod.

library(quantmod)
getSymbols("AAPL")
chartSeries(AAPL)
addMACD()   # this works

But addMACD(col = c('red','blue', 'green', 'black') get the following errors.

addMACD(col = c('red','blue, yellow')) Error in ifelse((macd[, 1] - macd[, 2]) > 0, col[1], col[2]) : replacement has length zero In addition: Warning message: In rep(yes, length.out = length(ans)) : 'x' is NULL so the result will be NULL

and according the manual of quantmod, addMACD has the colour options.

Thx.

Was it helpful?

Solution

It seems that is a bug in the addMACD function.

If you look at its source code (e.g. with fix(addMACD)) you will see that it does:

col <- if (missing(col)) 
        col <- c("#999999", "#777777", "#BBBBBB", "#FF0000")

Hence, if you define col, the above lines assigns NULL to col.

If you change those lines to

if (missing(col)) 
        col <- c("#999999", "#777777", "#BBBBBB", "#FF0000") 

or just delete them altogether and specify a default value for col the function will work as expected.

You may want to have a look at this (and related discussions) on how to edit a function in R: What ways are there to edit a function in R?

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top