Demo entry 6631360

very very very very long and long and long and long

   

Submitted by anonymous on Jul 13, 2017 at 13:50
Language: RConsole. Code size: 1.0 kB.

ds<-read.csv("601088.csv",header=T)
ds$ma5<-SMA(ds$CLOSE,n=5)
ds$ma20<-SMA(ds$CLOSE,n=20)
ds$preCLOSE<-c(NA,ds$CLOSE[-length(ds$CLOSE)])
ds$ret1<-(ds$CLOSE-ds$preCLOSE)/ds$preCLOSE
ds$signal<-ifelse(ds$ma5<ds$ma20,0,1)
ds$presignal<-c(NA,ds$signal[-length(ds$signal)])
ds$point<-ds$signal-ds$presignal
write.csv(ds,file="601088.csv",fileEncoding = "UTF-8")
SH601088<-read.csv(file = "601088.csv",
                   fileEncoding = "UTF-8",
                   header = T)
rownames(ds)<-ds$DATE
buy<-c(which(SH601088$point==1))
sell<-c(which(SH601088$point==-1))
ifelse(sell[1]<buy[1],sell<-sell[-1])
ifelse(sell[length(sell)]<buy[length(buy)],sell<-c(sell,length(SH601088$DATE)))
ds<-ds[,c("OPEN","CLOSE","HIGH","LOW","ma5","ma20")]
ds<-as.xts(ds)
class(ds)
p<-dygraph(ds)%>%
  dyCandlestick()%>%
  dyEvent(SH601088$DATE[buy], labelLoc = "bottom",color = "red") %>%
  dyEvent(SH601088$DATE[sell], labelLoc = "bottom",color = "green") %>%
  dyRangeSelector(height=10,
                  strokeColor="")
p

This snippet took 0.00 seconds to highlight.

Back to the Entry List or Home.

Delete this entry (admin only).