When I try to display an indicator on weekly data using Quantmod's addTA function the indicator is invisible. Below is a toy example:
require(quantmod)
ticker <- c("^GSPC")
getSymbols("^GSPC", src = "yahoo", from = as.Date("1960-01-04"))
#change to weeklies
spy <- to.weekly(GSPC)
spyAD <- Ad(spy)
spyDVI <- DVI(spyAD)[,3]
chartSeries(GSPC,theme = chartTheme('white'), TA = NULL, subset = "1995-08::")
addTA(spyDVI)
Is there something that I'm doing wrong? It works perfectly on daily data, but not only weekly or monthly.
It works fine on weekly and monthly data if your chartSeries
call uses data of the same frequency. Your example plots daily data, then calls addTA
on weekly data.
For example:
chartSeries(spy, theme=chartTheme('white'), TA=NULL, subset="1995-08::")
addTA(spyDVI)
The lesson is that you have to be very careful if you call addTA
with different data than what is supplied to the original chartSeries
call.