This rough code identify HL HH LH LL from zigzag.
Since the internal instruction of the platform uses only one price value to calculate the zigzag, I used 2 instructions at a time, one to identify the peaks (High) and another one for the troughs (Low). Then, to draw the segments, and as we do it by advancing in the history, to draw a new low, the previous point must be a peak, except that sometimes it is not the case if the price did not go high enough for example to form a peak, so that is why we can see several successive low points (same goes for high points). In this case only the first point is identified.
To check if a trend is reversed we can start from this first test by checking the last identifications.
percent = 0.5
zzh = ZigZag[percent](high)
zzl = zigzag[percent](low)
itop = 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 itop 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