Guest User

Von ZigZag

a guest
Apr 25th, 2021
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.46 KB | None | 0 0
  1. //@version=4
  2. study("Zig Zag High Low", overlay = true)
  3. length = input(4, title = "High/Low length")
  4. h = highest(high, length * 2 + 1)
  5. l = lowest(low, length * 2 + 1)
  6. f_isMin(len) =>
  7. l == low[len]
  8. f_isMax(len) =>
  9. h == high[len]
  10.  
  11. var dirUp = false
  12. var lastLow = high * 100
  13. var lastHigh = 0.0
  14. var timeLow = bar_index
  15. var timeHigh = bar_index
  16. var line li = na
  17. f_drawLine() =>
  18. _li_color = dirUp ? color.teal : color.orange
  19. line.new(
  20. timeHigh - length, lastHigh,
  21. timeLow - length, lastLow,
  22. xloc.bar_index, color=_li_color, width=2
  23. )
  24.  
  25. if dirUp
  26. if (f_isMin(length) and low[length] < lastLow)
  27. lastLow := low[length]
  28. timeLow := bar_index
  29. line.delete(li)
  30. li := f_drawLine()
  31.  
  32. if (f_isMax(length) and high[length] > lastLow)
  33. lastHigh := high[length]
  34. timeHigh := bar_index
  35. dirUp := false
  36. li := f_drawLine()
  37.  
  38. if not dirUp
  39. if (f_isMax(length) and high[length] > lastHigh)
  40. lastHigh := high[length]
  41. timeHigh := bar_index
  42. line.delete(li)
  43. li := f_drawLine()
  44. if f_isMin(length) and low[length] < lastHigh
  45. lastLow := low[length]
  46. timeLow := bar_index
  47. dirUp := true
  48. li := f_drawLine()
  49. if (f_isMax(length) and high[length] > lastLow)
  50. lastHigh := high[length]
  51. timeHigh := bar_index
  52. dirUp := false
  53. li := f_drawLine()
  54.  
Advertisement
Add Comment
Please, Sign In to add comment