Skip to content

Commit 048a875

Browse files
committed
Pass function calls and indicator values to the environment
To coordinate with functions that manipulate TA such as swapTA(), moveTA() and dropTA(), TA values is passed to a new name list "TA" and function calls are passed to call_list.
1 parent a4ee734 commit 048a875

File tree

16 files changed

+290
-87
lines changed

16 files changed

+290
-87
lines changed

R/addAroon.R

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ function (n = 20, ..., on = NA, legend = "auto")
4545
bty = "n",
4646
y.intersp=0.95)))
4747
exp <- c(expression(
48+
Aroon <- TA$Aroon,
4849
# add inbox color
4950
rect(xlim[1], 0, xlim[2], 100, col=theme$fill),
5051
# add grid lines and left-side axis labels
@@ -58,6 +59,8 @@ function (n = 20, ..., on = NA, legend = "auto")
5859
rect(xlim[1], 0, xlim[2], 100, border=theme$labels)), exp)
5960

6061
lchob <- current.chob()
62+
ncalls <- length(lchob$Env$call_list)
63+
lchob$Env$call_list[[ncalls + 1]] <- match.call()
6164
if (is.null(lchob$Env$theme$aroon$col$arronUp)) {
6265
lchob$Env$theme$aroon$col$aroonUp <- 3
6366
lchob$Env$theme$aroon$col$aroonDn <- 4
@@ -66,7 +69,7 @@ function (n = 20, ..., on = NA, legend = "auto")
6669
xdata <- cbind(Hi(xdata),Lo(xdata))
6770
xsubset <- lchob$Env$xsubset
6871
Aroon <- aroon(HL=xdata,n=n)[xsubset,-3]
69-
lchob$Env$Aroon <- Aroon
72+
lchob$Env$TA$Aroon <- Aroon
7073
# lenv$xdata <- structure(Aroon, .Dimnames = list(NULL, "aroon"))
7174
if(is.na(on)) {
7275
lchob$add_frame(ylim=c(0,100),asp=1,fixed=TRUE)
@@ -116,6 +119,7 @@ function (n = 20, ..., on = NA, legend = "auto")
116119
bty = "n",
117120
y.intersp=0.95)))
118121
exp <- c(expression(
122+
AroonOsc <- TA$AroonOsc,
119123
# add inbox color
120124
rect(xlim[1], c(min(AroonOsc,na.rm=TRUE)*0.95, max(AroonOsc)*1.05)[1], xlim[2], c(min(AroonOsc,na.rm=TRUE)*0.95, max(AroonOsc)*1.05)[2], col=theme$fill),
121125
# add grid lines and left-side axis labels
@@ -129,14 +133,16 @@ function (n = 20, ..., on = NA, legend = "auto")
129133
rect(xlim[1], c(min(AroonOsc,na.rm=TRUE)*0.95, max(AroonOsc, na.rm=TRUE)*1.05)[1], xlim[2], c(min(AroonOsc,na.rm=TRUE)*0.95, max(AroonOsc, na.rm=TRUE)*1.05)[2], border=theme$labels)), exp)
130134

131135
lchob <- current.chob()
136+
ncalls <- length(lchob$Env$call_list)
137+
lchob$Env$call_list[[ncalls + 1]] <- match.call()
132138
if (is.null(lchob$Env$theme$aroon$col$aroonOsc)) {
133139
lchob$Env$theme$aroon$col$aroonOsc <- 3
134140
}
135141
xdata <- lchob$Env$xdata
136142
xdata <- cbind(Hi(xdata),Lo(xdata))
137143
xsubset <- lchob$Env$xsubset
138144
AroonOsc <- aroon(HL=xdata,n=n)[xsubset,3]
139-
lchob$Env$AroonOsc <- AroonOsc
145+
lchob$Env$TA$AroonOsc <- AroonOsc
140146
if(is.na(on)) {
141147
lchob$add_frame(ylim=c(min(AroonOsc,na.rm=TRUE)*0.95, max(AroonOsc, na.rm=TRUE)*1.05),asp=1,fixed=TRUE)
142148
lchob$next_frame()

R/addCLV.R

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ function (..., on = NA, legend = "auto")
4040
bty = "n",
4141
y.intersp=0.95)))
4242
exp <- c(expression(
43+
clv <- TA$clv,
4344
# add inbox color
4445
rect(xlim[1], range(clv, na.rm=TRUE)[1], xlim[2], range(clv, na.rm=TRUE)[2], col=theme$fill),
4546
# add grid lines and left-side axis labels
@@ -53,13 +54,15 @@ function (..., on = NA, legend = "auto")
5354
rect(xlim[1], range(clv, na.rm=TRUE)[1], xlim[2], range(clv, na.rm=TRUE)[2], border=theme$labels)), exp)
5455

