Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- study("xabcde", overlay=true)
- useAltTF = input(true, title='Use Alt Timeframe')
- tf = input('15', title='Alt Timeframe')
- showPatterns = input(true, title='Show Patterns')
- zigzag() =>
- _isUp = close >= open
- _isDown = close <= open
- _direction = _isUp[1] and _isDown ? -1 : _isDown[1] and _isUp ? 1 : nz(_direction[1])
- _zigzag = _isUp[1] and _isDown and _direction[1] != -1 ? highest(2) : _isDown[1] and _isUp and _direction[1] != 1 ? lowest(2) : na
- sz = useAltTF ? (change(time(tf)) != 0 ? security(tickerid, tf, zigzag()) : na) : zigzag()
- plot(sz, title='zigzag', color=black, linewidth=2)
- // ||--- Pattern Recognition:
- x = valuewhen(sz, sz, 5)
- a = valuewhen(sz, sz, 4)
- b = valuewhen(sz, sz, 3)
- c = valuewhen(sz, sz, 2)
- d = valuewhen(sz, sz, 1)
- e = valuewhen(sz, sz, 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))
- cde = (abs(d-e)/abs(c-d))
- // ||--> Functions:
- isHnS(_mode)=>
- _xab = xab >= 2.0 and xab <= 10
- _abc = abc >= 0.90 and abc <= 1.1
- _bcd = bcd >= 0.236 and bcd <= 0.88
- _xad = xad >= 0.90 and xad <= 1.1
- _xab and _abc and _bcd and _xad and (_mode == 1 ? d < c : d > c)
- plotshape(not showPatterns ? na : isHnS(-1) and not isHnS(-1)[1], text="Head and Shoulders", style=shape.labeldown, color=maroon, textcolor=white, location=location.top, transp=0)
- plotshape(not showPatterns ? na : isHnS(1) and not isHnS(1)[1], text="Head and Shoulders", style=shape.labelup, color=green, textcolor=white, location=location.bottom, transp=0)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement