更改 R quantmod TTR 制作的技术指标的线条颜色? [英] Change line colors of technical indicators made by R quantmod TTR?

查看:35
本文介绍了更改 R quantmod TTR 制作的技术指标的线条颜色?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I tried to plot with chartSeries in the R package quantmod, and add SMI lines using the addSMI() method. SMI generates two lines - the solid line is visible while the dotted line is not. Can anybody propose a way to change the color of the dotted line so that it is more noticeable? Here are the codes. I also attached an image generated.

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 图表中的两条线见下文.

See below for the two lines in the bottom SMI chart.

!

罗伯特的方法使它起作用.这是最新的代码和图表.

Edits: Robert's method made it work. Here is latest code and chart.

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)   

图表如下.

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

The question now is: the chart can be generated by running line by line. If I "source" the source codes in a batch mode, The SMI subchart does not show up at all. Any ideas?

推荐答案

试试这个:

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)

这篇关于更改 R quantmod TTR 制作的技术指标的线条颜色?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