xmd79

Opening Range with Infinite Price Targets

Jan 5th, 2023
251
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.77 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. // © SamRecio
  3.  
  4. //@version=5
  5. indicator("Opening Range with Infinite Price Targets",shorttitle = "|OR|", overlay = true, max_labels_count = 500, max_lines_count = 500, max_bars_back = 5000)
  6.  
  7. tog_hist = input.bool(false,"Display Historical Data?", inline = "1", group = "Settings")
  8. start_hour = input.int(9,minval = 0,maxval = 23, group = "Range Time", title ="Start Time:", inline = "1")
  9. start_min = input.int(30,minval = 0,maxval = 59, group = "Range Time", title ="", inline = "1")
  10. end_hour = input.int(9,minval = 0,maxval = 23, group = "Range Time", title = "End Time:  ", inline = "2")
  11. end_min = input.int(45,minval = 0,maxval = 59, group = "Range Time", title ="", inline = "2")
  12. target_p = input.float(50,title = "                      Price Target %", minval = 0, tooltip = "Percent(%) of Range to use for Price Targets.")*0.01
  13.  
  14. color1 = input.color(#0c3299, title = "High", group = "Colors", inline = "1")
  15. color2 = input.color(#0c3299, title = "Low", group = "Colors", inline = "1")
  16. color3 = input.color(#3179f5, title = "Mean", group = "Colors", inline = "1")
  17. colorf = input.color(color.new(#3179f5,95), title = "Fill", group = "Colors", inline = "1")
  18. colorg = color.rgb(0,255,0)
  19. colorr = color.rgb(255,0,0)
  20. color4 = input.color(#bbd9fb, title = "Targets", group = "Colors", inline = "2")
  21.  
  22.  
  23. start_time = start_hour + (start_min*0.01)
  24. end_time = end_hour + (end_min*0.01)
  25.  
  26.  
  27. t_time = hour + (minute*0.01)
  28. get_or(_start_time,_end_time) =>
  29. var float or_hi = na
  30. var float or_lo = na
  31. or_t = (t_time >= start_time and t_time < end_time)
  32. or_f = or_t == false
  33. or_o = or_t and not or_t[1]
  34. if or_o
  35. or_hi := high
  36. or_lo := low
  37. if or_t and high > or_hi
  38. or_hi := high
  39. if or_t and low < or_lo
  40. or_lo := low
  41. [or_hi,or_lo,or_t,or_f,or_o]
  42.  
  43. [or_high,or_low,or_true,or_false,or_open] = get_or(start_time,end_time)
  44.  
  45. or_range = or_high - or_low
  46. or_mean = math.avg(or_high,or_low)
  47. or_end = or_false and (or_false[1] == false)
  48. eod = (ta.valuewhen(or_open,bar_index,0) - ta.valuewhen(or_end,bar_index,1)) - 1
  49. ba_or = ta.valuewhen(or_end,bar_index,0)
  50.  
  51. var long_count = 0
  52. var short_count = 0
  53. if or_open
  54. long_count := 0
  55. short_count := 0
  56.  
  57. pt_step = or_range*target_p
  58. pt_1 = or_high + pt_step
  59. pt_1b = or_low - pt_step
  60. pt_2 = or_high + pt_step*2
  61. pt_2b = or_low - pt_step*2
  62.  
  63. var float pt_x1 = na
  64. var float pt_x2 = na
  65. var int scount = na
  66. var int lcount = na
  67. var line l1 = na
  68. var line l2 = na
  69. var line l3 = na
  70. var line l4 = na
  71. var line l5 = na
  72. var line l6 = na
  73. var line l7 = na
  74. var line lx = na
  75. var label lab1 = na
  76. var label lab2 = na
  77. var label pt1 = na
  78. var label pt2 = na
  79. var label pt3 = na
  80. var label pt4 = na
  81. var label ptx = na
  82. if or_true
  83. scount := 1
  84. lcount := 1
  85. if or_end
  86. pt_x1 := or_high + pt_step
  87. pt_x2 := or_low - pt_step
  88. if tog_hist == false
  89. a_allLines = line.all
  90. if array.size(a_allLines) > 0
  91. for i = 0 to array.size(a_allLines) - 1
  92. line.delete(array.get(a_allLines, i))
  93. a_allLabels = label.all
  94. if array.size(a_allLabels) > 0
  95. for i = 0 to array.size(a_allLabels) - 1
  96. label.delete(array.get(a_allLabels, i))
  97. l1 := line.new(ba_or,or_high,ba_or + eod, or_high, color = color1, width = 2)
  98. l2 := line.new(ba_or,or_low,ba_or + eod, or_low, color = color2, width = 2)
  99. l3 := line.new(ba_or,or_mean,ba_or + eod, or_mean, color = color3)
  100. l4 := line.new(ba_or,pt_x1,ba_or + eod, pt_x1, color = color4, style = line.style_dotted)
  101. pt1 := label.new(ba_or + eod + 1, pt_x1, style = label.style_label_left, text = "PT1", tooltip = str.tostring(str.format("{0, number, currency}",math.round(pt_x1,2))), textcolor = color4, color = color.new(color4,100), size = size.tiny)
  102. l5 := line.new(ba_or,pt_x2,ba_or + eod, pt_x2, color = color4, style = line.style_dotted)
  103. pt2 := label.new(ba_or + eod + 1, pt_x2, style = label.style_label_left, text = "PT1", tooltip = str.tostring(str.format("{0, number, currency}",math.round(pt_x2,2))), textcolor = color4, color = color.new(color4,100), size = size.tiny)
  104. linefill.new(l1, l2,colorf)
  105. //One a Day Alerts
  106. alertcondition(close > or_high and close[1] <= or_high and or_false and long_count == 0,title = "First Break Above Range")
  107. alertcondition(close < or_low and close[1] >= or_low and or_false and short_count == 0, title = "First Break Below Range")
  108. //Breakout Alerts
  109. alertcondition(close > or_high and close[1] <= or_high and or_false,title = "Break Above Range")
  110. alertcondition(close < or_low and close[1] >= or_low and or_false, title = "Break Below Range")
  111. //BREAKOUT LABELS///////////////////////////////////////////////////////////////
  112.  
  113. if close > or_high and close[1] <= or_high and or_false and long_count == 0
  114. lab1 := label.new(bar_index,or_high, style = label.style_triangleup, size = size.auto, color = colorg, yloc = yloc.abovebar)
  115. long_count := 1
  116.  
  117. if close < or_low and close[1] >= or_low and or_false and short_count == 0
  118. lab2 := label.new(bar_index,or_low, style = label.style_triangledown, size = size.auto, color = colorr, yloc = yloc.belowbar)
  119. short_count := 1
  120. ////////////////////////////////////////////////////////////////////////////////
  121. //To infinity and beyond!//////////////////////////////////////////////////////
  122.  
  123. alertcondition(close > pt_x1 and or_false, title = "New Long PT Hit")
  124. if close > pt_x1 and or_false
  125. lcount := math.floor((close - or_high)/pt_step) + 1
  126. for i = (lcount[1] + 1) to lcount
  127. pt_x1 := or_high + (i*pt_step)
  128. lx := line.new(bar_index,pt_x1,ba_or + eod, pt_x1, color = color4)
  129. ptx := label.new(ba_or + eod + 1,pt_x1, style = label.style_label_left, text = "PT" + str.tostring(i), tooltip = str.tostring(str.format("{0, number, currency}",math.round(pt_x1,2))), textcolor = color4, color = color.new(color4,100), size = size.tiny)
  130.  
  131. alertcondition(close < pt_x2 and or_false, title = "New Short PT Hit")
  132. if close < pt_x2 and or_false
  133. scount := math.floor((or_low - close)/pt_step) + 1
  134. for i = (scount[1] + 1) to scount
  135. pt_x2 := or_low - (i*pt_step)
  136. lx := line.new(bar_index,pt_x2, ba_or + eod, pt_x2, color = color4)
  137. ptx := label.new(ba_or + eod + 1,pt_x2, style = label.style_label_left, text = "PT" + str.tostring(i), tooltip = str.tostring(str.format("{0, number, currency}",math.round(pt_x2,2))), textcolor = color4, color = color.new(color4,100), size = size.tiny)
  138.  
  139.  
  140. plot(or_high, title = "OR High", display = display.none, editable = false)
  141. plot(or_mean, title = "OR Mean", display = display.none, editable = false)
  142. plot(or_low, title = "OR Low", display = display.none, editable = false)
Advertisement
Add Comment
Please, Sign In to add comment