11`swapTA` <-
2- function (ta1 ,ta2 ,occ1 = 1 ,occ2 = 1 ,dev ) {
2+ function (ta1 ,ta2 ,occ1 = 1 ,occ2 = 1 ,chob ) {
33 if (missing(ta1 ) | missing(ta2 )) stop(" two TA indicator required" )
44
5- # default to the current device if none specified
6- if (missing(dev )) dev <- dev.cur ()
7- ta.list <- listTA(dev )
5+ # default to the current chob if none specified
6+ if (missing(chob )) chob <- get.chob ()
7+ ta.list <- listTA(chob )
88
99 # get the current chob
10- lchob <- get. chob()[[ dev ]]
10+ lchob <- chob
1111
1212 # make indicator name match original call
1313 if (regexpr(" ^add" ,ta1 ) == - 1 ) ta1 <- paste(" add" ,ta1 ,sep = ' ' )
@@ -19,14 +19,25 @@ function(ta1,ta2,occ1=1,occ2=1,dev) {
1919 which.ta2 <- which(ta2 == sapply(ta.list ,
2020 function (x ) deparse(x [[1 ]])))[occ2 ]
2121
22- tmp.ta1 <- lchob @ passed.args $ TA [[which.ta1 ]]
23- tmp.ta2 <- lchob @ passed.args $ TA [[which.ta2 ]]
24-
25- lchob @ passed.args $ TA [[which.ta1 ]] <- tmp.ta2
26- lchob @ passed.args $ TA [[which.ta2 ]] <- tmp.ta1
22+ # ## swap two TAs without temporary storage
23+
24+ ta.seq <- seq_along(ta.list )
25+ ta.swap <- replace(ta.seq , c(which.ta1 , which.ta2 ), ta.seq [c(which.ta2 , which.ta1 )])
26+ lchob $ Env $ TA <- lchob $ Env $ TA [ta.swap ]
27+ lchob $ Env $ call_list [- 1 ] <- lchob $ Env $ call_list [1 + ta.swap ]
28+ # swap frames
29+ frame <- sapply(lchob $ Env $ actions [9 + c(which.ta1 , which.ta2 )], function (x ) attr(x , " frame" ))
30+ attr(lchob $ Env $ actions [[9 + which.ta1 ]], " frame" ) <- frame [2 ]
31+ attr(lchob $ Env $ actions [[9 + which.ta2 ]], " frame" ) <- frame [1 ]
32+ # swap actions
33+ lchob $ Env $ actions [- c(1 : 9 )] <- lchob $ Env $ actions [9 + ta.swap ]
34+ # swap y limits
35+ lchob $ Env $ ylim [frame ] <- lchob $ Env $ ylim [rev(frame )]
36+
37+ # ## End swap
2738
28- do.call( " chartSeries.chob " , list ( lchob ))
29- write.chob(lchob ,lchob @ device )
39+ lchob
40+ # write.chob(lchob,lchob@device)
3041}
3142
3243`moveTA` <-
0 commit comments