xmd79

High Low Open Mid Ranges

Oct 3rd, 2021
138
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.94 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. // © Shanxia
  3.  
  4. //@version=4
  5. study("High Low Open Mid Ranges", shorttitle="OHLM", overlay=true)
  6.  
  7.  
  8. higherTF = input("W", "Timeframe", input.resolution)
  9.  
  10. lstyle1 = input("Dotted", "Linestyles", options=["Dotted", "Solid", "Dashed"], inline="in2")
  11. style1 = lstyle1 == "Dotted" ? line.style_dotted : lstyle1 == "Solid" ? line.style_solid : line.style_dashed
  12. lstyle2 = input("Solid", "", options=["Dotted", "Solid", "Dashed"], inline="in2")
  13. style2 = lstyle2 == "Dotted" ? line.style_dotted : lstyle2 == "Solid" ? line.style_solid : line.style_dashed
  14.  
  15. my_color = input(color.aqua, "Line Color", input.color, inline="in1")
  16. txtcol = input(color.new(color.white, 10), "Text color", input.color, inline="in1")
  17.  
  18.  
  19. ex = input("Right", "Extend", options=["Right", "None"], inline="in3")
  20. ex1 = ex == "Right" ? extend.right : extend.none
  21. lwidth = input("2", "Width", options=["1", "2", "3", "4", "5"], inline="in3")
  22. width = lwidth == "1" ? 1 : lwidth == "2" ? 2 : lwidth == "3" ? 3 : lwidth == "4" ? 4 : 5
  23.  
  24. inp = input(true, "Price", input.bool, inline="in4")
  25. inpoff = input(15, " | Offset", inline="in4")
  26.  
  27. i_q = input(false, "Quarters | ", input.bool, inline="in5")
  28. i_t = input(true, "Table", input.bool, inline="in5")
  29.  
  30. var string title2 = "Table Options"
  31.  
  32. op1 = input("BRight", "Position", options=["BRight", "BLeft", "TRight", "TLeft"], group=title2, inline="in6")
  33. op1a = op1 == "BRight" ? position.bottom_right : op1 == "BLeft" ? position.bottom_left : op1 == "TRight" ? position.top_right : op1 == "TLeft" ? position.top_left : na
  34.  
  35. op2 = input("Normal", "Size", options=["Auto", "Tiny", "Small", "Normal", "Large", "Huge"], group=title2, inline="in6")
  36. op2a = op2 == "Normal" ? size.normal : op2 == "Tiny" ? size.tiny : op2 == "Normal" ? size.normal : op2 == "Small" ? size.small : op2 == "Large" ? size.large : op2 == "Huge" ? size.huge : op2 == "Auto" ? size.auto : na
  37.  
  38. op3 = input("1", "Border Width", options=["1", "2", "3", "4"], group=title2, inline="in7")
  39. op3a = op3 == "1" ? 1 : op3 == "2" ? 2 : op3 == "3" ? 3 : op3 == "4" ? 4 : na
  40. op4 = input(#388cff, "|", input.color, group=title2, inline="in7")
  41.  
  42. op5 = input(color.new(#000000, 20), "Colors", input.color, group=title2, inline="in8")
  43. op6 = input(color.new(color.navy, 20), "", input.color, group=title2, inline="in8")
  44.  
  45. op7 = input(color.new(color.white, 10), "|", input.color, group=title2, inline="in8")
  46. op8 = input(color.new(color.white,10), "", input.color, group=title2, inline="in8")
  47.  
  48.  
  49. ///
  50. i_mid = security(syminfo.tickerid, higherTF, hl2, lookahead=true)
  51. i_open = security(syminfo.tickerid, higherTF, open, lookahead=true)
  52. i_high = security(syminfo.tickerid, higherTF, high, lookahead=true)
  53. i_low = security(syminfo.tickerid, higherTF, low, lookahead=true)
  54. tq = (i_high + i_mid) / 2
  55. bq = (i_mid + i_low) / 2
  56.  
  57. L_mid = i_mid
  58. L_open = i_open
  59. L_high = i_high
  60. L_low = i_low
  61. tql = tq
  62. bql = bq
  63.  
  64.  
  65. var line v_open = na
  66. var line v_mid = na
  67. var line v_high = na
  68. var line v_low = na
  69.  
  70. var line qline1 = na
  71. var line qline2 = na
  72.  
  73.  
  74.  
  75.  
  76. if L_low[1] != L_low
  77. line.set_x2(v_open, bar_index)
  78. line.set_x2(v_mid, bar_index)
  79. line.set_x2(v_high, bar_index)
  80. line.set_x2(v_low, bar_index)
  81.  
  82. line.set_extend(v_open, extend.none)
  83. line.set_extend(v_mid, extend.none)
  84. line.set_extend(v_high, extend.none)
  85. line.set_extend(v_low, extend.none)
  86.  
  87. line.set_style(v_open, style1)
  88. line.set_style(v_mid, style1)
  89. line.set_style(v_high, style1)
  90. line.set_style(v_low, style1)
  91.  
  92. v_open := line.new(bar_index, L_open, bar_index + 1, L_open, width= width, extend=ex1, style=style2, color=my_color)
  93. v_mid := line.new(bar_index, L_mid, bar_index + 1, L_mid, width= width, extend=ex1, style=style2, color=my_color)
  94. v_high := line.new(bar_index, L_high, bar_index + 1, L_high, width= width,extend=ex1, style=style2, color=my_color)
  95. v_low := line.new(bar_index, L_low, bar_index + 1, L_low, width= width, extend=ex1, style=style2, color=my_color)
  96. label.new(bar_index[1], L_open[1], inp ? "O | " + tostring(L_open[1]) : "O", style=label.style_none, textcolor=txtcol)
  97. label.new(bar_index[1], L_mid[1], inp ? "M | " + tostring(L_mid[1]) : "M", style=label.style_none, textcolor=txtcol)
  98. label.new(bar_index[1], L_high[1], inp ? "H | " + tostring(L_high[1]) : "H", style=label.style_none, textcolor=txtcol)
  99. label.new(bar_index[1], L_low[1], inp ? "L | " + tostring(L_low[1]) : "L", style=label.style_none, textcolor=txtcol)
  100.  
  101. if L_low[1] != L_low and i_q
  102. line.set_x2(qline1, bar_index)
  103. line.set_x2(qline2, bar_index)
  104.  
  105. line.set_extend(qline1, extend.none)
  106. line.set_extend(qline2, extend.none)
  107.  
  108. line.set_style(qline2, style1)
  109. line.set_style(qline1, style1)
  110.  
  111. qline1 := line.new(bar_index, tql, bar_index + 1, tql, width= width, extend=ex1, style=style2, color=my_color)
  112. qline2 := line.new(bar_index, bql, bar_index + 1, bql, width= width, extend=ex1, style=style2, color=my_color)
  113. label.new(bar_index[1], tql[1], inp ? "TQ | " + tostring(tql[1]) : "TQ", style=label.style_none, textcolor=txtcol)
  114. label.new(bar_index[1], bql[1], inp ? "BQ | " + tostring(bql[1]) : "BQ", style=label.style_none, textcolor=txtcol)
  115.  
  116.  
  117. lb1 = label.new(bar_index + inpoff, L_mid, inp ? higherTF+ " | Mid | " + tostring(L_mid) : higherTF + " | Mid", textcolor=txtcol, style=label.style_none)
  118. label.delete(lb1[1])
  119.  
  120. lb2 = label.new(bar_index + inpoff, L_open, inp ? higherTF+ " | Open | " + tostring(L_open) : higherTF + " | Open", textcolor=txtcol, style=label.style_none)
  121. label.delete(lb2[1])
  122.  
  123. lb3 = label.new(bar_index + inpoff, L_high, inp ? higherTF+ " | High | " + tostring(L_high) : higherTF + " | High", textcolor=txtcol, style=label.style_none)
  124. label.delete(lb3[1])
  125.  
  126. lb4 = label.new(bar_index + inpoff, L_low, inp ? higherTF+ " | Low | " + tostring(L_low) : higherTF + " | Low" , textcolor=txtcol, style=label.style_none)
  127. label.delete(lb4[1])
  128.  
  129. if i_q
  130. lb5 = label.new(bar_index + inpoff, tql, inp ? higherTF+ " | TQ | " + tostring(tql) : higherTF + " | TQ", textcolor=txtcol, style=label.style_none)
  131. label.delete(lb5[1])
  132.  
  133. lb6 = label.new(bar_index + inpoff, bql, inp ? higherTF+ " | BQ | " + tostring(bql) : higherTF + " | BQ" , textcolor=txtcol, style=label.style_none)
  134. label.delete(lb6[1])
  135.  
  136. if not na(v_low) and line.get_x2(v_low) != bar_index
  137. line.set_x2(v_open, bar_index)
  138. line.set_x2(v_mid, bar_index)
  139. line.set_x2(v_high, bar_index)
  140. line.set_x2(v_low, bar_index)
  141.  
  142. if not na(v_low) and line.get_x2(v_low) and tq != bar_index
  143. line.set_x2(qline1, bar_index)
  144. line.set_x2(qline2, bar_index)
  145.  
  146.  
  147. //table
  148.  
  149. var table pan = table.new(op1a, 5, 10, color.new(color.blue,100), i_t ? op4 : na, op3a, i_t ? op4 : na, op3a)
  150.  
  151. tc(x,y,z) =>
  152. table.cell(pan, x, y, z, text_color=op7, bgcolor=op5, text_size=op2a)
  153.  
  154. ts(v, w, x, y) =>
  155. z = security(syminfo.tickerid, v, w, lookahead=true )
  156. table.cell(pan, x, y, tostring(z), text_color=op8, bgcolor=op6, text_size=op2a)
  157. if i_t
  158. tc(0,0,"TF"), tc(1,0,"Open"), tc(2, 0, "High"), tc(3,0, "Low"), tc(4, 0, "Mid"), tc(0, 1, "D"), tc(0, 2, "YD"), tc(0,3,"W"), tc(0,4, "LW"), tc(0,5, "M"), tc(0,6,"LM"), tc(0,7,"Q"), tc(0,8,"LQ")
  159.  
  160. ts('D', open, 1,1), ts('D', high, 2,1), ts('D', low, 3,1), ts('D', hl2, 4,1)
  161. ts('D', open[1], 1,2), ts('D', high[1], 2,2), ts('D', low[1], 3,2), ts('D', hl2[1], 4,2)
  162.  
  163. ts('W', open, 1,3), ts('W', high, 2,3), ts('W', low, 3,3), ts('W', hl2, 4,3)
  164. ts('W', open[1], 1,4), ts('W', high[1], 2,4), ts('W', low[1], 3,4), ts('W', hl2[1], 4,4)
  165.  
  166. ts('M', open, 1,5), ts('M', high, 2,5), ts('M', low, 3,5), ts('M', hl2, 4,5)
  167. ts('M', open[1], 1,6), ts('M', high[1], 2,6), ts('M', low[1], 3,6), ts('M', hl2[1], 4,6)
  168.  
  169. ts('3M', open, 1,7), ts('3M', high, 2,7), ts('3M', low, 3,7), ts('3M', hl2, 4,7)
  170. ts('3M', open[1], 1,8), ts('3M', high[1], 2,8), ts('3M', low[1], 3,8), ts('3M', hl2[1], 4,8)
  171.  
  172.  
  173.  
Advertisement
Add Comment
Please, Sign In to add comment