xmd79

Hotch Session

Apr 30th, 2023
125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 10.16 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. // © Hotchachachaaa
  3.  
  4. //@version=5
  5. indicator("Hotch Session",overlay=true,max_bars_back=500)
  6. tz = "UTC"
  7. tsAsia = input.bool( title="Show Asian Session", defval=true, group = "Asian Trade Session")
  8. startHourAsia = input.int( title="Asia Start hour", defval=0, minval=0, maxval=23, group = "Asian Trade Session")
  9. startMinuteAsia = input.int( title="Asia Start minute", defval=0, minval=0, maxval=59, group = "Asian Trade Session")
  10. endHour2Asia = input.int( title="Asia End hour", defval=8, minval=0, maxval=23, group = "Asian Trade Session")
  11. endMinute2Asia = input.int( title="Asia End minute", defval=0, minval=0, maxval=59, group = "Asian Trade Session")
  12. tsEurope = input.bool( title="Show European Session", defval=true, group = "European Trade Session")
  13. startHourEurope = input.int( title="Europen Start hour", defval=8, minval=0, maxval=23, group = "European Trade Session")
  14. startMinuteEurope = input.int( title="Europen Start minute", defval=00, minval=0, maxval=59, group = "European Trade Session")
  15. endHour2Europe = input.int( title="Europen End hour", defval=14, minval=0, maxval=23, group = "European Trade Session")
  16. endMinute2Europe = input.int( title="Europen End minute", defval=0, minval=0, maxval=59, group = "European Trade Session")
  17. tsAmericas = input.bool( title="Show American Session", defval=true, group = "American Trade Session")
  18. startHourAmericas = input.int( title="Americas Start hour", defval=12, minval=0, maxval=23, group = "American Trade Session")
  19. startMinuteAmericas = input.int( title="Americas Start minute", defval=30, minval=0, maxval=59, group = "American Trade Session")
  20. endHour2Americas = input.int( title="Americas End hour", defval=16, minval=0, maxval=23, group = "American Trade Session")
  21. endMinute2Americas = input.int( title="Americas End minute", defval=0, minval=0, maxval=59, group = "American Trade Session")
  22. tsCustom = input.bool( title="Show Custom Session", defval=false, group = "Custom Trade Session")
  23. startHourCustom = input.int( title="Custom Start hour", defval=16, minval=0, maxval=23, group = "Custom Trade Session")
  24. startMinuteCustom = input.int( title="Custom Start minute", defval=00, minval=0, maxval=59, group = "Custom Trade Session")
  25. endHour2Custom = input.int( title="Custom End hour", defval=20, minval=0, maxval=23, group = "Custom Trade Session")
  26. endMinute2Custom = input.int( title="Custom End minute", defval=0, minval=0, maxval=59, group = "Custom Trade Session")
  27. displayCustomBG = input.bool( title="Show Custom Background", defval=false, group = "Custom Trade Session")
  28. showMon = input(title="Monday", defval=true, group = "Trade Session")
  29. showTue = input(title="Tuesday", defval=true, group = "Trade Session")
  30. showWed = input(title="Wednesday", defval=true, group = "Trade Session")
  31. showThu = input(title="Thursday", defval=true, group = "Trade Session")
  32. showFri = input(title="Friday", defval=true, group = "Trade Session")
  33. showSat = input(title="Saturday", defval=false, group = "Trade Session")
  34. showSun = input(title="Sunday", defval=false, group = "Trade Session")
  35. tzYear = year(time, tz)
  36. tzMonth = month(time, tz)
  37. tzDay = dayofmonth(time, tz)
  38. tzDayOfWeek = dayofweek(time, tz)
  39. displayBG = input.bool(title="Display Session as Background Color", defval = true)
  40. displayHiLo = input.bool(title="Display Session High/Low", defval= true)
  41. ////////////////asia session
  42. startTime1Asia = timestamp(tz, tzYear, tzMonth, tzDay, startHourAsia, startMinuteAsia)
  43. endTime1Asia = timestamp(tz, tzYear, tzMonth, tzDay, endHour2Asia, endMinute2Asia)
  44. activeAsia = if startTime1Asia <= time and time <= endTime1Asia and tsAsia
  45. if tzDayOfWeek == dayofweek.monday and showMon
  46. true
  47. else if tzDayOfWeek == dayofweek.tuesday and showTue
  48. true
  49. else if tzDayOfWeek == dayofweek.wednesday and showWed
  50. true
  51. else if tzDayOfWeek == dayofweek.thursday and showThu
  52. true
  53. else if tzDayOfWeek == dayofweek.friday and showFri
  54. true
  55. else if tzDayOfWeek == dayofweek.saturday and showSat
  56. true
  57. else if tzDayOfWeek == dayofweek.sunday and showSun
  58. true
  59. else
  60. false
  61. else
  62. false
  63.  
  64. var float Asiahigh = na
  65. var float Asialow = na
  66. bgColorAsia = color.new(color.red,85)
  67. rangeColorAsia = activeAsia[1] ? color.new(color.red,0): color.new(color.red,100)
  68.  
  69. AsiaLookback= nz(ta.barssince(ta.change(activeAsia))) + 1
  70.  
  71. if activeAsia
  72.  
  73. Asiahigh := nz(ta.highest(high,AsiaLookback))
  74. Asialow := nz(ta.lowest(low,AsiaLookback))
  75.  
  76. if not activeAsia[1]
  77. Asiahigh := high[1]
  78. Asialow := low[1]
  79.  
  80. plot(displayHiLo?Asiahigh :na , color= rangeColorAsia, title= "Asia High",linewidth=2)
  81. plot(displayHiLo?Asialow :na, color= rangeColorAsia, title= "Asia Low",linewidth=2)
  82. bgcolor(activeAsia and displayBG ? bgColorAsia : na, title = "Asia Session Background")
  83.  
  84. ////////////////Europe session
  85. startTime1Europe = timestamp(tz, tzYear, tzMonth, tzDay, startHourEurope, startMinuteEurope)
  86. endTime1Europe = timestamp(tz, tzYear, tzMonth, tzDay, endHour2Europe, endMinute2Europe)
  87. activeEurope = if startTime1Europe <= time and time <= endTime1Europe and tsEurope
  88. if tzDayOfWeek == dayofweek.monday and showMon
  89. true
  90. else if tzDayOfWeek == dayofweek.tuesday and showTue
  91. true
  92. else if tzDayOfWeek == dayofweek.wednesday and showWed
  93. true
  94. else if tzDayOfWeek == dayofweek.thursday and showThu
  95. true
  96. else if tzDayOfWeek == dayofweek.friday and showFri
  97. true
  98. else if tzDayOfWeek == dayofweek.saturday and showSat
  99. true
  100. else if tzDayOfWeek == dayofweek.sunday and showSun
  101. true
  102. else
  103. false
  104. else
  105. false
  106.  
  107. var float Europehigh = na
  108. var float Europelow = na
  109. bgColorEurope = color.new(color.green,85)
  110. rangeColorEurope = activeEurope[1] ? color.new(color.green,0): color.new(color.green,100)
  111.  
  112. EuropeLookback= nz(ta.barssince(ta.change(activeEurope))) + 1
  113. if activeEurope
  114.  
  115. Europehigh := nz(ta.highest(high,EuropeLookback))
  116. Europelow := nz(ta.lowest(low,EuropeLookback))
  117.  
  118. if not activeEurope[1]
  119. Europehigh := high[1]
  120. Europelow := low[1]
  121.  
  122. plot(displayHiLo?Europehigh:na , color= rangeColorEurope, title= "Europe High",linewidth=2)
  123. plot(displayHiLo?Europelow :na , color= rangeColorEurope, title= "Europe Low",linewidth=2)
  124. bgcolor(activeEurope and displayBG ? bgColorEurope : na, title = "Europe Session Background")
  125.  
  126. ////////////////Americas session
  127. startTime1Americas = timestamp(tz, tzYear, tzMonth, tzDay, startHourAmericas, startMinuteAmericas)
  128. endTime1Americas = timestamp(tz, tzYear, tzMonth, tzDay, endHour2Americas, endMinute2Americas)
  129. activeAmericas = if startTime1Americas <= time and time <= endTime1Americas and tsAmericas
  130. if tzDayOfWeek == dayofweek.monday and showMon
  131. true
  132. else if tzDayOfWeek == dayofweek.tuesday and showTue
  133. true
  134. else if tzDayOfWeek == dayofweek.wednesday and showWed
  135. true
  136. else if tzDayOfWeek == dayofweek.thursday and showThu
  137. true
  138. else if tzDayOfWeek == dayofweek.friday and showFri
  139. true
  140. else if tzDayOfWeek == dayofweek.saturday and showSat
  141. true
  142. else if tzDayOfWeek == dayofweek.sunday and showSun
  143. true
  144. else
  145. false
  146. else
  147. false
  148.  
  149. var float Americashigh = na
  150. var float Americaslow = na
  151. bgColorAmericas = color.new(color.blue,85)
  152. rangeColorAmericas = activeAmericas[1] ? color.new(color.blue,0): color.new(color.blue,100)
  153.  
  154. AmericasLookback= nz(ta.barssince(ta.change(activeAmericas))) + 1
  155. if activeAmericas
  156.  
  157. Americashigh := nz(ta.highest(high,AmericasLookback))
  158. Americaslow := nz(ta.lowest(low,AmericasLookback))
  159.  
  160. if not activeAmericas[1]
  161. Americashigh := high[1]
  162. Americaslow := low[1]
  163.  
  164. plot(displayHiLo?Americashigh:na , color= rangeColorAmericas, title= "Americas High",linewidth=2)
  165. plot(displayHiLo?Americaslow:na , color= rangeColorAmericas, title= "Americas Low",linewidth=2)
  166. bgcolor(activeAmericas and displayBG ? bgColorAmericas : na, title = "Americas Session Background")
  167.  
  168. ////////////////Custom session
  169. startTime1Custom = timestamp(tz, tzYear, tzMonth, tzDay, startHourCustom, startMinuteCustom)
  170. endTime1Custom = timestamp(tz, tzYear, tzMonth, tzDay, endHour2Custom, endMinute2Custom)
  171. activeCustom = if startTime1Custom <= time and time <= endTime1Custom and tsCustom
  172. if tzDayOfWeek == dayofweek.monday and showMon
  173. true
  174. else if tzDayOfWeek == dayofweek.tuesday and showTue
  175. true
  176. else if tzDayOfWeek == dayofweek.wednesday and showWed
  177. true
  178. else if tzDayOfWeek == dayofweek.thursday and showThu
  179. true
  180. else if tzDayOfWeek == dayofweek.friday and showFri
  181. true
  182. else if tzDayOfWeek == dayofweek.saturday and showSat
  183. true
  184. else if tzDayOfWeek == dayofweek.sunday and showSun
  185. true
  186. else
  187. false
  188. else
  189. false
  190.  
  191. var float Customhigh = na
  192. var float Customlow = na
  193. bgColorCustom = color.new(color.yellow,85)
  194. rangeColorCustom = activeCustom[1] ? color.new(color.yellow,0): color.new(color.yellow,100)
  195.  
  196. CustomLookback= nz(ta.barssince(ta.change(activeCustom))) + 1
  197. if activeCustom
  198.  
  199. Customhigh := nz(ta.highest(high,CustomLookback))
  200. Customlow :=nz(ta.lowest(low,CustomLookback))
  201.  
  202. if not activeCustom[1]
  203. Customhigh := high[1]
  204. Customlow := low[1]
  205.  
  206. plot(displayHiLo?Customhigh:na , color= rangeColorCustom, title= "Custom High",linewidth=2)
  207. plot(displayHiLo?Customlow:na , color= rangeColorCustom, title= "Custom Low",linewidth=2)
  208. bgcolor(activeCustom and displayBG and displayCustomBG ? bgColorCustom : na, title = "Custom Session Background")
Add Comment
Please, Sign In to add comment