I use following code to create Donchian channels for daily charts:
lag(DonchianChannel(cbind(Hi(XXX), Lo(XXX))))
And add it to the plot using addTA
How can I add Donchian channels to weekly and monthly charts? (essentially where weeks and months are treated as days). Any advice would be appreciated.
Here's an example of a Donchian Channel for the weekly chart of MSFT shares:
library(quantmod)
library(TTR)
my_quote <- getSymbols("MSFT", auto.assign = FALSE)
my_quote_w <- to.weekly(my_quote)
dc <- lag(DonchianChannel(my_quote_w[,c("my_quote.High", "my_quote.Low")]))
candleChart(my_quote_w,col=TRUE,theme=chartTheme('white'),
subset='last 3 years', log.scale=TRUE, name="MSFT-weekly")
plot(addTA(dc$high, on=1, col='red'))
plot(addTA(dc$low, on=1, col='blue'))
Hope this helps.