require(zoo)
## Loading required package: zoo
## 
## Attaching package: 'zoo'
## The following objects are masked from 'package:base':
## 
##     as.Date, as.Date.numeric
require(quantmod)
## Loading required package: quantmod
## Loading required package: xts
## Loading required package: TTR
## Version 0.4-0 included new data defaults. See ?getSymbols.
 which.peaks <- function(x,partial=TRUE,decreasing=FALSE,lag=1){
     if (decreasing){
         if (partial){
             which(diff(c(FALSE,diff(x,lag=lag)>0,TRUE))>0)
         }else {
             which(diff(diff(x,lag=lag)>0)>0)+1
         }
     }else {
         if (partial){
             which(diff(c(TRUE,diff(x,lag=la)>=0,FALSE))<0)
         }else {
             which(diff(diff(x,lag=lag)>=0)<0)+1
         }
     }
 }
#
load("~/git/Gong/power_500.RData")
plot(power_500[,3],type="l")

y=rollmean(power_500[,3],11)
plot(y,type="l")
mp=which.peaks(y,decreasing=TRUE,lag=5)
points(mp,y[mp],col=3)