# [RS]ZigZag (MA, ABC%) V1

180 0
Experimental: Method to read ABC% pattern rates from a zigzag
```study("[RS]ZigZag (MA, ABC%) V1", overlay=true)
length = input(4)
showBasis = input(false)
hls = rma(hl2, length)

plot(not showBasis ? na : hls, color=black)
isRising = hls >= hls[1]

zigzag = isRising and not isRising[1] ? lowest(length) :  not isRising and isRising[1] ? highest(length) : na
plot(zigzag, color=black)

//  ||-->   Bands:
upper = not isRising and isRising[1] ? highest(length) : na
lower = isRising and not isRising[1] ? lowest(length) : na
plot(upper, color=black)
plot(lower, color=black)

//  ||---   Pattern Recognition:

//istop() => zigzag == filteredtopf
//isbot() => zigzag == filteredbotf

x = valuewhen(zigzag, zigzag, 4)
a = valuewhen(zigzag, zigzag, 3)
b = valuewhen(zigzag, zigzag, 2)
c = valuewhen(zigzag, zigzag, 1)
d = valuewhen(zigzag, zigzag, 0)

xab = (abs(b-a)/abs(x-a))
abc = (abs(b-c)/abs(a-b))
bcd = (abs(c-d)/abs(b-c))

//  ||-->   Functions:
isABC_rate(_mode)=> (_mode == 1 ? d < c : d > c)

plotshape(bcd > 0 and bcd <= 0.5 and isABC_rate(-1) and not isABC_rate(-1)[1], text="0%+", style=shape.labeldown, color=maroon, textcolor=white, location=location.top, transp=0, offset=-2)
plotshape(bcd > 0.5 and bcd <= 1 and isABC_rate(-1) and not isABC_rate(-1)[1], text="50%+", style=shape.labeldown, color=maroon, textcolor=white, location=location.top, transp=0, offset=-2)
plotshape(bcd > 1 and bcd <= 2 and isABC_rate(-1) and not isABC_rate(-1)[1], text="100%+", style=shape.labeldown, color=maroon, textcolor=white, location=location.top, transp=0, offset=-2)
plotshape(bcd > 2 and bcd <= 3 and isABC_rate(-1) and not isABC_rate(-1)[1], text="200%+", style=shape.labeldown, color=maroon, textcolor=white, location=location.top, transp=0, offset=-2)
plotshape(bcd > 3 and bcd <= 4 and isABC_rate(-1) and not isABC_rate(-1)[1], text="300%+", style=shape.labeldown, color=maroon, textcolor=white, location=location.top, transp=0, offset=-2)
plotshape(bcd > 4 and bcd <= 10 and isABC_rate(-1) and not isABC_rate(-1)[1], text="400%+", style=shape.labeldown, color=maroon, textcolor=white, location=location.top, transp=0, offset=-2)

plotshape(bcd > 0 and bcd <= 0.5 and isABC_rate(1) and not isABC_rate(1)[1], text="0%+", style=shape.labelup, color=green, textcolor=white, location=location.bottom, transp=0)
plotshape(bcd > 0.5 and bcd <= 1 and isABC_rate(1) and not isABC_rate(1)[1], text="50%+", style=shape.labelup, color=green, textcolor=white, location=location.bottom, transp=0)
plotshape(bcd > 1 and bcd <= 2 and isABC_rate(1) and not isABC_rate(1)[1], text="100%+", style=shape.labelup, color=green, textcolor=white, location=location.bottom, transp=0)
plotshape(bcd > 2 and bcd <= 3 and isABC_rate(1) and not isABC_rate(1)[1], text="200%+", style=shape.labelup, color=green, textcolor=white, location=location.bottom, transp=0)
plotshape(bcd > 3 and bcd <= 4 and isABC_rate(1) and not isABC_rate(1)[1], text="300%+", style=shape.labelup, color=green, textcolor=white, location=location.bottom, transp=0)
plotshape(bcd > 4 and bcd <= 10 and isABC_rate(1) and not isABC_rate(1)[1], text="400%+", style=shape.labelup, color=green, textcolor=white, location=location.bottom, transp=0)
```
EN English
EN English (UK)
EN English (IN)
DE Deutsch
FR Français
ES Español
IT Italiano
PL Polski
SV Svenska
TR Türkçe
RU Русский
PT Português
ID Bahasa Indonesia
MS Bahasa Melayu
TH ภาษาไทย
VI Tiếng Việt
JA 日本語
KO 한국어
ZH 简体中文
ZH 繁體中文
AR العربية
Home Stock Screener Forex Signal Finder Cryptocurrency Signal Finder Economic Calendar How It Works Chart Features House Rules Moderators Website & Broker Solutions Widgets Stock Charting Library Feature Request Blog & News FAQ Help & Wiki Twitter