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)