Skip to content

Commit e9199a1

Browse files
committed
Allow custom settings to TA's color
Pass color settings to addTA functions except for addSAR, addMACD, addShading, addLines, addPoints and add*MA functions that have their own 'col' argument. Users can call chartTheme(addTA = list(...)) colors and pass chart.theme object to chartSeries to manage desired chart colors.
1 parent 435e7a3 commit e9199a1

File tree

14 files changed

+142
-80
lines changed

14 files changed

+142
-80
lines changed

R/addAroon.R

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@ function (n = 20, ..., on = NA, legend = "auto")
2020
ylim <- c(0,100)
2121
theme <- x$Env$theme
2222

23-
lines(x.pos, Aroon[,1], col = theme$aroon$col$aroonUp,
23+
lines(x.pos, Aroon[,1], col = theme$Aroon$col$aroonUp,
2424
lwd = 1, lend = 2, ...)
25-
lines(x.pos, Aroon[,2], col = theme$aroon$col$aroonDn,
25+
lines(x.pos, Aroon[,2], col = theme$Aroon$col$aroonDn,
2626
lwd = 1, lend = 2, ...)
2727
}
2828
if(!is.character(legend) || legend == "auto")
@@ -39,7 +39,7 @@ function (n = 20, ..., on = NA, legend = "auto")
3939
legend = c(paste(legend, ":"),
4040
paste("aroonUp :",format(last(Aroon[xsubset,1]),nsmall = 3L)),
4141
paste("aroonDn :",format(last(Aroon[xsubset,2]),nsmall = 3L))),
42-
text.col = c(theme$fg, theme$aroon$col$aroonUp, theme$aroon$col$aroonDn),
42+
text.col = c(theme$fg, theme$Aroon$col$aroonUp, theme$Aroon$col$aroonDn),
4343
xjust = lc$xjust,
4444
yjust = lc$yjust,
4545
bty = "n",
@@ -61,9 +61,10 @@ function (n = 20, ..., on = NA, legend = "auto")
6161
lchob <- current.chob()
6262
ncalls <- length(lchob$Env$call_list)
6363
lchob$Env$call_list[[ncalls + 1]] <- match.call()
64-
if (is.null(lchob$Env$theme$aroon$col$arronUp)) {
65-
lchob$Env$theme$aroon$col$aroonUp <- 3
66-
lchob$Env$theme$aroon$col$aroonDn <- 4
64+
if (is.null(lchob$Env$theme$Aroon)) {
65+
lchob$Env$theme$Aroon$col$aroonUp <- 3
66+
lchob$Env$theme$Aroon$col$aroonDn <- 4
67+
lchob$Env$theme$Aroon$col$aroonOsc <- 3
6768
}
6869
xdata <- lchob$Env$xdata
6970
xdata <- cbind(Hi(xdata),Lo(xdata))
@@ -97,7 +98,7 @@ function (n = 20, ..., on = NA, legend = "auto")
9798
ylim <- range(AroonOsc,na.rm=TRUE)
9899
theme <- x$Env$theme
99100

100-
lines(x.pos, AroonOsc, col = theme$aroon$col$aroonOsc,
101+
lines(x.pos, AroonOsc, col = theme$Aroon$col$aroonOsc,
101102
lwd = 1, lend = 2, ...)
102103
}
103104
if(!is.character(legend) || legend == "auto")
@@ -135,8 +136,10 @@ function (n = 20, ..., on = NA, legend = "auto")
135136
lchob <- current.chob()
136137
ncalls <- length(lchob$Env$call_list)
137138
lchob$Env$call_list[[ncalls + 1]] <- match.call()
138-
if (is.null(lchob$Env$theme$aroon$col$aroonOsc)) {
139-
lchob$Env$theme$aroon$col$aroonOsc <- 3
139+
if (is.null(lchob$Env$theme$Aroon)) {
140+
lchob$Env$theme$Aroon$col$aroonUp <- 3
141+
lchob$Env$theme$Aroon$col$aroonDn <- 4
142+
lchob$Env$theme$Aroon$col$aroonOsc <- 3
140143
}
141144
xdata <- lchob$Env$xdata
142145
xdata <- cbind(Hi(xdata),Lo(xdata))

R/addCLV.R

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ function (..., on = NA, legend = "auto")
1818
ylim <- range(clv,na.rm=TRUE)
1919
theme <- x$Env$theme
2020

21-
lines(x.pos, clv, type = "h", col = theme$clv$col,
21+
lines(x.pos, clv, type = "h", col = theme$CLV$col,
2222
lwd = 1, lend = 2, ...)
2323
}
2424
if(!is.character(legend) || legend == "auto")
@@ -34,7 +34,7 @@ function (..., on = NA, legend = "auto")
3434
legend(x = lc$x, y = lc$y,
3535
legend = c(paste(legend, ":"),
3636
paste(format(last(clv[xsubset]),nsmall = 3L))),
37-
text.col = c(theme$fg, 5),
37+
text.col = c(theme$fg, theme$CLV$col),
3838
xjust = lc$xjust,
3939
yjust = lc$yjust,
4040
bty = "n",
@@ -56,8 +56,8 @@ function (..., on = NA, legend = "auto")
5656
lchob <- current.chob()
5757
ncalls <- length(lchob$Env$call_list)
5858
lchob$Env$call_list[[ncalls + 1]] <- match.call()
59-
if (is.null(lchob$Env$theme$clv$col)) {
60-
lchob$Env$theme$clv$col <- 5
59+
if (is.null(lchob$Env$theme$CLV)) {
60+
lchob$Env$theme$CLV$col <- 5
6161
}
6262
xdata <- lchob$Env$xdata
6363
xsubset <- lchob$Env$xsubset

R/addCMO.R

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
max(abs(cmo), na.rm = TRUE))*1.05
2323
theme <- x$Env$theme
2424

25-
lines(x.pos, cmo, col = "#0033CC", lwd = 1, lend = 2)
25+
lines(x.pos, cmo, col = theme$CMO$col, lwd = 1, lend = 2)
2626
}
2727
mapply(function(name, value) {
2828
assign(name, value, envir = lenv)
@@ -34,7 +34,7 @@
3434
legend(x = lc$x, y = lc$y,
3535
legend = c(paste(legend, ":"),
3636
paste(sprintf("%.3f",last(cmo[xsubset])), sep = "")),
37-
text.col = c(theme$fg, "#0033CC"),
37+
text.col = c(theme$fg, theme$CMO$col),
3838
xjust = lc$xjust,
3939
yjust = lc$yjust,
4040
bty = "n",
@@ -57,6 +57,9 @@
5757
lchob <- current.chob()
5858
ncalls <- length(lchob$Env$call_list)
5959
lchob$Env$call_list[[ncalls + 1]] <- match.call()
60+
if (is.null(lchob$Env$theme$CMO)) {
61+
lchob$Env$theme$CMO$col <- "#0033CC"
62+
}
6063

6164
x <- lchob$Env$xdata
6265
xsubset <- lchob$Env$xsubset

R/addChaikin.R

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ function (..., on = NA, legend = "auto")
2121
ylim <- range(ChaikinAD,na.rm=TRUE)
2222
theme <- x$Env$theme
2323

24-
lines(x.pos, ChaikinAD, col = theme$chaikin$col$chaikinad,
24+
lines(x.pos, ChaikinAD, col = theme$ChAD$col$chaikinAD,
2525
lwd = 1, lend = 2, ...)
2626
}
2727
if(!is.character(legend) || legend == "auto")
@@ -37,7 +37,7 @@ function (..., on = NA, legend = "auto")
3737
legend(x = lc$x, y = lc$y,
3838
legend = c(paste(legend, ":"),
3939
paste(format(last(ChaikinAD[xsubset]),nsmall = 3L))),
40-
text.col = c(theme$fg, theme$chaikin$col$chaikinad),
40+
text.col = c(theme$fg, theme$ChAD$col$chaikinAD),
4141
xjust = lc$xjust,
4242
yjust = lc$yjust,
4343
bty = "n",
@@ -59,8 +59,8 @@ function (..., on = NA, legend = "auto")
5959
lchob <- current.chob()
6060
ncalls <- length(lchob$Env$call_list)
6161
lchob$Env$call_list[[ncalls + 1]] <- match.call()
62-
if (is.null(lchob$Env$theme$chaikin$col$chaikinad)) {
63-
lchob$Env$theme$chaikin$col$chaikinad <- 3
62+
if (is.null(lchob$Env$theme$ChAD)) {
63+
lchob$Env$theme$ChAD$col$chaikinAD <- 3
6464
}
6565
xdata <- lchob$Env$xdata
6666
xsubset <- lchob$Env$xsubset
@@ -92,7 +92,7 @@ function (n = 10, maType, ..., on = NA, legend = "auto")
9292
ylim <- range(ChaikinVol,na.rm=TRUE)
9393
theme <- x$Env$theme
9494

95-
lines(x.pos, ChaikinVol, col = theme$chaikin$col$chaikinvol,
95+
lines(x.pos, ChaikinVol, col = theme$ChVol$col$chaikinVol,
9696
lwd = 1, lend = 2, ...)
9797
}
9898
if(missing(maType)) maType <- "SMA"
@@ -109,7 +109,7 @@ function (n = 10, maType, ..., on = NA, legend = "auto")
109109
legend(x = lc$x, y = lc$y,
110110
legend = c(paste(legend, ":"),
111111
paste(format(last(ChaikinVol[xsubset]),nsmall = 3L))),
112-
text.col = c(theme$fg, theme$chaikin$col$chaikinvol),
112+
text.col = c(theme$fg, theme$ChVol$col$chaikinVol),
113113
xjust = lc$xjust,
114114
yjust = lc$yjust,
115115
bty = "n",
@@ -130,8 +130,8 @@ function (n = 10, maType, ..., on = NA, legend = "auto")
130130
lchob <- current.chob()
131131
ncalls <- length(lchob$Env$call_list)
132132
lchob$Env$call_list[[ncalls + 1]] <- match.call()
133-
if (is.null(lchob$Env$theme$chaikin$col$chaikinvol)) {
134-
lchob$Env$theme$chaikin$col$chaikinvol <- "#F5F5F5"
133+
if (is.null(lchob$Env$theme$ChVol)) {
134+
lchob$Env$theme$ChVol$col$chaikinVol <- "#F5F5F5"
135135
}
136136
xdata <- lchob$Env$xdata
137137
xsubset <- lchob$Env$xsubset

R/addEMV.R

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,16 @@ function (volume, n = 9, maType, vol.divisor = 10000, ..., on = NA,
2121
ylim <- range(emv,na.rm=TRUE)*1.05
2222
theme <- x$Env$theme
2323

24-
lines(x.pos, emv$emv, col = 6, lwd = 1, lend = 2, ...)
25-
lines(x.pos, emv$maEMV, col = 7, lwd = 1, lend = 2, ...)
24+
lines(x.pos, emv$emv, col = theme$EMV$col$emv, lwd = 1, lend = 2, ...)
25+
lines(x.pos, emv$maEMV, col = theme$EMV$col$maEMV, lwd = 1, lend = 2, ...)
2626
}
2727
lchob <- current.chob()
2828
ncalls <- length(lchob$Env$call_list)
2929
lchob$Env$call_list[[ncalls + 1]] <- match.call()
30+
if (is.null(lchob$Env$theme$EMV)) {
31+
lchob$Env$theme$EMV$col$emv <- 6
32+
lchob$Env$theme$EMV$col$maEMV <- 7
33+
}
3034
if(missing(volume)) volume <- lchob$Env$vo
3135
if(missing(maType)) maType <- "SMA"
3236
if(!is.character(legend) || legend == "auto")
@@ -46,7 +50,7 @@ function (volume, n = 9, maType, vol.divisor = 10000, ..., on = NA,
4650
legend = c(paste(legend, ":"),
4751
paste("emv :", sprintf("%.3f",last(emv$emv[xsubset]))),
4852
paste("maEMV :", sprintf("%.3f",last(emv$maEMV[xsubset])))),
49-
text.col = c(theme$fg, 6, 7),
53+
text.col = c(theme$fg, theme$EMV$col$emv, theme$EMV$col$maEMV),
5054
xjust = lc$xjust,
5155
yjust = lc$yjust,
5256
bty = "n",

R/addKST.R

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ function (n = c(10, 10, 10, 15), nROC = c(10, 15, 20, 30), nSig = 9,
2222
ylim <- range(kst, na.rm=TRUE) * 1.05
2323
theme <- x$Env$theme
2424

25-
lines(x.pos, kst[,1], col = 6, lwd = 1, lend = 2, ...)
26-
lines(x.pos, kst[,2], col = 7, lwd = 1, lend = 2, ...)
25+
lines(x.pos, kst[,1], col = theme$KST$col$kst, lwd = 1, lend = 2, ...)
26+
lines(x.pos, kst[,2], col = theme$KST$col$signal, lwd = 1, lend = 2, ...)
2727
}
2828
if(missing(maType)) maType <- "SMA"
2929
if(!is.character(legend) || legend == "auto")
@@ -43,7 +43,7 @@ function (n = c(10, 10, 10, 15), nROC = c(10, 15, 20, 30), nSig = 9,
4343
legend = c(legend,
4444
paste("kst :",format(last(kst[xsubset,1]),nsmall = 3L)),
4545
paste("signal :",format(last(kst[xsubset,2]),nsmall = 3L))),
46-
text.col = c(theme$fg, 6, 7),
46+
text.col = c(theme$fg, theme$KST$col$kst, theme$KST$col$signal),
4747
xjust = lc$xjust,
4848
yjust = lc$yjust,
4949
bty = "n",
@@ -65,6 +65,10 @@ function (n = c(10, 10, 10, 15), nROC = c(10, 15, 20, 30), nSig = 9,
6565
lchob <- current.chob()
6666
ncalls <- length(lchob$Env$call_list)
6767
lchob$Env$call_list[[ncalls + 1]] <- match.call()
68+
if (is.null(lchob$Env$theme$KST)) {
69+
lchob$Env$theme$KST$col$kst <- 6
70+
lchob$Env$theme$KST$col$signal <- 7
71+
}
6872
x <- lchob$Env$xdata
6973
xsubset <- lchob$Env$xsubset
7074
x <- Cl(x)

R/addMFI.R

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ function (n = 14, ..., on = NA, legend = "auto")
2020
ylim <- c(0,100)
2121
theme <- x$Env$theme
2222

23-
lines(x.pos, mfi, col = 8, lwd = 1, lend = 2, ...)
23+
lines(x.pos, mfi, col = theme$MFI$col, lwd = 1, lend = 2, ...)
2424
}
2525
if(!is.character(legend) || legend == "auto")
2626
legend <- gsub("^addMFI", "Money Flow Index ", deparse(match.call()))
@@ -35,7 +35,7 @@ function (n = 14, ..., on = NA, legend = "auto")
3535
legend(x = lc$x, y = lc$y,
3636
legend = c(paste(legend, ":"),
3737
paste(format(last(mfi[xsubset]),nsmall = 3L))),
38-
text.col = c(theme$fg, 8),
38+
text.col = c(theme$fg, theme$MFI$col),
3939
xjust = lc$xjust,
4040
yjust = lc$yjust,
4141
bty = "n",
@@ -57,6 +57,9 @@ function (n = 14, ..., on = NA, legend = "auto")
5757
lchob <- current.chob()
5858
ncalls <- length(lchob$Env$call_list)
5959
lchob$Env$call_list[[ncalls + 1]] <- match.call()
60+
if (is.null(lchob$Env$theme$MFI)) {
61+
lchob$Env$theme$MFI$col <- 8
62+
}
6063
x <- lchob$Env$xdata
6164
xsubset <- lchob$Env$xsubset
6265
volume <- lchob$Env$vo

R/addOBV.R

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ function (..., on = NA, legend = "auto")
1919
ylim <- range(obv, na.rm=TRUE) * 1.05
2020
theme <- x$Env$theme
2121

22-
lines(x.pos, obv, col = 4, lwd = 1, lend = 2, ...)
22+
lines(x.pos, obv, col = theme$OBV$col, lwd = 1, lend = 2, ...)
2323

2424
}
2525
if(!is.character(legend) || legend == "auto")
@@ -36,7 +36,7 @@ function (..., on = NA, legend = "auto")
3636
legend(x = lc$x, y = lc$y,
3737
legend = c(paste(legend, ":"),
3838
paste(format(last(obv[xsubset]),nsmall = 3L))),
39-
text.col = c(theme$fg, 4),
39+
text.col = c(theme$fg, theme$OBV$col),
4040
xjust = lc$xjust,
4141
yjust = lc$yjust,
4242
bty = "n",
@@ -58,6 +58,9 @@ function (..., on = NA, legend = "auto")
5858
lchob <- current.chob()
5959
ncalls <- length(lchob$Env$call_list)
6060
lchob$Env$call_list[[ncalls + 1]] <- match.call()
61+
if (is.null(lchob$Env$theme$OBV)) {
62+
lchob$Env$theme$OBV$col <- 4
63+
}
6164
x <- try.xts(lchob$Env$xdata, error=FALSE)
6265
xsubset <- lchob$Env$xsubset
6366
vo <- lchob$Env$vo

R/addSMI.R

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,8 @@
2626
max(abs(smi[,1]), na.rm = TRUE))*1.05
2727
theme <- x$Env$theme
2828

29-
COLOR <- "#0033CC"
30-
SIGNAL <- "#BFCFFF"
31-
32-
lines(x.pos,smi[,1],col=COLOR,lwd=1,type='l')
33-
lines(x.pos,smi[,2],col=SIGNAL,lwd=1,lty='dotted',type='l')
29+
lines(x.pos,smi[,1],col=theme$SMI$col$smi,lwd=1,type='l')
30+
lines(x.pos,smi[,2],col=theme$SMI$col$signal,lwd=1,lty='dotted',type='l')
3431

3532
}
3633
mapply(function(name, value) {
@@ -40,22 +37,20 @@
4037
exp <- parse(text = gsub("list", "chartSMI", as.expression(substitute(list(x = current.chob(),
4138
n = n,fast = fast,slow = slow,signal = signal,ma.type = ma.type)))), srcfile = NULL)
4239
exp <- c(exp, expression(
43-
COLOR <- "#0033CC",
44-
SIGNAL <- "#BFCFFF",
4540
text(0, max(abs(smi[,1]), na.rm = TRUE)*.9,
4641
paste("Stochastic Momentum Index (",
4742
paste(n,fast,slow,signal,sep=','),
4843
"):", sep = ""), col = theme$fg,
4944
pos = 4),
5045

5146
text(0, max(abs(smi[,1]), na.rm = TRUE)*.9,
52-
paste("\n\n\nSMI: ",sprintf("%.3f",last(smi[xsubset,1])), sep = ""), col = COLOR,
53-
pos = 4),
47+
paste("\n\n\nSMI: ",sprintf("%.3f",last(smi[xsubset,1])), sep = ""),
48+
col = theme$SMI$col$smi, pos = 4),
5449

5550
text(0, max(abs(smi[,1]), na.rm = TRUE)*.9,
5651
paste("\n\n\n\n\nSignal: ",
57-
sprintf("%.3f",last(smi[xsubset,2])), sep = ""), col = SIGNAL,
58-
pos = 4)))
52+
sprintf("%.3f",last(smi[xsubset,2])), sep = ""),
53+
col = theme$SMI$col$signal, pos = 4)))
5954
exp <- c(expression(
6055
smi <- TA$smi,
6156
# add inbox color
@@ -73,6 +68,10 @@
7368
lchob <- current.chob()
7469
ncalls <- length(lchob$Env$call_list)
7570
lchob$Env$call_list[[ncalls + 1]] <- match.call()
71+
if (is.null(lchob$Env$theme$SMI)) {
72+
lchob$Env$theme$SMI$col$smi <- "#0033CC"
73+
lchob$Env$theme$SMI$col$signal <- "#BFCFFF"
74+
}
7675

7776
x <- lchob$Env$xdata
7877
xsubset <- lchob$Env$xsubset

0 commit comments

Comments
 (0)