This code snippet is designed to identify and plot the last zigzag highs and lows on a price chart using the ProBuilder programming language. The zigzag pattern is a technical analysis tool used to filter out smaller price movements, making trends easier to spot.
zz = zigzagpoint[15]
lookback = 100
if islastbarupdate then
//find last zigzag tops & bottoms
a=0
unset($zz)
for i = lookback-1 downto 0
itop = zz[i+1]>zz[i+2] and zz[i]zz[i+1]
if itop then
$zz[a]=zz[i+1]
$zzbar[a]=barindex-(i+1)
$zztype[a]=1
lasttop = $zz[a]
a=a+1
endif
if ibottom then
$zz[a]=zz[i+1]
$zzbar[a]=barindex-(i+1)
$zztype[a]=-1
lastbottom = $zz[a]
a=a+1
endif
next
//plot the zigzag tops & bottoms
if a>0 then
for i = 0 to a-1
if $zztype[i]=1 then //is that a top?
drawpoint($zzbar[i],$zz[i],3) coloured("cyan")
else //nope! that's a bottom
drawpoint($zzbar[i],$zz[i],3) coloured("crimson")
endif
next
endif
return lasttop, lastbottom
The code snippet above performs the following steps:
This code is useful for traders or analysts who want to visually identify significant price points and trends in financial markets using automated methods.
Check out this related content for more information:
https://www.prorealcode.com/topic/zigzag-dysfonctionnement/page/2/#post-201122
Visit Link