Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- library(R.utils)
- library(lubridate)
- eu <- read.csv(file.choose(), header=F)
- head(eu)
- time.date <- unique(eu[,1])
- Test <- data.frame(
- str(10),
- numeric(),
- numeric(),
- numeric(),
- numeric(),
- str(5),
- str(5),
- stringsAsFactors=FALSE)
- x = 1
- pb <- txtProgressBar(min = 0, max = length(time.date), style = 3)
- for (x in 1:length(time.date)) {
- cur_day <- eu[eu[,1] == time.date[x],]
- nHigh = max(cur_day[,4])
- nLow = min(cur_day[,5])
- nHighAtnr = which.max(cur_day[,4])
- nLowAtnr = which.min(cur_day[,5])
- nHighAt = cur_day[nHighAtnr,2]
- nLowAt = cur_day[nLowAtnr,2]
- Test[x,1] = as.character(time.date[x])
- Test[x,2] = cur_day[1,3]
- Test[x,3] = nHigh
- Test[x,4] = nLow
- Test[x,5] = cur_day[length(cur_day),6]
- Test[x,6] = nHighAt
- Test[x,7] = nLowAt
- setTxtProgressBar(pb,x )
- }
- colnames(Test) <- c('Date','Open','High','Low','Close','HighAt','LowAt')
- #a <- df[!(df$plan==0 & df$sevk==0),]
- #Remove Saturday and Sunday candles
- Test <- Test[!(wday(as.Date(Test$Date,"%Y.%m.%d"))==7 || wday(as.Date(Test$Date,"%Y.%m.%d"))==1 ),]
- Test2 <- data.frame(str(5))
- x = 1
- for (x in 1:length(Test$Date)) {
- if (Test$Open[x] <= Test$Close[x]) {
- #UP DAY
- Test2[x,1] <- lapply(Test$LowAt[x], as.character)
- }else {
- #Down Day
- Test2[x,1] <- lapply(Test$HighAt[x], as.character)
- }
- }
- colnames(Test2)[1] <- "Time"
- Test3 <- unique(Test2$Time)
- Test4 <- 1
- x = 1
- for (x in 1:length(Test3)) {
- Test4[x] = match(Test3[x], Test2$Time)
- }
- write.csv(Test5,"test.csv",row.names=FALSE,na="")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement