6

i'm currently using quantmod ZigZag overlay and i noticed it is calculated a bit differently then the original overlay. I've demonstrated the difference in the following picture of RDWR using ZigZag(5%) with quantmod and a with a different program. as you can see quantmod is missing allot of significant points peaks and highs. you can also see the difference pretty clearly when using StockCharts.

I think it's because of the way quantmod smooth the trend. the algorithm should be using both high & low values and not just an average price or some other regression. i was wondering if quantmod or maybe TTR provide an alternative ZigZag overlay that will produced the desired output (illustrated in the upper part of the picture).

Thanks.

the code for displaying the quantmod output in the picture is

s<-get(getSymbols('rdwr'))["2012-07::"]
chart_Series(s)
add_TA(ZigZag(s,5),on=1)
haki
  • 9,389
  • 15
  • 62
  • 110
  • 2
    FWIW, it works with `chartSeries` like this: `chartSeries(s); addZigZag(5)`, or in one step `chartSeries(s, TA="addZigZag(5)")`. I think there is still some work to be done on the `chart_Series` framework... – GSee Feb 09 '13 at 22:57
  • 1
    Right you are ! z<-na.omit(ZigZag(s,5)); z<-rbind(z[findPeaks(z)],z[findValleys(z)]); z; SOLVED ! (didn't realize they have different implementation for the overlays in the new charting function). BTW, how can i draw the old overlay with chart_Series (@agstudy just solved me another issue by moving to the experimental function) – haki Feb 09 '13 at 23:04

1 Answers1

5

The problem is that ?ZigZag says the input should be a high/low price series and you provided an OHLCVA series. It works correctly if you provide a high/low series.

s <- getSymbols('rdwr', auto.assign=FALSE)
chart_Series(s, subset="2012-07::")
add_TA(ZigZag(s[,2:3],5),on=1)

enter image description here

Joshua Ulrich
  • 173,410
  • 32
  • 338
  • 418
  • +1, but `?ZigZag` is a little ambiguous. It says `HL` should be an "Object that is coercible to xts or matrix and *contains* either a High-Low price series, or a Close price series.". [emphasis added]. Given that quantmod often subsets inputs with things like `HLC`, `Cl`, etc., it's seems reasonable to expect ZigZag to work with an OHLCVA object. – GSee Feb 10 '13 at 16:33
  • @GSee: *sigh* I can see how that might be confusing. – Joshua Ulrich Feb 10 '13 at 16:33