更改R quantmod TTR制作的技术指标的线条颜色?

时间:2015-05-21 18:29:13

标签: r quantmod

我尝试在R package quantmod中使用chartSeries绘图,并使用addSMI()方法添加SMI行。 SMI生成两条线 - 实线可见而虚线不可见。任何人都可以提出一种方法来改变虚线的颜色,使其更加引人注目吗?这是代码。我还附上了生成的图像。

library(quantmod)

x<-getSymbols("IBM", src='yahoo', from="2014-11-20", to="2015-05-20", auto.assign=FALSE)
chartSeries(x, name=paste(stockFirmName,"(",stock,")"), line.type = "l", 
        TA=c(addSMI()), theme = chartTheme("white", up.col='red',dn.col="blue"), major.ticks="months", color.vol=FALSE, multi.col = FALSE) 

title(main="", cex.main=2.5, font.main=4, col.main="gold", 
      sub="", cex.sub=1.5, font.sub=4, col.sub="blue", 
      xlab="", ylab="",col.lab="blue", cex.lab=1)   

请参阅下面的底部SMI图表中的两行。

enter image description here

编辑:罗伯特的方法让它发挥作用。这是最新的代码和图表。

library(quantmod)

x<-getSymbols("IBM", src='yahoo', from="2014-11-20", to="2015-05-20", auto.assign=FALSE)
chartSeries(x, name=paste("IBM"), line.type = "l", 
        TA=NULL, 
        theme = chartTheme("white", up.col='red',dn.col="blue"), 
              major.ticks="months", color.vol=FALSE, multi.col = FALSE) 

addTA(SMI(HLC(x)),col=2:3)

title(main="", cex.main=2.5, font.main=4, col.main="gold", 
  sub="", cex.sub=1.5, font.sub=4, col.sub="blue", 
  xlab="", ylab="",col.lab="blue", cex.lab=1)   

图表如下。 enter image description here

现在的问题是:可以通过逐行运行生成图表。如果我&#34;来源&#34;如果源代码处于批处理模式,则SMI子图表根本不会显示。有什么想法吗?

1 个答案:

答案 0 :(得分:1)

试试这个:

chartSeries(x, name=paste(stockFirmName,"(",stock,")"), line.type = "l", 
            TA=NULL, theme = chartTheme("white", up.col='green',dn.col='red'), major.ticks="months", color.vol=FALSE) 

addTA(SMI(HLC(x)),col=2:3)