xmd79

Levels High Low

Oct 12th, 2021
125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.69 KB | None | 0 0
  1. // This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
  2. // © nikfilippov05
  3.  
  4. //@version=4
  5. study("Levels High Low", shorttitle="Levels High Low", overlay=true, max_bars_back = 5000, max_lines_count = 500, max_labels_count = 500)
  6.  
  7. lenH = input(title="Length High", type=input.integer, defval=20, minval=1)
  8. lenL = input(title="Length Low", type=input.integer, defval=20, minval=1)
  9. var high_label = array.new_label()
  10. var low_label = array.new_label()
  11. var high_array_lines = array.new_line()
  12. var low_array_lines = array.new_line()
  13. var high_line = close
  14. var low_line = close
  15.  
  16.  
  17. fun(src, len, isHigh, _style, _yloc, _color, array_label, array_lines) =>
  18. p = nz(src[len])
  19. isFound = true
  20. for i = 0 to len - 1
  21. if isHigh and src[i] > p
  22. isFound := false
  23.  
  24. if not isHigh and src[i] < p
  25. isFound := false
  26.  
  27. for i = len + 1 to 2 * len
  28. if isHigh and src[i] >= p
  29. isFound := false
  30.  
  31. if not isHigh and src[i] <= p
  32. isFound := false
  33.  
  34. if isFound
  35. array.push(array_label, label.new(bar_index[len], p, tostring(p), style=_style, yloc=_yloc, color=_color))
  36. array.push(array_lines, line.new(bar_index[len], p, bar_index, p, color=_color, extend=extend.right))
  37. if array.size(array_label) > 1
  38. for i = 1 to array.size(array_label) - 1
  39. if label.get_y(array.get(array_label, array.size(array_label) - 1)) > label.get_y(array.get(array_label, i - 1)) and src == high
  40. label.delete(array.get(array_label, i - 1))
  41. line.delete(array.get(array_lines, i - 1))
  42. if label.get_y(array.get(array_label, array.size(array_label) - 1)) < label.get_y(array.get(array_label, i - 1)) and src == low
  43. label.delete(array.get(array_label, i - 1))
  44. line.delete(array.get(array_lines, i - 1))
  45.  
  46. if array.size(array_label) > 1
  47. if label.get_y(array.get(array_label, array.size(array_label) - 1)) < high and src == high
  48. label.delete(array.get(array_label, array.size(array_label) - 1))
  49. line.delete(array.get(array_lines, array.size(array_label) - 1))
  50. if label.get_y(array.get(array_label, array.size(array_label) - 1)) > low and src == low
  51. label.delete(array.get(array_label, array.size(array_label) - 1))
  52. line.delete(array.get(array_lines, array.size(array_label) - 1))
  53.  
  54.  
  55. fun(high, lenH, true, label.style_label_down, yloc.abovebar, color.lime, high_label, high_array_lines)
  56. fun(low, lenL, false, label.style_label_up, yloc.belowbar, color.red, low_label, low_array_lines)
Advertisement
Add Comment
Please, Sign In to add comment