I am following up several stocks prices. Thanks to Vincent Zoonekynd (https://stackoverflow.com/users/1129973/vincent-zoonekynd), I was able to plot multiple charts in a page. Now, I want to add 20 ,and 200 days single moving average line to each chart but the chart is repeated. My code is
library(quantmod)
end <- Sys.Date()
start <- end - 365
stocks <- c("GOOG", "INTC", "AAPL")
stocksts <- list()
i <- 1
for(stock in stocks){
stocksts[[i]] <- getSymbols(stock
, src = "yahoo"
, from = start
, to = end
,auto.assign = FALSE
, return.class = "xts")
i <- i+1
}
par(mfcol=c(3,1), oma=c(1,1,0,0), mar=c(1,1,1,0), tcl=-0.1, mgp=c(0,0,0))
for (i in 1:length(stocksts)){
chartSeries(na.omit(scale(stocksts[[i]]))
,"candlesticks"
,name = names(df)
,TA = NULL
, layout = NULL
, yrange = c(-3,3)
)
addSMA(n = 20, col = "green")
addSMA(n = 200, col = "red")
}
Would you please advise how could I print candlestick and SMA charts avoiding repetition?