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)