print(z <- Sys.time())
## [1] "2015-01-09 10:21:06 JST"
attach(lllnew)
library(dtw)
## Loading required package: proxy
## 
## Attaching package: 'proxy'
## 
## The following objects are masked from 'package:stats':
## 
##     as.dist, dist
## 
## Loaded dtw v1.17-1. See ?dtw for help, citation("dtw") for use in publication.
library(dplyr)
## 
## Attaching package: 'dplyr'
## 
## The following object is masked from 'package:stats':
## 
##     filter
## 
## The following objects are masked from 'package:base':
## 
##     intersect, setdiff, setequal, union
par(mfrow = c(3,2))
srch <- 226472
srch2 <- srch + 288
trade <- srch + 72

plot(Close[srch:srch2], xlab=Time[srch], ylab="Original", type="l", lwd=2)
abline(h=Close[trade], col="gray")
plot(RSI[srch:srch2], xlab=Time[srch], ylab="Original", xlim=c(0,300), ylim=c(0,100), type="l", lwd=2, col="lightgreen")

i <- 0
z <- 0
y <- 0

while(i <= 226472){
  i <- i + 1
  n <- i + 72
  H24 <- i + 288
  if(dtw(Close[i:n], Close[226472:226544])$distance<430){
  

      plot(Close[srch:srch2], axes=F, xlab="", ylab="", type="l", lwd=2)
      par(new=T)
      plot(Close[i:H24], xlab=Time[i], ylab=X[i], type="l")    
      abline(h=Close[i + 72], col="blue")
      z <- z + 1
    if(Close[i + 72] < (max(Close[n:H24]) + min(Close[n:H24]))/2){
      abline(h=Close[i + 72], col="red")
      z <- z - 1
      y <- y + 1
    }
    plot(RSI[i:H24], xlab=Time[i], ylab=X[i], xlim=c(0,300), ylim=c(0,100), type="l")
    par(new=T)
    plot(RSI[srch:trade], xlab=Time[i], ylab=X[i], xlim=c(0,300), ylim=c(0,100), type="l", col="lightgreen")
    i <- i + 72
  
  
  }
}

print(c(z,y))
## [1] 454 476
print(z <- Sys.time())
## [1] "2015-01-09 10:33:49 JST"