[R-SIG-Finance] Empty indicator / plot.window: need finite 'ylim' values

Mike m|ke9 @end|ng |rom po@teo@n|
Mon Aug 17 22:42:56 CEST 2020


> > On 17 Aug 2020, at 04:55, Rasmus Liland <jral using posteo.no> wrote:

> >     plot(chart_Series(sample.xts[subset,1], TA=ta))
> > 
> > A plot appears.  No errors.

For now. But when you add an indicator like add_BBands() which is
calculated within chart_Series, this indicator will start at
observation 20, not from the beginning. This is because you call
chart_Series without lead time for calculation.


On 17.08. Daniel Cegiełka wrote:

> chart_Series() is a plot env/func, so plot(chart_Series()) make no sense :)

Like Joshua wrote, indeed, I use chart_Series within a function.

> But your problem is here:
> 
> sample.xts[subset, 2]

Yes, not the main window is the issue, but the indicator is. So I
have to ask more specific:

Can I plot a subset of chart and indicator where the indicator's
subset is completely NA resulting in the indicator's plot region
being left blank?

Mike


The new minimal reproducible:

library(quantmod)

my_plot_function <- function () {
  data (sample_matrix)
  sample.xts <- as.xts (sample_matrix[1:50,'Close'], dateFormat="POSIXct")
  sample.xts <- cbind (sample.xts, NA)
  sample.xts[50,2] <- 0
  colnames (sample.xts) <- c('Close', 'Stops')

  ta <- list ("add_TA(sample.xts[,2])")

  # In the range to be plotted ta is completely NA 
  subset <- '2007-01-10::2007-01-30'

  plot (chart_Series (sample.xts[,1], subset=subset, TA=ta))
}

my_plot_function ()



More information about the R-SIG-Finance mailing list