xmd79

Weekly Power 3

Nov 2nd, 2022
215
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 24.31 KB | None | 0 0
  1. // © Infinity_Trading_
  2. // Last Modified: 11/1/2022
  3.  
  4. //@version=5
  5. indicator(title="Weekly Power 3", shorttitle="_WPower3", overlay=true, max_lines_count=100)
  6.  
  7. // Purpose:
  8. //
  9. // Did you know there is a simple line you can place on your chart to immediately make the weeks price action more understandable?
  10. // Its called the Weekly Open Line. And its the opening price of the trading week.
  11. // It was created by The Inner Circle Trader (ICT) and incorporates another one of his concepts called Power 3.
  12.  
  13. // Usage:
  14. //
  15. // Like all scripts publish by Infinity Trading, everything in the indicator is customizable by the user.
  16. // Every label, line, or text can be individually toggled ON or OFF so the user has complete control over the element they want displayed on their chart.
  17. // All of the lines can be individually adjusted by color, line style, or line width.
  18. // The color and text color on the high and low of the week labels can be individually changed.
  19. // And so much more!
  20.  
  21.  
  22. ///////////////////////////////////////////////////////////////////////////////// INPUTS
  23.  
  24. var string GP1 = "Weekly Open Line"
  25. i_weekly_open_toggle = input.bool(defval=true, title="Color", group=GP1, inline="weekly_open")
  26. i_weekly_open_color = input.color(defval=color.new(#b22833, 0), title="", group=GP1, inline="weekly_open")
  27. i_weekly_open_width = input.int(defval=4, minval=1, maxval=10, title="Line Width", group=GP1)
  28. i_weekly_open_line_style = input.string(defval="solid (─)", title="Line Style", options=["solid (─)", "dotted (┈)", "dashed (╌)"], group=GP1)
  29.  
  30.  
  31. var string GP2 = "Weekly High"
  32. // Weekly high line
  33. i_weekly_high_toggle = input.bool(defval=true, title="High Line", group=GP2, inline="weekly_high")
  34. i_weekly_high_color = input.color(defval=color.new(#0e2ddc, 0), title="", group=GP2, inline="weekly_high")
  35. i_weekly_high_width = input.int(defval=1, minval=1, maxval=10, title="", group=GP2, inline="weekly_high")
  36. i_weekly_high_line_style = input.string(defval="solid (─)", title="", options=["solid (─)", "dotted (┈)", "dashed (╌)"], group=GP2, inline="weekly_high")
  37. // Weekly high label
  38. i_weekly_high_label_toggle = input.bool(defval=true, title="High Label", group=GP2, inline="weekly_high_label")
  39. i_weekly_high_label_color = input.color(defval=color.new(#42bda8, 0), title="", group=GP2, inline="weekly_high_label")
  40. i_weekly_high_label_textcolor = input.color(defval=color.new(#131722, 0), title="", group=GP2, inline="weekly_high_label")
  41. i_weekly_high_label_size = input.string(defval="Normal", title="Size", options=["Tiny", "Small", "Normal", "Large", "Huge", "Auto"], group=GP2, inline="weekly_high_label")
  42.  
  43. var string GP3 = "Weekly Low"
  44. // Weekly low line
  45. i_weekly_low_toggle = input.bool(defval=true, title="Low Line", group=GP3, inline="weekly_low")
  46. i_weekly_low_color = input.color(defval=color.new(#0e2ddc, 0), title="", group=GP3, inline="weekly_low")
  47. i_weekly_low_width = input.int(defval=1, minval=1, maxval=10, title="", group=GP3, inline="weekly_low")
  48. i_weekly_low_line_style = input.string(defval="solid (─)", title="", options=["solid (─)", "dotted (┈)", "dashed (╌)"], group=GP3, inline="weekly_low")
  49. // Weekly low label
  50. i_weekly_low_label_toggle = input.bool(defval=true, title="Low Label", group=GP3, inline="weekly_low_label")
  51. i_weekly_low_label_color = input.color(defval=color.new(#f7525f, 0), title="", group=GP3, inline="weekly_low_label")
  52. i_weekly_low_label_textcolor = input.color(defval=color.new(#131722, 0), title="", group=GP3, inline="weekly_low_label")
  53. i_weekly_low_label_size = input.string(defval="Normal", title="Size", options=["Tiny", "Small", "Normal", "Large", "Huge", "Auto"], group=GP3, inline="weekly_low_label")
  54.  
  55.  
  56. var string GP5 = "Day of the Week Labels"
  57. i_day_label_toggle = input.bool(defval=true, title="Display Labels", group=GP5)
  58. i_day_text_color = input.color(defval=color.new(#7b1fa2, 20), title="Color", group=GP5, inline="day_text")
  59. i_day_text_size = input.string(defval="Large", title="Size", options=["Tiny", "Small", "Normal", "Large", "Huge", "Auto"], group=GP5, inline="day_text")
  60. i_day_label_buffer = input.int(defval=10, step=5, title="Buffer", minval=5, maxval=50, group=GP5)
  61. i_day_label_position = input.string(defval="Above", title="Position", options=["Above", "Below"], group=GP5)
  62.  
  63. var string GP7 = "Best Odds High of the Week Zone (if Bearish Week)"
  64.  
  65. i_best_probability_high_toggle = input.bool(defval=true, title="High Zone Line", group=GP7, inline="best_prob_high", tooltip = "ICT says if you expect to have a Bullish Week the best odds are that the WEEKLY LOW will form between Tuesdays London Open and Wednesdays NY Open")
  66. i_best_probability_high_color = input.color(defval=color.new(#90bff9, 0), title="", group=GP7, inline="best_prob_high")
  67. i_best_probability_high_width = input.int(defval=4, minval=1, maxval=10, title="Width", group=GP7, inline="best_prob_high")
  68. i_best_probability_high_text_toggle = input.bool(defval=false, title="Display Label ", group=GP7, inline="best_prob_high2")
  69. i_best_probability_high_text_color = input.color(defval=color.new(#131722, 0), title="", group=GP7, inline="best_prob_high2")
  70. i_best_probability_high_buffer = input.int(defval=0, step=1, title="Buffer", minval=-5, maxval=5, group=GP7, inline="best_prob_high2")
  71.  
  72. var string GP6 = "Best Odds Low of the Week Zone (if Bullish Week)"
  73.  
  74. i_best_probability_low_toggle = input.bool(defval=true, title="Low Zone Line", group=GP6, inline="best_prob_low", tooltip = "ICT says if you expect to have a Bearish Week the best odds are that the WEEKLY HIGH will form between Tuesdays London Open and Wednesdays NY Open")
  75. i_best_probability_low_color = input.color(defval=color.new(#90bff9, 0), title="", group=GP6, inline="best_prob_low")
  76. i_best_probability_low_width = input.int(defval=4, minval=1, maxval=10, title="Width", group=GP6, inline="best_prob_low")
  77. i_best_probability_low_text_toggle = input.bool(defval=false, title="Display Label ", group=GP6, inline="best_prob_low2")
  78. i_best_probability_low_text_color = input.color(defval=color.new(#131722, 0), title="", group=GP6, inline="best_prob_low2")
  79. i_best_probability_low_buffer = input.int(defval=0, step=1, title="Buffer", minval=-5, maxval=5, group=GP6, inline="best_prob_low2")
  80.  
  81.  
  82. ///////////////////////////////////////////////////////////////////////////////// HELPER FUNCTIONS
  83.  
  84.  
  85. // Function the converts string inputs to line style code
  86. line_style_function(input_var) =>
  87. switch input_var
  88. "dotted (┈)" => line.style_dotted
  89. "dashed (╌)" => line.style_dashed
  90. => line.style_solid
  91.  
  92.  
  93. // Function that converts string inputs to text size code
  94. text_size_function(string_size) =>
  95. switch string_size
  96. "Tiny" => size.tiny
  97. "Small" => size.small
  98. "Normal" => size.normal
  99. "Large" => size.large
  100. "Huge" => size.huge
  101. "Auto" => size.auto
  102.  
  103.  
  104. weekly_open = request.security(syminfo.tickerid, "W", open)
  105. weekly_past_low = request.security(syminfo.tickerid, "W", low)
  106. weekly_past_high = request.security(syminfo.tickerid, "W", high)
  107. weekly_time_open = request.security(syminfo.tickerid, "W", time)
  108. weekly_time_close = request.security(syminfo.tickerid, "W", time_close)
  109.  
  110. ///////////////////////////////////////////////////////////////////////////////// TIME
  111.  
  112. // Time of one period on your current chart
  113. dt = time - time[1]
  114. periods_in_24hrs = 1440 / timeframe.multiplier
  115. // 31 hours between Tuesday London Open and Wed NY Open
  116. // 1860 min in 31 hours
  117. periods_in_high_prob_zone = 1860 / timeframe.multiplier
  118. timespan_high_prob_zone = periods_in_high_prob_zone + periods_in_24hrs
  119.  
  120.  
  121. tuesday_london_open_est = time(timeframe.period, '0300-0330:2', "America/New_York")
  122. wednesday_ny_open_est = time(timeframe.period, '0930-1000:3', "America/New_York")
  123.  
  124. time_middle_hour = (hour(time, "America/New_York") == 4) and (minute(time) == 0)
  125. timespan_week_est = time(timeframe.period, '1800-1559:123456', "America/New_York")
  126.  
  127.  
  128.  
  129. /////////////////////////////////////////////////////////////////////////////////
  130.  
  131.  
  132. // Converts inputs selections into code
  133. weekly_open_line_style = line_style_function(i_weekly_open_line_style)
  134. weekly_high_line_style = line_style_function(i_weekly_high_line_style)
  135. weekly_low_line_style = line_style_function(i_weekly_low_line_style)
  136. weekly_high_label_size = text_size_function(i_weekly_high_label_size)
  137. weekly_low_label_size = text_size_function(i_weekly_low_label_size)
  138. day_text_size = text_size_function(i_day_text_size)
  139.  
  140.  
  141. // Instantiate variables
  142. var line line_weekly_open = na
  143. var line line_weekly_high = na
  144. var line line_weekly_low = na
  145. var line line_weekly_low_best_prob = na
  146. var line line_weekly_high_best_prob = na
  147. var box box_monday = na
  148. var box box_tuesday = na
  149. var box box_wednesday = na
  150. var box box_thursday = na
  151. var box box_friday = na
  152. var box box_best_prob_low = na
  153. var box box_best_prob_high = na
  154. var float weekly_high = 0.0
  155. var float weekly_low = 0.0
  156. var float label_level = 0.0
  157. var float first_weekly_candle_low = 0.0
  158. var float first_weekly_candle_high = 0.0
  159. var label label_weekly_high = na
  160. var label label_weekly_low = na
  161.  
  162.  
  163. ///////////////////////////////////////////////////////////////////////////////// MAIN LOGIC
  164. ///////////////////////////////////////////////////////////////////////////////// Determines whether current candle is the start of new week
  165.  
  166.  
  167. // Start of new week
  168. if dayofmonth(time, "America/New_York") != dayofmonth(time, "America/New_York")[1] and dayofweek(time, "America/New_York") == dayofweek.sunday
  169.  
  170. if i_weekly_open_toggle
  171. // Draw Weekliy Open Line for all previous weeks
  172. line_weekly_open := line.new(x1=weekly_time_open, y1=weekly_open, x2=weekly_time_close, y2=weekly_open, xloc=xloc.bar_time, color=i_weekly_open_color, style=weekly_open_line_style, width=i_weekly_open_width)
  173.  
  174.  
  175. if i_weekly_high_toggle
  176. line_weekly_high := line.new(x1=weekly_time_open, y1=weekly_past_high, x2=weekly_time_close, y2=weekly_past_high, xloc=xloc.bar_time, color=i_weekly_high_color, style=weekly_high_line_style, width=i_weekly_high_width)
  177.  
  178.  
  179. if i_weekly_low_toggle
  180. line_weekly_low := line.new(x1=weekly_time_open, y1=weekly_past_low, x2=weekly_time_close, y2=weekly_past_low, xloc=xloc.bar_time, color=i_weekly_low_color, style=weekly_low_line_style, width=i_weekly_low_width)
  181.  
  182.  
  183. // Reset weeky variables
  184. weekly_high := 0.0
  185. weekly_low := 50000.0
  186.  
  187. // Create blank box at the start of each week
  188. box_monday := box.new(left=na, top=na, right=na, bottom=na, xloc=xloc.bar_index, text="Monday", text_color=i_day_text_color, text_halign=text.align_center, text_valign=text.align_center, text_size=day_text_size, border_color=color.new(#000000, 100), border_width=2, border_style=line.style_solid, bgcolor=color.new(#000000, 100))
  189. box_tuesday := box.new(left=na, top=na, right=na, bottom=na, xloc=xloc.bar_index, text="Tuesday", text_color=i_day_text_color, text_halign=text.align_center, text_valign=text.align_center, text_size=day_text_size, border_color=color.new(#000000, 100), border_width=2, border_style=line.style_solid, bgcolor=color.new(#000000, 100))
  190. box_wednesday := box.new(left=na, top=na, right=na, bottom=na, xloc=xloc.bar_index, text="Wednesday", text_color=i_day_text_color, text_halign=text.align_center, text_valign=text.align_center, text_size=day_text_size, border_color=color.new(#000000, 100), border_width=2, border_style=line.style_solid, bgcolor=color.new(#000000, 100))
  191. box_thursday := box.new(left=na, top=na, right=na, bottom=na, xloc=xloc.bar_index, text="Thursday", text_color=i_day_text_color, text_halign=text.align_center, text_valign=text.align_center, text_size=day_text_size, border_color=color.new(#000000, 100), border_width=2, border_style=line.style_solid, bgcolor=color.new(#000000, 100))
  192. box_friday := box.new(left=na, top=na, right=na, bottom=na, xloc=xloc.bar_index, text="Friday", text_color=i_day_text_color, text_halign=text.align_center, text_valign=text.align_center, text_size=day_text_size, border_color=color.new(#000000, 100), border_width=2, border_style=line.style_solid, bgcolor=color.new(#000000, 100))
  193.  
  194.  
  195. // Weekly High Label on opening candle of the week
  196. if i_weekly_high_label_toggle
  197. // Add a label for the high of the current week
  198. label_weekly_high := label.new(x=bar_index, y=high + 3, xloc=xloc.bar_index, yloc=yloc.price, text="Weekly High", color=i_weekly_high_label_color, style=label.style_label_down, textcolor=i_weekly_high_label_textcolor, size=weekly_high_label_size)
  199.  
  200. // Weekly Low Label on opening candle of the week
  201. if i_weekly_low_label_toggle
  202. // Add a label for the low of the current week
  203. label_weekly_low := label.new(x=bar_index, y=low - 3, xloc=xloc.bar_index, yloc=yloc.price, text="Weekly Low", color=i_weekly_low_label_color, style=label.style_label_up, textcolor=i_weekly_low_label_textcolor, size=weekly_low_label_size)
  204.  
  205. // Variable to keep track of high/low when opening candle is high/low of the week
  206. first_weekly_candle_high := high
  207. first_weekly_candle_low := low
  208.  
  209.  
  210. // Restart variable for Best Probability Weekly High/Low Zones
  211. line_weekly_low_best_prob := line.new(x1=na, y1=na, x2=na, y2=na, color=color.yellow, style=line.style_solid, width=4)
  212. box_best_prob_low := box.new(left=na, top=na, right=na, bottom=na, xloc=xloc.bar_index, text="ICTs Best Odds Low of the Week Zone", text_color=i_best_probability_low_text_color, text_halign=text.align_center, text_valign=text.align_center, text_size=size.normal, border_color=color.new(#000000, 100), border_width=2, border_style=line.style_solid, bgcolor=color.new(#000000, 100))
  213. line_weekly_high_best_prob := line.new(x1=na, y1=na, x2=na, y2=na, color=color.yellow, style=line.style_solid, width=4)
  214. box_best_prob_high := box.new(left=na, top=na, right=na, bottom=na, xloc=xloc.bar_index, text="ICTs Best Odds High of the Week Zone", text_color=i_best_probability_high_text_color, text_halign=text.align_center, text_valign=text.align_center, text_size=size.normal, border_color=color.new(#000000, 100), border_width=2, border_style=line.style_solid, bgcolor=color.new(#000000, 100))
  215.  
  216.  
  217. else
  218.  
  219. // Weekly High Label after the first candle of the week
  220. // For second candle of the week
  221. if weekly_high == 0.0
  222. if i_weekly_high_label_toggle and high > high[1]
  223. // Add a label for the high of the current week
  224. label_weekly_high := label.new(x=bar_index, y=high + 3, xloc=xloc.bar_index, yloc=yloc.price, text="Weekly High", color=i_weekly_high_label_color, style=label.style_label_down, textcolor=i_weekly_high_label_textcolor, size=weekly_high_label_size)
  225. label.delete(label_weekly_high[1])
  226. else
  227. // For all subsequent candles of the week
  228. if i_weekly_high_label_toggle and high > weekly_high and high > first_weekly_candle_high
  229. // Add a label for the high of the current week
  230. label_weekly_high := label.new(x=bar_index, y=high + 3, xloc=xloc.bar_index, yloc=yloc.price, text="Weekly High", color=i_weekly_high_label_color, style=label.style_label_down, textcolor=i_weekly_high_label_textcolor, size=weekly_high_label_size)
  231. label.delete(label_weekly_high[1])
  232.  
  233. // Weekly Low Label after the first candle of the week
  234. // For second candle of the week
  235. if weekly_low == 50000.0
  236. if i_weekly_low_label_toggle and low < low[1]
  237. // Add a label for the low of the current week
  238. label_weekly_low := label.new(x=bar_index, y=low - 3, xloc=xloc.bar_index, yloc=yloc.price, text="Weekly Low", color=i_weekly_low_label_color, style=label.style_label_up, textcolor=i_weekly_low_label_textcolor, size=weekly_low_label_size)
  239. label.delete(label_weekly_low[1])
  240.  
  241. else
  242. // For all subsequent candles of the week
  243. if i_weekly_low_label_toggle and low < weekly_low and low < first_weekly_candle_low
  244. // Add a label for the low of the current week
  245. label_weekly_low := label.new(x=bar_index, y=low - 3, xloc=xloc.bar_index, yloc=yloc.price, text="Weekly Low", color=i_weekly_low_label_color, style=label.style_label_up, textcolor=i_weekly_low_label_textcolor, size=weekly_low_label_size)
  246. label.delete(label_weekly_low[1])
  247.  
  248.  
  249. // Update variable only if current candle is a higher high or lower low
  250. weekly_high := math.max(weekly_high, high)
  251. weekly_low := math.min(weekly_low, low)
  252.  
  253. // Are the labels to be displayed above or below the weekly price action?
  254. label_level := i_day_label_position == "Above" ? weekly_high + i_day_label_buffer : weekly_low - i_day_label_buffer
  255.  
  256. // Settings input to turn Day of the Week boxes ON/OFF
  257. if i_day_label_toggle
  258.  
  259. // On Monday at 3 AM EST create box
  260. if time_middle_hour and dayofweek(time, "America/New_York") == dayofweek.monday
  261. box.set_top(box_monday, label_level)
  262. box.set_bottom(box_monday, label_level - 1)
  263.  
  264. box.set_left(box_monday, bar_index)
  265. box.set_right(box_monday, bar_index + 1)
  266.  
  267. // On Tuesday at 3 AM EST create box
  268. if time_middle_hour and dayofweek(time, "America/New_York") == dayofweek.tuesday
  269. box.set_top(box_tuesday, label_level)
  270. box.set_bottom(box_tuesday, label_level - 1)
  271.  
  272. box.set_left(box_tuesday, bar_index)
  273. box.set_right(box_tuesday, bar_index + 1)
  274.  
  275.  
  276. // On Wednesday at 3 AM EST create box
  277. if time_middle_hour and dayofweek(time, "America/New_York") == dayofweek.wednesday
  278. box.set_top(box_wednesday, label_level)
  279. box.set_bottom(box_wednesday, label_level - 1)
  280.  
  281. box.set_left(box_wednesday, bar_index)
  282. box.set_right(box_wednesday, bar_index + 1)
  283.  
  284.  
  285. // On Thursday at 3 AM EST create box
  286. if time_middle_hour and dayofweek(time, "America/New_York") == dayofweek.thursday
  287. box.set_top(box_thursday, label_level)
  288. box.set_bottom(box_thursday, label_level - 1)
  289.  
  290. box.set_left(box_thursday, bar_index)
  291. box.set_right(box_thursday, bar_index + 1)
  292.  
  293.  
  294. // On Friday at 3 AM EST create box
  295. if time_middle_hour and dayofweek(time, "America/New_York") == dayofweek.friday
  296. box.set_top(box_friday, label_level)
  297. box.set_bottom(box_friday, label_level - 1)
  298.  
  299. box.set_left(box_friday, bar_index)
  300. box.set_right(box_friday, bar_index + 1)
  301.  
  302.  
  303.  
  304. // At every new candle during week update highs and lows and redraw the box
  305. if timespan_week_est
  306.  
  307. // Monday update
  308. box.set_top(box_monday, label_level)
  309. box.set_bottom(box_monday, label_level - 1)
  310. // Tuesday update
  311. box.set_top(box_tuesday, label_level)
  312. box.set_bottom(box_tuesday, label_level - 1)
  313. // Wednesday update
  314. box.set_top(box_wednesday, label_level)
  315. box.set_bottom(box_wednesday, label_level - 1)
  316. // Thursday update
  317. box.set_top(box_thursday, label_level)
  318. box.set_bottom(box_thursday, label_level - 1)
  319. // Friday update
  320. box.set_top(box_friday, label_level)
  321. box.set_bottom(box_friday, label_level - 1)
  322.  
  323. ///////////////////////////////////////////////////////////////////////////////// BEST PROBABILITY HIGH/LOW ZONES
  324.  
  325. // Toggle line for low zone of the week
  326. if i_best_probability_low_toggle
  327. // Create original line
  328. if timeframe.isminutes and time(timeframe.period, '0300-0301:2', "America/New_York") // Monday
  329. // Create line and shift over to start at Londons Open on Tuesday
  330. line_weekly_low_best_prob := line.new(x1=time + periods_in_24hrs * dt, y1=math.min(weekly_low, first_weekly_candle_low) + i_best_probability_low_buffer, x2=time + timespan_high_prob_zone * dt, y2=math.min(weekly_low, first_weekly_candle_low) + i_best_probability_low_buffer, xloc=xloc.bar_time, color=i_best_probability_low_color, style=line.style_solid, width=i_best_probability_low_width)
  331. // Toggle text on low zone of the week
  332. if i_best_probability_low_text_toggle
  333. box.set_top(box_best_prob_low, math.min(weekly_low, first_weekly_candle_low) + i_best_probability_low_buffer -2)
  334. box.set_bottom(box_best_prob_low, math.min(weekly_low, first_weekly_candle_low) + i_best_probability_low_buffer - 3)
  335. box.set_left(box_best_prob_low, bar_index + int(periods_in_high_prob_zone * 1.2))
  336. box.set_right(box_best_prob_low, bar_index + int(periods_in_high_prob_zone * 1.2) + 1)
  337.  
  338. // Update y axis on line and box for each candle past London Open on Monday
  339. // Have to use min to take into account when weekly open == weekly low
  340. line.set_y1(line_weekly_low_best_prob, math.min(weekly_low, first_weekly_candle_low) + i_best_probability_low_buffer)
  341. line.set_y2(line_weekly_low_best_prob, math.min(weekly_low, first_weekly_candle_low) + i_best_probability_low_buffer)
  342. box.set_top(box_best_prob_low, math.min(weekly_low, first_weekly_candle_low) + i_best_probability_low_buffer -2)
  343. box.set_bottom(box_best_prob_low, math.min(weekly_low, first_weekly_candle_low) + i_best_probability_low_buffer - 3)
  344.  
  345.  
  346. if i_best_probability_high_toggle
  347. if timeframe.isminutes and time(timeframe.period, '0300-0301:2', "America/New_York") // Monday
  348. line_weekly_high_best_prob := line.new(x1=time + periods_in_24hrs * dt, y1=math.max(weekly_high, first_weekly_candle_high) + i_best_probability_high_buffer, x2=time + timespan_high_prob_zone * dt, y2=math.max(weekly_high, first_weekly_candle_high) + i_best_probability_high_buffer, xloc=xloc.bar_time, color=i_best_probability_high_color, style=line.style_solid, width=i_best_probability_high_width)
  349. if i_best_probability_high_text_toggle
  350. box.set_top(box_best_prob_high, math.max(weekly_high, first_weekly_candle_high) + i_best_probability_high_buffer + 3)
  351. box.set_bottom(box_best_prob_high, math.max(weekly_high, first_weekly_candle_high) + i_best_probability_high_buffer + 2)
  352. box.set_left(box_best_prob_high, bar_index + int(periods_in_high_prob_zone * 1.2))
  353. box.set_right(box_best_prob_high, bar_index + int(periods_in_high_prob_zone * 1.2) + 1)
  354. // Update y axis on line and box for each candle past London Open on Monday
  355. // Have to use min to take into account when weekly open == weekly low
  356. line.set_y1(line_weekly_high_best_prob, math.max(weekly_high, first_weekly_candle_high) + i_best_probability_high_buffer)
  357. line.set_y2(line_weekly_high_best_prob, math.max(weekly_high, first_weekly_candle_high) + i_best_probability_high_buffer)
  358. box.set_top(box_best_prob_high, math.max(weekly_high, first_weekly_candle_high) + i_best_probability_high_buffer + 3)
  359. box.set_bottom(box_best_prob_high, math.max(weekly_high, first_weekly_candle_high) + i_best_probability_high_buffer + 2)
  360.  
  361.  
  362. ///////////////////////////////////////////////////////////////////////////////// DRAW CURRENT WEEKS LINES
  363.  
  364.  
  365. // Instantiate variables
  366. var line line_curr_weekly_open = na
  367. var line line_curr_weekly_high = na
  368. var line line_curr_weekly_low = na
  369.  
  370. // Draw lines for current week for open, high, & low
  371. if barstate.islast
  372.  
  373. // Weekliy Open Line
  374. if i_weekly_open_toggle
  375. line_curr_weekly_open := line.new(x1=weekly_time_open, y1=weekly_open, x2=time, y2=weekly_open, xloc=xloc.bar_time, color=i_weekly_open_color, style=weekly_open_line_style, width=i_weekly_open_width)
  376. line.delete(line_curr_weekly_open[1])
  377.  
  378. // Weekly High Line
  379. if i_weekly_high_toggle
  380. line_curr_weekly_high := line.new(x1=weekly_time_open, y1=weekly_past_high, x2=time, y2=weekly_past_high, xloc=xloc.bar_time, color=i_weekly_high_color, style=weekly_high_line_style, width=i_weekly_high_width)
  381. line.delete(line_curr_weekly_high[1])
  382.  
  383. // Weekly Low Line
  384. if i_weekly_low_toggle
  385. line_curr_weekly_low := line.new(x1=weekly_time_open, y1=weekly_past_low, x2=time, y2=weekly_past_low, xloc=xloc.bar_time, color=i_weekly_low_color, style=weekly_low_line_style, width=i_weekly_low_width)
  386. line.delete(line_curr_weekly_low[1])
  387.  
Advertisement
Add Comment
Please, Sign In to add comment