Advertisement
Guest User

Untitled

a guest
Dec 10th, 2018
126
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.55 KB | None | 0 0
  1. study("xabcde", overlay=true)
  2. useAltTF = input(true, title='Use Alt Timeframe')
  3. tf = input('15', title='Alt Timeframe')
  4. showPatterns = input(true, title='Show Patterns')
  5. zigzag() =>
  6. _isUp = close >= open
  7. _isDown = close <= open
  8. _direction = _isUp[1] and _isDown ? -1 : _isDown[1] and _isUp ? 1 : nz(_direction[1])
  9. _zigzag = _isUp[1] and _isDown and _direction[1] != -1 ? highest(2) : _isDown[1] and _isUp and _direction[1] != 1 ? lowest(2) : na
  10.  
  11. sz = useAltTF ? (change(time(tf)) != 0 ? security(tickerid, tf, zigzag()) : na) : zigzag()
  12.  
  13. plot(sz, title='zigzag', color=black, linewidth=2)
  14.  
  15. // ||--- Pattern Recognition:
  16.  
  17. x = valuewhen(sz, sz, 5)
  18. a = valuewhen(sz, sz, 4)
  19. b = valuewhen(sz, sz, 3)
  20. c = valuewhen(sz, sz, 2)
  21. d = valuewhen(sz, sz, 1)
  22. e = valuewhen(sz, sz, 0)
  23.  
  24. xab = (abs(b-a)/abs(x-a))
  25. xad = (abs(a-d)/abs(x-a))
  26. abc = (abs(b-c)/abs(a-b))
  27. bcd = (abs(c-d)/abs(b-c))
  28. cde = (abs(d-e)/abs(c-d))
  29.  
  30. // ||--> Functions:
  31.  
  32. isHnS(_mode)=>
  33. _xab = xab >= 2.0 and xab <= 10
  34. _abc = abc >= 0.90 and abc <= 1.1
  35. _bcd = bcd >= 0.236 and bcd <= 0.88
  36. _xad = xad >= 0.90 and xad <= 1.1
  37. _xab and _abc and _bcd and _xad and (_mode == 1 ? d < c : d > c)
  38.  
  39.  
  40. 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)
  41. 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