percent = 0.5
zzh = ZigZag[percent](high)
zzl = zigzag[percent](low)
top = zzh<zzh[1] and zzh[1]>zzh[2]
bot = zzl>zzl[1] and zzl[1]<zzl[2]
once lastzz=1
atr = averagetruerange[10]
//peaks
if top then
//segment
if lastzz<0 then
drawsegment(barindex[1],zzh[1],prevlbar,prevl)
//LH
if zzh[1]<prevh then
drawtext("LH",barindex[1],zzh[1]+atr/2,dialog,bold,16)
else
//HH
drawtext("HH",barindex[1],zzh[1]+atr/2,dialog,bold,16)
endif
else
drawsegment(barindex[1],zzh[1],prevhbar,prevh)
endif
lastzz=1
prevhbar=barindex[1]
prevh=zzh[1]
endif
//troughs
if bot then
//segment
if lastzz>0 then
drawsegment(barindex[1],zzl[1],prevhbar,prevh)
//HL
if zzl[1]>prevl then
drawtext("HL",barindex[1],zzl[1]-atr/2,dialog,bold,16)
else
//LL
drawtext("LL",barindex[1],zzl[1]-atr/2,dialog,bold,16)
endif
else
drawsegment(barindex[1],zzl[1],prevlbar,prevl)
endif
lastzz=-1
prevlbar=barindex[1]
prevl=zzl[1]
endif
return