5556
lchob <- current.chob()
57+
ncalls <- length(lchob$Env$call_list)
58+
lchob$Env$call_list[[ncalls + 1]] <- match.call()
5659
if (is.null(lchob$Env$theme$clv$col)) {
5760
lchob$Env$theme$clv$col <- 5
5861
}
5962
xdata <- lchob$Env$xdata
6063
xsubset <- lchob$Env$xsubset
6164
clv <- CLV(HLC=HLC(xdata))[xsubset]
62-
lchob$Env$clv <- clv
65+
lchob$Env$TA$clv <- clv
6366
if(is.na(on)) {
6467
lchob$add_frame(ylim=range(clv,na.rm=TRUE),asp=1,fixed=TRUE)
6568
lchob$next_frame()

R/addCMF.R

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
bty = "n",
3939
y.intersp=0.95)))
4040
exp <- c(expression(
41+
cmf <- TA$cmf,
4142
# add inbox color
4243
rect(xlim[1], -max(abs(cmf), na.rm = TRUE)*1.05, xlim[2], max(abs(cmf), na.rm = TRUE)*1.05, col=theme$fill),
4344
# add grid lines and left-side axis labels
@@ -52,6 +53,8 @@
5253
segments(xlim[1], 0, xlim[2], 0, col = "#999999")), exp)
5354

5455
lchob <- current.chob()
56+
ncalls <- length(lchob$Env$call_list)
57+
lchob$Env$call_list[[ncalls + 1]] <- match.call()
5558
xdata <- lchob$Env$xdata
5659
xdata <- if(is.OHLC(xdata)) {
5760
cbind(Hi(xdata),Lo(xdata),Cl(xdata))
@@ -60,7 +63,7 @@
6063
vo <- lchob$Env$vo
6164

6265
cmf <- CMF(xdata,vo,n=n)[xsubset]
63-
lchob$Env$cmf <- cmf
66+
lchob$Env$TA$cmf <- cmf
6467
if(!is.character(legend) || legend == "auto")
6568
lchob$Env$legend <- paste("Chaikin Money Flow (", n, ")", sep="")
6669
lchob$add_frame(ylim=c(-max(abs(cmf), na.rm = TRUE),

R/addCMO.R

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
bty = "n",
4141
y.intersp=0.95)))
4242
exp <- c(expression(
43+
cmo <- TA$cmo,
4344
# add inbox color
4445
rect(xlim[1], -max(abs(cmo), na.rm = TRUE)*1.05, xlim[2], max(abs(cmo), na.rm = TRUE)*1.05, col=theme$fill),
4546
# add grid lines and left-side axis labels
@@ -54,6 +55,8 @@
5455
segments(xlim[1], 0, xlim[2], 0, col = "#666666", lty = "dotted")), exp)
5556

5657
lchob <- current.chob()
58+
ncalls <- length(lchob$Env$call_list)
59+
lchob$Env$call_list[[ncalls + 1]] <- match.call()
5760

5861
x <- lchob$Env$xdata
5962
xsubset <- lchob$Env$xsubset
@@ -69,7 +72,7 @@
6972
}
7073

