how to count zigzag moves
Forums › ProRealTime English forum › ProBuilder support › how to count zigzag moves
- This topic has 4 replies, 3 voices, and was last updated 11 months ago by robertogozzi.
-
-
05/22/2023 at 4:59 PM #215033
Hi
I would like to count the quantity of zigzag moves of an index/security of a chart
ex: zigzag moves of 5% of the SPX index
I have tried a few things but what I get is kind strange, is it possible? The last attempt was this one but it gives an error message (the following variable is undefined: count )
thank you
a= ZigZagPoint[10](close)
b=count[a]
c=cumsum (b)
return c05/22/2023 at 6:33 PM #215034Firstly, COUNT is not defined anywhere thus can’t be used.
Secondly, ZIGZAG returns a value each bar, it doesn’t count swing points, so counting it will return a huge number.
Thirdly, you can count swing points with this code, but it’s useless as it’s a repainting, so it may change any swing point several bars after they have already been counted as you will easily spot on a 1-second TF (see my attached pic):
12345678ONCE Count = 0myZZ = ZigZagPoint[10](close)SwingHI = (myZZ < myZZ[1]) AND (myZZ[1] > myZZ[2])SwingLO = (myZZ > myZZ[1]) AND (myZZ[1] < myZZ[2])IF SwingHI OR SwingLO THENc = c + 1ENDIFreturn c AS "Count"05/22/2023 at 6:34 PM #215036(Sorry same time as Roberto)
Hi,
You can try this one…
I think the calculation of the ZigZag is incorrect, for example if I set a 5% change (from bottom to top or vice versa) then the number of change (points) is incorrect…??
ZigZag Count12345678910111213PercentChange=5ZZ=ZigZag[PercentChange](Close)If ZZ[1]<ZZ[2] and ZZ>ZZ[1] thenBottomCount=BottomCount+1ElsIf ZZ[1]>ZZ[2] and ZZ<ZZ[1] thenTopCount=TopCount+1EndIfTotalCount=BottomCount+TopCountReturn BottomCount as "BottomCount", TopCount as "TopCount", TotalCount as "TotalCount"05/23/2023 at 5:18 AM #215045Thank you it works, just return totalcount
1234567891011121314151617PercentChange=5ZZ=ZigZag[PercentChange](Close)If ZZ[1]<ZZ[2] and ZZ>ZZ[1] thenBottomCount=BottomCount+1ElsIf ZZ[1]>ZZ[2] and ZZ<ZZ[1] thenTopCount=TopCount+1EndIfTotalCount=BottomCount+TopCountReturn BottomCount as "BottomCount", TopCount as "TopCount", TotalCount as "TotalCount"05/23/2023 at 11:25 AM #215058 -
AuthorPosts