0

I'm a bit puzzled. I have a created a custom function:

doGraph <- function(x){
dev.new();
symb <- getSymbols(x, auto.assign = FALSE);
chartSeries(symb, subset = 'last 3 months', name=x);
addBBands();
addMACD();
}
doGraph("AAPL")

The above code does not add the Bollinger Bands, as I would expect (by the addBBands() call). However, if I remove the addMACD() call, the bands are added as expected. Additionally, if I type addBBands() after the function call, the bands are added. Does anyone have any thoughts on what could be going wrong here? Thanks!

0

1 Answer 1

1

Wrap plot around your add* calls

doGraph <- function(x){
  dev.new()
  symb <- getSymbols(x, auto.assign = FALSE)
  chartSeries(symb, subset = 'last 3 months', name=x)
  plot(addBBands())
  plot(addMACD())
}
doGraph("AAPL")
4
  • Or, better yet, put them in the chartSeries call: chartSeries(symb, subset='last 3 months', name=x, TA="addBBands();addMACD()"). Aug 20, 2013 at 18:47
  • Thanks Guys -- both solutions work. However, I'd like to understand why this happens? If I put both calls in the function, addBBands() gets skipped. However, if I call addBBands() afterwards, it appears with no issues. Is there an underlying restriction that I'm missing here? Any input appreciated! Aug 20, 2013 at 19:36
  • 1
    @MarkCukier did you click the links in my comment on my answer to the duplicate post?
    – GSee
    Aug 20, 2013 at 19:43
  • @GSee -- no, I didn't even notice that there was a comment on the original question. I'm now reading R-SIG-Finance history... thanks for the links! Aug 20, 2013 at 19:50

Not the answer you're looking for? Browse other questions tagged or ask your own question.