RicardoSantos

[RS]ZigZag (MA, ABC%) V1

Experimental: Method to read ABC% pattern rates from a zigzag
Script de código abierto

Siguiendo el verdadero espíritu de TradingView, el autor de este script lo ha publicado en código abierto, para que los traders puedan entenderlo y verificarlo. ¡Un hurra por el autor! Puede utilizarlo de forma gratuita, aunque si vuelve a utilizar este código en una publicación, debe cumplir con lo establecido en las Normas internas. Puede añadir este script a sus favoritos y usarlo en un gráfico.

Exención de responsabilidad

La información y las publicaciones que ofrecemos, no implican ni constituyen un asesoramiento financiero, ni de inversión, trading o cualquier otro tipo de consejo o recomendación emitida o respaldada por TradingView. Puede obtener información adicional en las Condiciones de uso.

¿Quiere utilizar este script en un gráfico?
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))
xad = (abs(a-d)/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)