7174
cmo <- CMO(xx,n=n)[xsubset]
72-
lchob$Env$cmo <- cmo
75+
lchob$Env$TA$cmo <- cmo
7376
if(!is.character(legend) || legend == "auto")
7477
lchob$Env$legend <- paste("Chande Momentum Oscillator (", n, ") ", sep="")
7578
lchob$add_frame(ylim=c(-max(abs(cmo), na.rm = TRUE),

R/addChaikin.R

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ function (..., on = NA, legend = "auto")
4343
bty = "n",
4444
y.intersp=0.95)))
4545
exp <- c(expression(
46+
ChaikinAD <- TA$ChaikinAD,
4647
# add inbox color
4748
rect(xlim[1], range(ChaikinAD, na.rm=TRUE)[1], xlim[2], range(ChaikinAD, na.rm=TRUE)[2], col=theme$fill),
4849
# add grid lines and left-side axis labels
@@ -56,14 +57,16 @@ function (..., on = NA, legend = "auto")
5657
rect(xlim[1], range(ChaikinAD, na.rm=TRUE)[1], xlim[2], range(ChaikinAD, na.rm=TRUE)[2], border=theme$labels)), exp)
5758

5859
lchob <- current.chob()
60+
ncalls <- length(lchob$Env$call_list)
61+
lchob$Env$call_list[[ncalls + 1]] <- match.call()
5962
if (is.null(lchob$Env$theme$chaikin$col$chaikinad)) {
6063
lchob$Env$theme$chaikin$col$chaikinad <- 3
6164
}
6265
xdata <- lchob$Env$xdata
6366
xsubset <- lchob$Env$xsubset
6467
vo <- lchob$Env$vo
6568
ChaikinAD <- chaikinAD(HLC = HLC(xdata), volume = vo)[xsubset]
66-
lchob$Env$ChaikinAD <- ChaikinAD
69+
lchob$Env$TA$ChaikinAD <- ChaikinAD
6770
if(is.na(on)) {
6871
lchob$add_frame(ylim=range(ChaikinAD,na.rm=TRUE),asp=1,fixed=TRUE)
6972
lchob$next_frame()
@@ -111,7 +114,8 @@ function (n = 10, maType, ..., on = NA, legend = "auto")
111114
yjust = lc$yjust,
112115
bty = "n",
113116
y.intersp=0.95)))
114-
exp <- c(expression(
117+
exp <- c(expression(
118+
ChaikinVol <- TA$ChaikinVol,
115119
# add inbox color
116120
rect(xlim[1], range(ChaikinVol, na.rm=TRUE)[1], xlim[2], range(ChaikinVol, na.rm=TRUE)[2], col=theme$fill),
117121
# add grid lines and left-side axis labels
@@ -124,13 +128,15 @@ function (n = 10, maType, ..., on = NA, legend = "auto")
124128
# add border of plotting area
125129
rect(xlim[1], range(ChaikinVol, na.rm=TRUE)[1], xlim[2], range(ChaikinVol, na.rm=TRUE)[2], border=theme$labels)), exp)
126130
lchob <- current.chob()
131+
ncalls <- length(lchob$Env$call_list)
132+
lchob$Env$call_list[[ncalls + 1]] <- match.call()
127133
if (is.null(lchob$Env$theme$chaikin$col$chaikinvol)) {
128134
lchob$Env$theme$chaikin$col$chaikinvol <- "#F5F5F5"
129135
}
130136
xdata <- lchob$Env$xdata
131137
xsubset <- lchob$Env$xsubset
132138
ChaikinVol <- chaikinVolatility(HL = HLC(xdata)[,-3], n = n, maType = maType)[xsubset]
133-
lchob$Env$ChaikinVol <- ChaikinVol
139+
lchob$Env$TA$ChaikinVol <- ChaikinVol
134140
if(is.na(on)) {
135141
lchob$add_frame(ylim=range(ChaikinVol,na.rm=TRUE),asp=1,fixed=TRUE)
136142
lchob$next_frame()

R/addEMV.R

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@ function (volume, n = 9, maType, vol.divisor = 10000, ..., on = NA,
1212
lenv$chartEMV <- function(x, volume, n, maType, vol.divisor, ..., on, legend) {
1313
xdata <- x$Env$xdata
1414
xsubset <- x$Env$xsubset
15-
volume <- x$Env$volume
15+
volume <- x$Env$TA$volume
1616
emv <- EMV(HL=HLC(xdata)[,-3], volume = volume, n = n, maType = maType,
17-
on = on, legend = legend)[xsubset]
17+
legend = legend)[xsubset]
1818
spacing <- x$Env$theme$spacing
1919
x.pos <- 1 + spacing * (1:NROW(emv) - 1)
2020
xlim <- x$Env$xlim
@@ -24,6 +24,9 @@ function (volume, n = 9, maType, vol.divisor = 10000, ..., on = NA,
2424
lines(x.pos, emv$emv, col = 6, lwd = 1, lend = 2, ...)
2525
lines(x.pos, emv$maEMV, col = 7, lwd = 1, lend = 2, ...)
2626
}
27+
lchob <- current.chob()
28+
ncalls <- length(lchob$Env$call_list)
29+
lchob$Env$call_list[[ncalls + 1]] <- match.call()
2730
if(missing(volume)) volume <- lchob$Env$vo
2831
if(missing(maType)) maType <- "SMA"
2932
if(!is.character(legend) || legend == "auto")
@@ -49,6 +52,7 @@ function (volume, n = 9, maType, vol.divisor = 10000, ..., on = NA,
4952
bty = "n",
5053
y.intersp=0.95)))
5154
exp <- c(expression(
55+
emv <- TA$emv,
5256
# add inbox color
5357
rect(xlim[1], range(emv,na.rm=TRUE)[1]*1.05, xlim[2], range(emv,na.rm=TRUE)[2]*1.05, col=theme$fill),
5458
# add grid lines and left-side axis labels
@@ -61,13 +65,12 @@ function (volume, n = 9, maType, vol.divisor = 10000, ..., on = NA,
6165
# add border of plotting area
6266
rect(xlim[1], range(emv,na.rm=TRUE)[1]*1.05, xlim[2], range(emv,na.rm=TRUE)[2]*1.05, border=theme$labels)), exp)
6367

64-
lchob <- current.chob()
6568
xdata <- lchob$Env$xdata
6669
xsubset <- lchob$Env$xsubset
6770
emv <- EMV(HL = HLC(xdata)[,-3], volume = volume, n = n, maType = maType,
6871
vol.divisor = vol.divisor)[xsubset]
69-
lchob$Env$emv <- emv
70-
lchob$Env$volume <- volume
72+
lchob$Env$TA$emv <- emv
73+
lchob$Env$TA$volume <- volume
7174
if(is.na(on)) {
7275
lchob$add_frame(ylim=range(emv,na.rm=TRUE)*1.05,asp=1,fixed=TRUE)
7376
lchob$next_frame()

R/addKST.R

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ function (n = c(10, 10, 10, 15), nROC = c(10, 15, 20, 30), nSig = 9,
5050
bty = "n",
5151
y.intersp=0.95)))
5252
exp <- c(expression(
53+
kst <- TA$kst,
5354
# add inbox color
5455
rect(xlim[1], range(kst, na.rm=TRUE)[1] * 1.05, xlim[2], range(kst, na.rm=TRUE)[2] * 1.05, col=theme$fill),
5556
# add grid lines and left-side axis labels
@@ -63,13 +64,15 @@ function (n = c(10, 10, 10, 15), nROC = c(10, 15, 20, 30), nSig = 9,
6364
rect(xlim[1], range(kst, na.rm=TRUE)[1] * 1.05, xlim[2], range(kst, na.rm=TRUE)[2] * 1.05, border=theme$labels)), exp)
6465

6566
lchob <- current.chob()
67+
ncalls <- length(lchob$Env$call_list)
68+
lchob$Env$call_list[[ncalls + 1]] <- match.call()
6669
x <- lchob$Env$xdata
6770
xsubset <- lchob$Env$xsubset
6871
x <- x[xsubset]
6972
x <- coredata(Cl(x))
7073
kst <- KST(price = x, n = n, nROC = nROC, nSig = nSig, maType = maType,
7174
wts = wts)
72-
lchob$Env$kst <- kst
75+
lchob$Env$TA$kst <- kst
7376
if(is.na(on)) {
7477
lchob$add_frame(ylim=range(kst, na.rm=TRUE) * 1.05,asp=1,fixed=TRUE)
7578
lchob$next_frame()

R/addMFI.R

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ function (n = 14, ..., on = NA, legend = "auto")
4141
bty = "n",
4242
y.intersp=0.95)))
4343
exp <- c(expression(
44+
mfi <- TA$mfi,
4445
# add inbox color
4546
rect(xlim[1], 0, xlim[2], 100, col=theme$fill),
4647
# add grid lines and left-side axis labels
@@ -54,12 +55,14 @@ function (n = 14, ..., on = NA, legend = "auto")
5455
rect(xlim[1], 0, xlim[2], 100, border=theme$labels)), exp)
5556

5657
lchob <- current.chob()
58+
ncalls <- length(lchob$Env$call_list)
59+
lchob$Env$call_list[[ncalls + 1]] <- match.call()
5760
x <- lchob$Env$xdata
5861
xsubset <- lchob$Env$xsubset
5962
volume <- lchob$Env$vo
6063
x <- HLC(x)
6164
mfi <- MFI(HLC = x, volume = volume, n = n)[xsubset]
62-
lchob$Env$mfi <- mfi
65+
lchob$Env$TA$mfi <- mfi
6366
if(any(is.na(on))) {
6467
lchob$add_frame(ylim=c(0,100),asp=1,fixed=TRUE)
6568
lchob$next_frame()

R/addOBV.R

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ function (..., on = NA, legend = "auto")
4242
bty = "n",
4343
y.intersp=0.95)))
4444
exp <- c(expression(
45+
obv <- TA$obv,
4546
# add inbox color
4647
rect(xlim[1], range(obv, na.rm=TRUE)[1] * 1.05, xlim[2], range(obv, na.rm=TRUE)[2] * 1.05, col=theme$fill),
4748
# add grid lines and left-side axis labels
@@ -55,11 +56,13 @@ function (..., on = NA, legend = "auto")
5556
rect(xlim[1], range(obv, na.rm=TRUE)[1] * 1.05, xlim[2], range(obv, na.rm=TRUE)[2] * 1.05, border=theme$labels)), exp)
5657

