如何使用 quantmode 将简单移动平均线添加到多个烛台图表
How to add simple moving average to multiple candlestick charts using quantmode
我正在跟进几只股票的价格。感谢 Vincent Zoonekynd (https://whosebug.com/users/1129973/vincent-zoonekynd),我能够在一个页面中绘制多个图表。
现在,我想向每个图表添加 20 和 200 天的单条移动平均线,但图表会重复。
我的密码是
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")
}
请问我如何打印烛条和 SMA 图表避免重复?
鉴于您设置的框架,我认为这就是您要找的东西,
我建议您查看 ,这可能会帮助您改进设置...
1: 设置
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
}
2: 添加SMA并同时绘制数据的新方法
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)){
price=Cl(stocksts[[i]])
newSMA <- newTA(SMA, Cl, on=NA)
print(chart_Series(price, TA = 'add_TA(SMA(price, 20), on = 1, col = "green"); add_TA(SMA(price, 200), on = 1, col = "red")', yrange = c(-3,3)))
}
我正在跟进几只股票的价格。感谢 Vincent Zoonekynd (https://whosebug.com/users/1129973/vincent-zoonekynd),我能够在一个页面中绘制多个图表。 现在,我想向每个图表添加 20 和 200 天的单条移动平均线,但图表会重复。 我的密码是
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")
}
请问我如何打印烛条和 SMA 图表避免重复?
鉴于您设置的框架,我认为这就是您要找的东西,
我建议您查看
1: 设置
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
}
2: 添加SMA并同时绘制数据的新方法
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)){
price=Cl(stocksts[[i]])
newSMA <- newTA(SMA, Cl, on=NA)
print(chart_Series(price, TA = 'add_TA(SMA(price, 20), on = 1, col = "green"); add_TA(SMA(price, 200), on = 1, col = "red")', yrange = c(-3,3)))
}