Advertisement
xmd79

Session Range Boxes

Jan 12th, 2023
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.69 KB | None | 0 0
  1. //@version=5
  2. indicator('Session Range Boxes', overlay=true)
  3.  
  4.  
  5. //-----------------------------------------------------------------------------------------------------------------------------------------------------------------
  6. //Inputs
  7. //-----------------------------------------------------------------------------------------------------------------------------------------------------------------
  8.  
  9.  
  10. //Seasonal Adjustment Input
  11. season = input.string(defval='Fall/Winter', options=['Spring/Summer', 'Fall/Winter'], title='US Season')
  12.  
  13.  
  14. //Session Display Toggles
  15. show_asia = input(defval=true, title='Show Asian Session')
  16. show_lon = input(defval=false, title='Show London Session')
  17. show_usa = input(defval=false, title='Show US Session')
  18.  
  19.  
  20. //Pip Range Display Toggle
  21. show_pip_range = input(defval=true, title='Show Pip Ranges')
  22.  
  23. //50 asian display toggle
  24. show_50_asian = input(defval=false, title='Show Asian 50%')
  25. show_50_london = input(defval=false, title='Show London 50%')
  26. show_50_usa = input(defval=false, title='Show US 50%')
  27.  
  28. /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  29. /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  30.  
  31.  
  32. //USE THIS SECTION TO EDIT BOX AND LABEL COLORS
  33.  
  34.  
  35. asia_color = #0f45b0 //color.black
  36. lon_color = #0073f5 //color.black
  37. usa_color = #832721 //color.black
  38.  
  39.  
  40. //You can change the colors by either using the built in color variables:
  41. //color.aqua, color.black, color.blue, color.fuchsia, color.gray, color.green, color.lime, color.maroon, color.navy, color.olive, color.orange, color.purple, color.red, color.silver, color.teal, color.white, color.yellow
  42.  
  43.  
  44. //Alternatively, you can select a hex code for any color you want.
  45. //There are a number of online resources to find hex codes. My personal favorite is https://www.color-hex.com/color-wheel/
  46.  
  47.  
  48. /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  49. /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  50.  
  51.  
  52. //-----------------------------------------------------------------------------------------------------------------------------------------------------------------
  53. //Definitions
  54. //-----------------------------------------------------------------------------------------------------------------------------------------------------------------
  55.  
  56.  
  57. //Sessions
  58. t_asia = season == 'Spring/Summer' ? time(timeframe.period, '1700-0200:23456') : time(timeframe.period, '1900-0200:23456')
  59. t_lon = time(timeframe.period, '0300-0700:23456')
  60. t_usa = time(timeframe.period, '0800-1600:23456')
  61.  
  62.  
  63. //Function to detect if time is in session
  64. time_in_range(sess) =>
  65. not na(sess) ? 1 : 0
  66.  
  67.  
  68. //Active Session Conditions
  69. asia_session_active = show_asia ? time_in_range(t_asia) == 1 ? 1 : 0 : na
  70. lon_session_active = show_lon ? time_in_range(t_lon) == 1 ? 1 : 0 : na
  71. usa_session_active = show_usa ? time_in_range(t_usa) == 1 ? 1 : 0 : na
  72.  
  73.  
  74. //Session Starting Points
  75. asia_start = asia_session_active[1] == 0 and asia_session_active == 1 ? 1 : 0
  76. lon_start = lon_session_active[1] == 0 and lon_session_active == 1 ? 1 : 0
  77. usa_start = usa_session_active[1] == 0 and usa_session_active == 1 ? 1 : 0
  78.  
  79.  
  80. //Session Ending Points
  81. asia_end = asia_session_active[1] == 1 and asia_session_active == 0 ? 1 : 0
  82. lon_end = lon_session_active[1] == 1 and lon_session_active == 0 ? 1 : 0
  83. usa_end = usa_session_active[1] == 1 and usa_session_active == 0 ? 1 : 0
  84.  
  85.  
  86. //Session High & Low Function
  87. sess_hh_ll(session_active, start) =>
  88. var hh = high
  89. var ll = low
  90. if session_active == 1
  91. if high > hh or start
  92. hh := high
  93. hh
  94. if low < ll or start
  95. ll := low
  96. ll
  97. [hh, ll]
  98.  
  99.  
  100. //Session Highs & Lows
  101. [asia_h, asia_l] = sess_hh_ll(asia_session_active, asia_start)
  102. [lon_h, lon_l] = sess_hh_ll(lon_session_active, lon_start)
  103. [usa_h, usa_l] = sess_hh_ll(usa_session_active, usa_start)
  104.  
  105.  
  106. //Session Colors
  107. asia_line_color = color.new(asia_color, 0)
  108. lon_line_color = color.new(lon_color, 0)
  109. usa_line_color = color.new(usa_color, 0)
  110.  
  111.  
  112. //Session Box Drawing Function
  113. draw_session_box(session_active, start, end, h, l, line_color, show_50) =>
  114. bars = ta.barssince(start)
  115. var line start_line_dev = na
  116. var line end_line_dev = na
  117. var line high_line_dev = na
  118. var line low_line_dev = na
  119. var line fifty_line_dev = na
  120. var line start_line = na
  121. var line end_line = na
  122. var line high_line = na
  123. var line low_line = na
  124. var line fifty_line = na
  125. if session_active
  126. line.delete(start_line_dev)
  127. line.delete(end_line_dev)
  128. line.delete(high_line_dev)
  129. line.delete(low_line_dev)
  130. line.delete(fifty_line_dev)
  131. start_line_dev := line.new(x1=bar_index[bars], y1=h, x2=bar_index[bars], y2=l, xloc=xloc.bar_index, color=line_color, width=1)
  132. end_line_dev := line.new(x1=bar_index, y1=h, x2=bar_index, y2=l, xloc=xloc.bar_index, color=line_color, width=1)
  133. high_line_dev := line.new(x1=bar_index[bars], y1=h, x2=bar_index, y2=h, xloc=xloc.bar_index, color=line_color, width=1)
  134. low_line_dev := line.new(x1=bar_index[bars], y1=l, x2=bar_index, y2=l, xloc=xloc.bar_index, color=line_color, width=1)
  135. if show_50
  136. fifty_line_dev := line.new(x1=bar_index[bars], y1=l + (h - l) / 2, x2=bar_index, y2=l + (h - l) / 2, xloc=xloc.bar_index, color=line_color, width=1)
  137. fifty_line_dev
  138. if end
  139. line.delete(start_line_dev)
  140. line.delete(end_line_dev)
  141. line.delete(high_line_dev)
  142. line.delete(low_line_dev)
  143. line.delete(fifty_line_dev)
  144. start_line := line.new(x1=bar_index[bars], y1=h, x2=bar_index[bars], y2=l, xloc=xloc.bar_index, color=line_color, width=1)
  145. end_line := line.new(x1=bar_index, y1=h, x2=bar_index, y2=l, xloc=xloc.bar_index, color=line_color, width=1)
  146. high_line := line.new(x1=bar_index[bars], y1=h, x2=bar_index, y2=h, xloc=xloc.bar_index, color=line_color, width=1)
  147. low_line := line.new(x1=bar_index[bars], y1=l, x2=bar_index, y2=l, xloc=xloc.bar_index, color=line_color, width=1)
  148. if show_50
  149. fifty_line := line.new(x1=bar_index[bars], y1=l + (h - l) / 2, x2=bar_index, y2=l + (h - l) / 2, xloc=xloc.bar_index, color=line_color, width=1)
  150. fifty_line
  151.  
  152.  
  153. //Session Label Printing Function
  154. print_session_label(session_active, h, l, start, end, label_color) =>
  155. bars = ta.barssince(start)
  156. var label range_label_dev = na
  157. var label range_label = na
  158. if session_active
  159. label.delete(range_label_dev)
  160. range_label_dev := label.new(x=bar_index[bars / 2], y=l, text='R = ' + str.tostring((h - l) * 10000), xloc=xloc.bar_index, yloc=yloc.price, color=color.new(color.white, 100), style=label.style_label_up, textcolor=label_color, size=size.normal)
  161. range_label_dev
  162. if end
  163. label.delete(range_label_dev)
  164. range_label := label.new(x=bar_index[bars / 2], y=l, text='R = ' + str.tostring((h - l) * 10000), xloc=xloc.bar_index, yloc=yloc.price, color=color.new(color.white, 100), style=label.style_label_up, textcolor=label_color, size=size.normal)
  165. range_label
  166.  
  167.  
  168. //-----------------------------------------------------------------------------------------------------------------------------------------------------------------
  169. //Outputs
  170. //-----------------------------------------------------------------------------------------------------------------------------------------------------------------
  171.  
  172.  
  173. //Session Range Boxes
  174. draw_session_box(asia_session_active, asia_start, asia_end, asia_h, asia_l, asia_line_color, show_50_asian)
  175. draw_session_box(lon_session_active, lon_start, lon_end, lon_h, lon_l, lon_line_color, show_50_london)
  176. draw_session_box(usa_session_active, usa_start, usa_end, usa_h, usa_l, usa_line_color, show_50_usa)
  177.  
  178.  
  179. //Session Range Labels
  180. if show_pip_range
  181. print_session_label(asia_session_active, asia_h, asia_l, asia_start, asia_end, asia_line_color)
  182. print_session_label(lon_session_active, lon_h, lon_l, lon_start, lon_end, lon_line_color)
  183. print_session_label(usa_session_active, usa_h, usa_l, usa_start, usa_end, usa_line_color)
  184.  
  185.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement