Advertisement
xmd79

TMB Levels

May 18th, 2024
222
1
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.18 KB | None | 1 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. // © sabricat
  3.  
  4. //@version=5
  5. indicator("TMB Levels", overlay=true, max_lines_count=500, max_labels_count=500)
  6.  
  7. tf = input.string("60", "Timeframe")
  8. src = input.string('High & Low', options=['High & Low', 'Open & Close'], title='Source')
  9.  
  10. hi_show = input.bool(true, "Top                      ", inline="high")
  11. hi_col = input.color(color.green, title="", inline="high")
  12. hi_width = input.int(1, "Width", inline="high")
  13. hi_style = input.string("Dashed", "", ["Solid", "Dashed", "Dotted"], inline="high")
  14.  
  15. mi_show = input.bool(true, "Mid                      ", inline="mid")
  16. mi_col = input.color(color.blue, title="", inline="mid")
  17. mi_width = input.int(2, "Width", inline="mid")
  18. mi_style = input.string("Solid", "", ["Solid", "Dashed", "Dotted"], inline="mid")
  19.  
  20. lo_show = input.bool(true, "Bottom         ", inline="low")
  21. lo_col = input.color(color.red, title="", inline="low")
  22. lo_width = input.int(1, "Width", inline="low")
  23. lo_style = input.string("Dashed", "", ["Solid", "Dashed", "Dotted"], inline="low")
  24.  
  25. co_show = input.bool(true, "Line chart", inline="line_chart")
  26. co_col = input.color(color.yellow, title="", inline="line_chart")
  27. co_width = input.int(2, "Width", inline="line_chart")
  28. co_style = input.string("Solid", "", ["Solid", "Dashed", "Dotted"], inline="line_chart")
  29.  
  30. f(src) =>
  31. v_ = src == 'High & Low' ? ((high - low) / 2 + low) : (math.abs((close - open) / 2) + math.min(close, open))
  32. lh_ = src == 'High & Low' ? high : math.max(open, close)
  33. ll_ = src == 'High & Low' ? low : math.min(open, close)
  34. [v_, lh_, ll_]
  35.  
  36. get_line_style(style_) =>
  37. switch style_
  38. "Solid" => line.style_solid
  39. "Dashed" => line.style_dashed
  40. "Dotted" => line.style_dotted
  41.  
  42. [v, lh, ll] = request.security(syminfo.tickerid, tf, f(src))
  43. changed = ta.change(time(tf)) != 0
  44.  
  45. var int last_mid_time = na
  46. var float last_mid_price = na
  47. var line li = na
  48. var line lih = na
  49. var line lil = na
  50. var line lic = na
  51.  
  52. if not na(lih)
  53. if hi_show
  54. lih.set_y1(lh)
  55. lih.set_y2(lh)
  56. lih.set_x2(time)
  57. if not na(li)
  58. if mi_show
  59. li.set_y1(v)
  60. li.set_y2(v)
  61. li.set_x2(time)
  62. if not na(lil)
  63. if lo_show
  64. lil.set_y1(ll)
  65. lil.set_y2(ll)
  66. lil.set_x2(time)
  67. if not na(lic)
  68. if co_show
  69. lic.set_y2(v)
  70. lic.set_x2(time)
  71.  
  72. if changed
  73. last_mid_time := time
  74. last_mid_price := v
  75. if hi_show
  76. lih := line.new(time, lh, time, lh, xloc=xloc.bar_time, width=hi_width, color=hi_col, style=get_line_style(hi_style))
  77. if mi_show
  78. li := line.new(time, v, time, v, xloc=xloc.bar_time, width=mi_width, color=mi_col, style=get_line_style(mi_style))
  79. if lo_show
  80. lil := line.new(time, ll, time, ll, xloc=xloc.bar_time, width=lo_width, color=lo_col, style=get_line_style(lo_style))
  81. if co_show
  82. lic := line.new(last_mid_time, last_mid_price, time, v, xloc=xloc.bar_time, width=co_width, color=co_col, style=get_line_style(co_style))
  83.  
  84.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement