1

In quantmod , when I using add_BBands() to add Bollinger Bands, it's show no Close column . But Close really in the dataframe . How to fix it ? Thanks!

library(quantmod)
library(TTR)
data(ttrc)
chartSeries(ttrc ,TA=c(add_BBands()))

The error message as below:

Error in Cl(xdata) : 
  subscript out of bounds: no column name containing "Close"
anderwyang
  • 1,801
  • 4
  • 18
  • 2
    I think this is typo, try without underscore: `chartSeries(ttrc ,TA = c(addBBands()))` – zx8754 Aug 03 '23 at 07:18
  • OK, looks like there is a function with an underscore, and it is used when the input is a timeseries, see: `?chart_Series`. And related post: https://stackoverflow.com/a/8504510/680068 – zx8754 Aug 03 '23 at 07:24

1 Answers1

1

As @zx8754 commented, this is a typo. You need to use addBBands() with chartSeries(). add_BBands() (the underscore version) is meant to be used with chart_Series().

BTW - great reproducible example!

Joshua Ulrich
  • 173,410
  • 32
  • 338
  • 418