graph - R- programming- Error in get.current.chob() : improperly set or missing graphics device -


library(quantmod) getsymbols("lt.ns") plot(lt.ns["2013-12-01::2014-12-01"]) close<-cl(lt.ns["2013-12-01::2014-12-01"]) open<-op(lt.ns["2013-12-01::2014-12-01"]) close<-as.matrix(close) open<-as.matrix(open) bbands<-addbbands(n=20,sd=2) values_bbands<-bbands@ta.values values_bbands[is.na(values_bbands)]<-0 bbands<-as.matrix(values_bbands) up<-bbands[,1] up<-as.matrix(up) down<-bbands[,3] down<-as.matrix(down) data<-read.table("c:\\temp\\dates.txt") attach(data) head(data) stock<-as.matrix(data)  for(i in 131:261) {     if(close[i]>down[i])     {     print("the selling date is:")     print(i)     big.red.dot <- xts(open[i], as.date(stock[i,1]))     points(big.red.dot, col="red", pch=19, cex=0.5  )     }     if(close[i]<up[i])     {         print("the buying date is:")         print(i)         big.green.dot <- xts(open[i], as.date(stock[i,1]))         points(big.green.dot, col="green", pch=19, cex=0.5  )     }  } 

when run code in r , "****error in get.current.chob() : improperly set or missing graphics device"****. 2-3 times output proper graph buy , sell signals indicated on graph when run code error gets displayed tried on different version of r-1.3 still error appears. in above code bbands<-addbbands(n=20,sd=2) appropriate? because when run code in individual lines same error gets displayed line too. want final output graph buy , sell points indicated @ respective points.

no, bbands <- addbbands(n=20,sd=2) not appropriate.

addbbands should called add bollinger bands already-existing graphics device created chartseries. can include directly in chartseries call:

library(quantmod) getsymbols("lt.ns") chartseries(lt.ns, ta="addbbands(n=20)", subset="2013-12-01::2014-12-01") 

if want calculate bollinger bands, call ttr::bbands (which addbbands does).

bbands <- bbands(hlc(lt.ns), n=20, sd=2) 

all other stuff you're doing can done couple calls addpoints, after constructing necessary objects plot.

# sells sell <- op(lt.ns) is.na(sell) <- which(!cl(lt.ns) > bbands$dn) addpoints(1:nrow(sell), sell, col='red', pch=19, cex=0.5) # buys buy <- op(lt.ns) is.na(buy) <- which(!cl(lt.ns) < bbands$up) addpoints(1:nrow(buy), buy, col='green', pch=19, cex=0.5) 

but note buys , sells not mutually exclusive.

> head(cbind(buy,sell))            lt.ns.open lt.ns.open.1 2007-01-01     1445.9       1445.9 2007-01-02     1447.0       1447.0 2007-01-03     1458.0       1458.0 2007-01-04     1489.7       1489.7 2007-01-05     1500.0       1500.0 2007-01-08     1471.0       1471.0 

Comments

Popular posts from this blog

node.js - Mongoose: Cast to ObjectId failed for value on newly created object after setting the value -

[C++][SFML 2.2] Strange Performance Issues - Moving Mouse Lowers CPU Usage -

ios - Possible to get UIButton sizeThatFits to work? -