RicardoSantos

[RS]ZigZag (MA, ABC%) V1

Experimental: Method to read ABC% pattern rates from a zigzag
开源脚本

本着真正的TradingView精神,该脚本的作者将其开源发布,以便交易者可以理解和验证它。为作者喝彩!您可以免费使用它,但在出版物中重复使用此代码受网站规则的约束。 您可以收藏它以在图表上使用。

免责声明

这些信息和出版物并不意味着也不构成TradingView提供或认可的金融、投资、交易或其它类型的建议或背书。请在使用条款阅读更多信息。

想在图表上使用此脚本?
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)