gpt4 book ai didi

R quantmod addTA函数改变颜色

转载 作者:行者123 更新时间:2023-12-02 03:53:42 26 4
gpt4 key购买 nike

首先,我使用 TTR 包中的 stoch 函数来计算慢随机,然后使用 addTA 函数将其添加到 chartSeries 函数的绘图中,但是,绘图中的这两行是黑色的,我想更改它们变成不同的颜色。

Input:

chartSeries(df, subset='last 3 years', TA = NULL, theme = "white", up.col = "green", dn.col = "red")

slow.stoc <- stoch(na.omit(HLC(df)), 25, 25, 9, 'SMA')[,2:3]

addTA(slow.stoc)

我尝试使用:

 lines(slow.stoc[2], col="red", lty="solid")

addLines(slow.stoc[2], col = "red")

但是两者都不起作用。请指教。谢谢。

最佳答案

试试这个:

   chartSeries(df, subset='last 3 years', TA = NULL, theme = "white", up.col = "green", dn.col = "red")
slow.stoc <- stoch(na.omit(HLC(df)), 25, 25, 9, 'SMA')[,2:3]
addTA(slow.stoc, col = c("red", "green"))

或者,我建议使用增强的 chart_Series:

library(quantmod)

# optional, set up bar colours as in your question, for chart_Series:
getSymbols("GOOG")
myTheme<-chart_theme()
myTheme$col$up.col<-'darkgreen'
myTheme$col$dn.col<-'darkred'
myTheme$col$dn.border <- 'black'
myTheme$col$up.border <- 'black'
myTheme$rylab <- FALSE
myTheme$col$grid <- "lightgrey"

# get your desired result
df <- GOOG
slow.stoc <- stoch(na.omit(HLC(df)), 25, 25, 9, 'SMA')[,2:3]
chart_Series(df, subset='2017', theme = myTheme)
add_TA(slow.stoc["2017", 1], col = "purple", lty = "dashed")
add_TA(slow.stoc["2017", 2], col = "red", lty = 3, on = 2)

enter image description here

关于R quantmod addTA函数改变颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44732183/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com