AnthonyAlexander

zig zag length function

Jan 17th, 2019
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.45 KB | None | 0 0
  1. //@version=3
  2. study("Ziggidy-Zaggedy", overlay = true)
  3.  
  4. zig1 = "Zig-Zag #1"
  5. zig2 = "Zig-Zag #2"
  6. zig3 = "Zig-Zag #3"
  7.  
  8. zig0 = input(zig1, "Zig-Zag Type", options = [zig1, zig2, zig3])
  9.  
  10. len0 = input(1, "Length")
  11.  
  12. zigzag(_len) =>
  13. _isUp = close >= open
  14. _isDown = close <= open
  15. _direction = 0.0
  16. _direction := _isUp[_len] and _isDown ? -1 : _isDown[_len] and _isUp ? 1 : nz(_direction[_len])
  17. _zigzag = _isUp[_len] and _isDown and _direction[_len] != -1 ? highest(2) : _isDown[_len] and _isUp and _direction[_len] != 1 ? lowest(2) : na
  18.  
  19. zzigzag(_len) =>
  20. _isUp = close >= open
  21. _isDown = close <= open
  22. _direction = 0.0
  23. _direction := _isUp[_len] and _isDown ? -_len : _isDown[_len] and _isUp ? _len : nz(_direction[_len])
  24. _zigzag = _isUp[_len] and _isDown and _direction[_len] != -_len ? highest(2) : _isDown[_len] and _isUp and _direction[_len] != _len ? lowest(2) : na
  25.  
  26. zzzigzag(_len) =>
  27. _isUp = close >= open
  28. _isDown = close <= open
  29. _direction = 0.0
  30. _direction := _isUp[_len] and _isDown ? -_len : _isDown[_len] and _isUp ? _len : nz(_direction[_len])
  31. _zigzag = _isUp[_len] and _isDown and _direction[_len] != -_len ? highest(_len * 2) : _isDown[_len] and _isUp and _direction[_len] != _len ? lowest(_len * 2) : na
  32.  
  33. plot(zig0 == zig1 ? zigzag(len0) : na, "Zig-Zag #1", blue)
  34. plot(zig0 == zig2 ? zzigzag(len0) : na, "Zig-Zag #2", red)
  35. plot(zig0 == zig3 ? zzzigzag(len0) : na, "Zig-Zag #3", green)
Advertisement
Add Comment
Please, Sign In to add comment