5758
lchob <- current.chob()
59+
ncalls <- length(lchob$Env$call_list)
60+
lchob$Env$call_list[[ncalls + 1]] <- match.call()
5861
x <- try.xts(lchob$Env$xdata, error=FALSE)
5962
xsubset <- lchob$Env$xsubset
6063
vo <- lchob$Env$vo
6164
obv <- OBV(price = Cl(x), volume = vo)[xsubset]
62-
lchob$Env$obv <- obv
65+
lchob$Env$TA$obv <- obv
6366
if(is.na(on)) {
6467
lchob$add_frame(ylim=range(obv, na.rm=TRUE) * 1.05 ,asp=1,fixed=TRUE)
6568
lchob$next_frame()

R/addSMI.R

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@
5757
sprintf("%.3f",last(smi[,2])), sep = ""), col = SIGNAL,
5858
pos = 4)))
5959
exp <- c(expression(
60+
smi <- TA$smi,
6061
# add inbox color
6162
rect(xlim[1], -max(abs(smi[,1]), na.rm = TRUE)*1.05, xlim[2], max(abs(smi[,1]), na.rm = TRUE)*1.05, col=theme$fill),
6263
# add grid lines and left-side axis labels
@@ -70,6 +71,8 @@
7071
rect(xlim[1], -max(abs(smi[,1]), na.rm = TRUE)*1.05, xlim[2], max(abs(smi[,1]), na.rm = TRUE)*1.05, border=theme$labels)), exp)
7172

7273
lchob <- current.chob()
74+
ncalls <- length(lchob$Env$call_list)
75+
lchob$Env$call_list[[ncalls + 1]] <- match.call()
7376

7477
x <- lchob$Env$xdata
7578
xsubset <- lchob$Env$xsubset
@@ -84,7 +87,7 @@
8487

8588
smi <- SMI(xx, n=n, nFast=fast,
8689
nSlow=slow, nSig=signal, maType=ma.type)[xsubset]
87-
lchob$Env$smi <- smi
90+
lchob$Env$TA$smi <- smi
8891

8992
lchob$add_frame(ylim=c(-max(abs(smi[,1]), na.rm = TRUE),
9093
max(abs(smi[,1]), na.rm = TRUE))*1.05, asp=1, fixed=TRUE)

0 commit comments

Comments
 (0)