Skip to content

Commit 8fb26c5

Browse files
committed
Refactor dropTA to use panel functionality
Since S4 method and chartSeries.chob are deprecated, dropTA, listTA and get.chob functions are refactored to use panel functionality of xts::plot.xts. The way TAs are removed is based on which frame they are added to.
1 parent 3f56737 commit 8fb26c5

File tree

3 files changed

+28
-17
lines changed

3 files changed

+28
-17
lines changed

R/TA.R

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -286,9 +286,11 @@ function(type=c('chartSeries','barChart','candleChart')) {
286286
}# }}}
287287
# listTA {{{
288288
`listTA` <-
289-
function(dev) {
290-
if(missing(dev)) dev <- dev.cur()
291-
sapply(get.chob()[[dev]]@passed.args$TA,function(x) x@call)
289+
function(chob) {
290+
if(missing(chob)) chob <- get.chob()
291+
# return function calls of addTA
292+
chob$Env$call_list[-1]
293+
#sapply(get.chob()[[dev]]@passed.args$TA,function(x) x@call)
292294
} # }}}
293295

294296
chartNULL <- function(...) return(invisible(NULL))

R/chob.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ function(x,pos)
2727
`get.chob` <-
2828
function()
2929
{
30-
x <- .chob$.chob
30+
x <- xts:::.plotxtsEnv$.xts_chob
3131
return(x)
3232
#x <- get('.chob',as.environment("package:quantmod"))
3333
#attr(x,'.Environment') <- NULL

R/dropTA.R

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -61,18 +61,15 @@ function(ta,pos,occ=1,dev) {
6161
}
6262

6363
`dropTA` <-
64-
function(ta,occ=1,dev,all=FALSE) {
64+
function(ta,occ=1,chob,all=FALSE) {
6565

6666
if(all) return(do.call('dropTA', list(1:length(listTA()))))
6767

6868
if(missing(ta)) stop("no TA indicator specified")
6969

70-
# default to the current device if none specified
71-
if(missing(dev)) dev <- dev.cur()
72-
ta.list <- listTA(dev)
73-
7470
# get the current chob
75-
lchob <- get.chob()[[dev]]
71+
if(missing(chob)) chob <- get.chob()
72+
ta.list <- listTA(chob)
7673

7774
sel.ta <- NULL
7875

@@ -91,22 +88,34 @@ function(ta,occ=1,dev,all=FALSE) {
9188
if(!is.na(which.ta)) {
9289

9390
# decrease window count if necessary
94-
if(lchob@passed.args$TA[[which.ta]]@new)
95-
lchob@windows <- lchob@windows - 1
91+
#if([email protected]$TA[[which.ta]]@new)
92+
# lchob@windows <- lchob@windows - 1
9693

9794
sel.ta <- c(sel.ta,which.ta)
95+
} else {
96+
stop("nothing to remove")
9897
}
9998
}
10099

101100
if(is.null(sel.ta)) stop("nothing to remove")
102101

103102
# remove TA from current list
104-
lchob@passed.args$TA <- lchob@passed.args$TA[-sel.ta]
105-
if(length(lchob@passed.args$TA) < 1)
106-
lchob@passed.args$TA <- list()
103+
ta.list <- ta.list[-sel.ta]
104+
for(li in sel.ta) {
105+
# number of actions of chartSeries object without TA is 9
106+
frame <- attr(chob$Env$actions[[9 + sel.ta]], "frame")
107+
if(abs(frame)==2)
108+
chob$Env$actions[[9 + sel.ta]] <- NULL
109+
else
110+
chob$remove_frame(frame)
111+
chob$Env$TA[[sel.ta]] <- NULL
112+
ncalls <- length(chob$Env$call_list)
113+
# plot.xts(...) is included in call_list but listTA() is not
114+
chob$Env$call_list[1 + sel.ta] <- NULL
115+
}
107116

108117
# redraw chart
109-
do.call("chartSeries.chob",list(lchob))
118+
chob
110119

111-
write.chob(lchob,lchob@device)
120+
#write.chob(lchob,lchob@device)
112121
}

0 commit comments

Comments
 (0)