title: ZigZag Indicator in R
body: <p>I have some simple R code that reads a list of stocks prices. I would like to plot the ZigZag indicator, highlight all the inflection points, and print out the value of the last three inflection points. This is supposed to do that, but it doesn't work properly.  Any ideas why?</p>
  
  <pre><code>library(TTR)
  
  mydata &lt;-read.csv("EURUSD.csv", sep=",",header=TRUE)
  
  attach(mydata)
  
  plot(BAR, PRICE)
  
  zz &lt;- ZigZag(PRICE, change = 5, percent = TRUE)
  
  lines(zz, col = "blue")
  
  #get the inflection points
  infl &lt;- c( FALSE, diff(diff(zz)&gt;0)!=0   )
  points(mydata$BAR[infl ], mydata$PRICE[infl ], col="red")
  
  #print the last 3 inflection points
  print( tail(mydata$PRICE[infl],1) )
  print( tail(mydata$PRICE[infl],2) )
  print( tail(mydata$PRICE[infl],3) )
  </code></pre>