chart_Series: Adding multiple custom indicators
On Wed, Jul 5, 2023 at 3:11?PM Mike <mike9 at posteo.nl> wrote:
Some time ago I wrote an R script where I added custom indicators to a main chart by putting them into a list like this: CODE: data (sample_matrix, package="xts") data <- as.xts (sample_matrix) ta <- list () ta[[1]] <- "add_TA (SMA (data$Close, 20), col='#BB0000')" ta[[2]] <- "add_TA (SMA (data$Close, 3), col='#00BB00')" co <- chart_Series (data, name='test data', TA=ta) plot (co)
Thanks for the reproducible example!
After some updates, and now running
packageVersion('quantmod')
[1] '0.4.23' I started the code again and got this: Error in !is.null(TA) && nchar(TA) > 0 : 'length = 2' in coercion to 'logical(1)' I don't get the error when I add one indicator only. On an older machine running quantmod 0.4.20 I get this message as a warning instead of an error. What causes the error and what is the best practice to plot a chart (using the new chart_Series) with multiple custom indicators?
That chart_Series() code didn't change between those 2 versions of
quantmod. This went from a warning to an error based on changes in R
itself. You can verify by running the code below on both machines:
ta <- list("a", "b")
!is.null(ta) && nchar(ta) > 0
## Error in !is.null(ta) && nchar(ta) > 0 :
## 'length = 2' in coercion to 'logical(1)'
The chart_Series() docs say that the TA arg should be "a character
string of semi-colon seperated TA calls". So you can do this:
chart_Series(data, name = "test data", TA = paste(ta, collapse = ";"))
Best,
Josh
Mike
_______________________________________________ R-SIG-Finance at r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-sig-finance -- Subscriber-posting only. If you want to post, subscribe first. -- Also note that this is not the r-help list where general R questions should go.
Joshua Ulrich | about.me/joshuaulrich FOSS Trading | www.fosstrading.com