Color change color change function
First, I used the stoch function in the TTR package to calculate the slow stochastic and then added it to the chart from the chartSeries function using the addTA function, however these two lines in the chart are black and I would like to change them to a different color.
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)
I tried using:
lines(slow.stoc[2], col="red", lty="solid")
addLines(slow.stoc[2], col = "red")
But both don't work. Please advise. Thank.
+3
source to share
1 answer
Try the following:
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"))
Alternatively, which I would recommend, use advanced instead 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)
+5
source to share