xmd79

Session Range Boxes

Jan 5th, 2023
135
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.50 KB | None | 0 0
  1. //@version=4
  2. study("Session Range Boxes", overlay=true)
  3.  
  4.  
  5. //-----------------------------------------------------------------------------------------------------------------------------------------------------------------
  6. //Inputs
  7. //-----------------------------------------------------------------------------------------------------------------------------------------------------------------
  8.  
  9.  
  10. //Seasonal Adjustment Input
  11. season = input(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") : time(timeframe.period, "1900-0200")
  59. t_lon = time(timeframe.period, "0300-0700")
  60. t_usa = time(timeframe.period, "0800-1600")
  61.  
  62.  
  63. //Function to detect if time is in session
  64. time_in_range(sess)=> not na(sess) ? 1 : 0
  65.  
  66.  
  67. //Active Session Conditions
  68. asia_session_active = show_asia ? (time_in_range(t_asia)==1 ? 1 : 0) : na
  69. lon_session_active = show_lon ? (time_in_range(t_lon)==1 ? 1 : 0) : na
  70. usa_session_active = show_usa ? (time_in_range(t_usa)==1 ? 1 : 0) : na
  71.  
  72.  
  73. //Session Starting Points
  74. asia_start = (asia_session_active[1]==0) and (asia_session_active==1) ? 1 : 0
  75. lon_start = (lon_session_active[1]==0) and (lon_session_active==1) ? 1 : 0
  76. usa_start = (usa_session_active[1]==0) and (usa_session_active==1) ? 1 : 0
  77.  
  78.  
  79. //Session Ending Points
  80. asia_end = (asia_session_active[1]==1) and (asia_session_active==0) ? 1 : 0
  81. lon_end = (lon_session_active[1]==1) and (lon_session_active==0) ? 1 : 0
  82. usa_end = (usa_session_active[1]==1) and (usa_session_active==0) ? 1 : 0
  83.  
  84.  
  85. //Session High & Low Function
  86. sess_hh_ll(session_active, start)=>
  87. var hh = high
  88. var ll = low
  89. if session_active==1
  90. if (high > hh) or start
  91. hh := high
  92. if (low < ll) or start
  93. ll := low
  94. [hh, ll]
  95.  
  96.  
  97. //Session Highs & Lows
  98. [asia_h, asia_l] = sess_hh_ll(asia_session_active, asia_start)
  99. [lon_h, lon_l] = sess_hh_ll(lon_session_active, lon_start)
  100. [usa_h, usa_l] = sess_hh_ll(usa_session_active, usa_start)
  101.  
  102.  
  103. //Session Colors
  104. asia_line_color = color.new(asia_color, 0)
  105. lon_line_color = color.new(lon_color, 0)
  106. usa_line_color = color.new(usa_color, 0)
  107.  
  108.  
  109. //Session Box Drawing Function
  110. draw_session_box(session_active, start, end, h, l, line_color, show_50)=>
  111. bars = barssince(start)
  112. var line start_line_dev = na
  113. var line end_line_dev = na
  114. var line high_line_dev = na
  115. var line low_line_dev = na
  116. var line fifty_line_dev = na
  117. var line start_line = na
  118. var line end_line = na
  119. var line high_line = na
  120. var line low_line = na
  121. var line fifty_line = na
  122. if session_active
  123. line.delete(start_line_dev)
  124. line.delete(end_line_dev)
  125. line.delete(high_line_dev)
  126. line.delete(low_line_dev)
  127. line.delete(fifty_line_dev)
  128. 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)
  129. end_line_dev := line.new(x1=bar_index, y1=h, x2=bar_index, y2=l, xloc=xloc.bar_index, color=line_color, width=1)
  130. 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)
  131. 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)
  132. if show_50
  133. 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)
  134. if end
  135. line.delete(start_line_dev)
  136. line.delete(end_line_dev)
  137. line.delete(high_line_dev)
  138. line.delete(low_line_dev)
  139. line.delete(fifty_line_dev)
  140. 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)
  141. end_line := line.new(x1=bar_index, y1=h, x2=bar_index, y2=l, xloc=xloc.bar_index, color=line_color, width=1)
  142. high_line := line.new(x1=bar_index[bars], y1=h, x2=bar_index, y2=h, xloc=xloc.bar_index, color=line_color, width=1)
  143. low_line := line.new(x1=bar_index[bars], y1=l, x2=bar_index, y2=l, xloc=xloc.bar_index, color=line_color, width=1)
  144. if show_50
  145. 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)
  146.  
  147.  
  148. //Session Label Printing Function
  149. print_session_label(session_active, h, l, start, end, label_color)=>
  150. bars = barssince(start)
  151. var label range_label_dev = na
  152. var label range_label = na
  153. if session_active
  154. label.delete(range_label_dev)
  155. range_label_dev := label.new(x=bar_index[bars/2], y=l, text="R = " + tostring((h - l)*10000), xloc=xloc.bar_index, yloc=yloc.price, color=color.new(color.white, 100), style=label.style_labelup, textcolor=label_color, size=size.normal)
  156. if end
  157. label.delete(range_label_dev)
  158. range_label := label.new(x=bar_index[bars/2], y=l, text="R = " + tostring((h - l)*10000), xloc=xloc.bar_index, yloc=yloc.price, color=color.new(color.white, 100), style=label.style_labelup, textcolor=label_color, size=size.normal)
  159.  
  160.  
  161. //-----------------------------------------------------------------------------------------------------------------------------------------------------------------
  162. //Outputs
  163. //-----------------------------------------------------------------------------------------------------------------------------------------------------------------
  164.  
  165.  
  166. //Session Range Boxes
  167. draw_session_box(asia_session_active, asia_start, asia_end, asia_h, asia_l, asia_line_color, show_50_asian)
  168. draw_session_box(lon_session_active, lon_start, lon_end, lon_h, lon_l, lon_line_color,show_50_london)
  169. draw_session_box(usa_session_active, usa_start, usa_end, usa_h, usa_l, usa_line_color,show_50_usa)
  170.  
  171.  
  172. //Session Range Labels
  173. if show_pip_range
  174. print_session_label(asia_session_active, asia_h, asia_l, asia_start, asia_end, asia_line_color)
  175. print_session_label(lon_session_active, lon_h, lon_l, lon_start, lon_end, lon_line_color)
  176. print_session_label(usa_session_active, usa_h, usa_l, usa_start, usa_end, usa_line_color)
Advertisement
Add Comment
Please, Sign In to add comment