Search code examples
rxtsquantmod

ChartSeries AddTA(OBV()) Error [TTR-Quantmod]


I have a ChartSeries error in my production code. Code Below

chartSeries(Stock, theme = chartTheme("white"), TA=c(addTA(ATR(Stock[,c("High","Low","Close")], n=14)), addTA(ADX(Stock[,c("High","Low","Close")])), addTA(OBV(Stock[,"Close"], Stock[,"Total.Trade.Quantity"])), addTA(chaikinAD(Stock[,c("High","Low","Close")], Stock[,"Total.Trade.Quantity"])), addTA(CMF(Stock[,c("High","Low","Close")], Stock[,"Total.Trade.Quantity"])), addRSI(), addSMI(), addMACD(type = "DEMA"), addBBands(), addDEMA(n = 20, on = 1, with.col = Cl, overlay = TRUE, col = "blue")), subset='last 4 months')

Error Code:

Error in seq.default(min(tav * 0.975, na.rm = TRUE), max(tav * 1.05, na.rm = TRUE), : 'from' must be a finite number In addition: Warning messages: 1: In min(tav * 0.975, na.rm = TRUE) : no non-missing arguments to min; returning Inf 2: In max(tav * 1.05, na.rm = TRUE) : no non-missing arguments to max; returning -Inf

Data file info:

So my data file, an xts styled OHLCV (csv), has 1 row of a total of 4718 rows with 3 NA values (on the first row of the file). The rest of the rows are completely filled with no other NA values.

Edit:

Just omitted the row containing NA values, and still get the same error. So the error has to do something with something else.

Edit 2:

So I found that the error is localized to the addTA(OBV(Stock[,"Close"], Stock[,"Total.Trade.Quantity"])) function/arguments. Any suggestions or tips?


Solution

  • This code resolves your problem:

    Stock <- AAPL["2018-08"]
    chartSeries(Stock, theme="white")
    addTA(OBV(Cl(Stock), Vo(Stock)))
    

    Stock prices chart with OBV added