xmd79

AV

Oct 4th, 2021
237
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.81 KB | None | 0 0
  1. //@version=4
  2. study("AV", overlay=true)
  3. //plot(timestamp(syminfo.timezone,year(timenow),month(timenow),dayofmonth(timenow), hour(timenow), minute(timenow)),color=color.blue)
  4.  
  5. debugColor = color.new(color.green, 100)
  6. maxBoxCount = input(title="Maximum box count", type=input.integer, defval=100)
  7.  
  8. lineWidth = input(title="Line width", type=input.integer, defval=1)
  9.  
  10. defaultEuropeColor = color.new(#F0FFFF, 0)
  11. defaultUSAColor = color.new(#FFE4E1,0)
  12. defaultAsiaColor = color.new(#FFFFED,0)
  13.  
  14. EuropeBorderColor = input(title="Europe box border",type=input.color, defval=#A0AAAA)
  15. EuropeBackgroundColor = input(title="Europe background colour",type=input.color, defval=defaultEuropeColor)
  16.  
  17. USABorderColor = input(title="USA box border",type=input.color, defval=#AA9090)
  18. USABackgroundColor = input(title="USA background colour",type=input.color, defval=defaultUSAColor)
  19.  
  20. AsiaBorderColor = input(title="Asia (Aust/NZ/JP) box border",type=input.color, defval=#909995)
  21. AsiaBackgroundColor = input(title="Asia (Aust/NZ/JP) background colour",type=input.color, defval=defaultAsiaColor)
  22.  
  23. europe = input(title="Europe Session", type=input.bool, defval=true)
  24. usa=input(title="New York Session", type=input.bool, defval=true)
  25. asia = input(title="Asia Session", type=input.bool, defval=true)
  26.  
  27.  
  28. ///Sessions
  29.  
  30. Europe = input(title="Europe Session", type=input.session, defval="0300-1200")
  31. USA = input(title="New York Session", type=input.session, defval="0800-1700")
  32. Asia = input(title="Asia (NZ/Aust/JP) Session", type=input.session, defval="1700-0400")
  33.  
  34. //Bars
  35. is_newbar(sess) =>
  36. t = time("D", sess)
  37. na(t[1]) and not na(t) or t[1] < t
  38.  
  39. is_session(sess) =>
  40. not na(time("D", sess))
  41.  
  42.  
  43. //Europe
  44. europeNewbar = is_newbar(Europe)
  45. europeSession = is_session(Europe)
  46. //europeBox = box.new(na,na,na,na,border_width=2,xloc=xloc.bar_time,border_style=line.style_solid, border_color=EuropeBorderColor, bgcolor=EuropeBackgroundColor)
  47. //plotshape(europeNewbar,"eu new",style=shape.xcross)
  48. if europe and europeSession
  49.  
  50. float europeLow = na
  51. europeLow := if europeSession
  52. if europeNewbar
  53. low
  54. else
  55. min(europeLow[1],low)
  56. else
  57. europeLow[1]
  58.  
  59. float europeHigh = na
  60. europeHigh := if europeSession
  61. if europeNewbar
  62. high
  63. else
  64. max(europeHigh[1],high)
  65. else
  66. europeHigh[1]
  67.  
  68. int europeStart=na
  69. europeStart := if europeSession
  70. if europeNewbar
  71. time
  72. else
  73. min(europeStart[1],time)
  74. else
  75. na
  76. int europeEnd=na
  77. europeEnd := if europeSession
  78. if europeNewbar
  79. time_close
  80. else
  81. max(europeEnd[1],time_close)
  82. else
  83. na
  84.  
  85.  
  86. europeBox = if europeNewbar
  87. box.new(left=europeStart, bottom=europeLow, right=europeEnd, top=europeHigh,border_width=lineWidth,xloc=xloc.bar_time,border_style=line.style_solid, border_color=EuropeBorderColor, bgcolor=EuropeBackgroundColor )
  88.  
  89. if not europeNewbar
  90.  
  91. box.set_right(europeBox[1], europeEnd)
  92. box.set_top(europeBox[1], europeHigh)
  93. box.set_bottom(europeBox[1], europeLow)
  94.  
  95. if timeframe.period == "240"
  96. box.delete(europeBox[maxBoxCount])
  97.  
  98. //New York
  99. usaNewbar = is_newbar(USA)
  100. usaSession = is_session(USA)
  101.  
  102. if usa and usaSession
  103. float usaLow = na
  104. usaLow := if usaSession
  105. if usaNewbar
  106. low
  107. else
  108. min(usaLow[1],low)
  109. else
  110. usaLow[1]
  111.  
  112. float usaHigh = na
  113. usaHigh := if usaSession
  114. if usaNewbar
  115. high
  116. else
  117. max(usaHigh[1],high)
  118. else
  119. usaHigh[1]
  120.  
  121. int usaStart=na
  122. usaStart := if usaSession
  123. if usaNewbar
  124. time
  125. else
  126. min(usaStart[1],time)
  127. else
  128. na
  129.  
  130. int usaEnd=na
  131. usaEnd := if usaSession
  132. if usaNewbar
  133. time_close
  134. else
  135. max(usaEnd[1],time_close)
  136. else
  137. na
  138.  
  139.  
  140. usaBox = if usaNewbar
  141. usaBox = box.new(left=usaStart, bottom=usaLow, right=usaEnd, top=usaHigh,border_width=lineWidth,xloc=xloc.bar_time,border_style=line.style_solid, border_color=USABorderColor, bgcolor=USABackgroundColor )
  142.  
  143. if not usaNewbar
  144.  
  145. box.set_right(usaBox[1], usaEnd)
  146. box.set_top(usaBox[1], usaHigh)
  147. box.set_bottom(usaBox[1], usaLow)
  148.  
  149. if timeframe.period == "240"
  150. box.delete(usaBox[maxBoxCount])
  151.  
  152.  
  153. //Asia
  154. asiaNewbar = is_newbar(Asia)
  155. asiaSession = is_session(Asia)
  156. if asia and asiaSession
  157.  
  158.  
  159. float asiaLow = na
  160. asiaLow := if asiaSession
  161. if asiaNewbar
  162. low
  163. else
  164. min(asiaLow[1],low)
  165. else
  166. asiaLow[1]
  167.  
  168. float asiaHigh = na
  169. asiaHigh := if asiaSession
  170. if asiaNewbar
  171. high
  172. else
  173. max(asiaHigh[1],high)
  174. else
  175. asiaHigh[1]
  176.  
  177. int asiaStart = na
  178. asiaStart := if asiaSession
  179. if asiaNewbar
  180. time
  181. else
  182. min(asiaStart[1],time)
  183. else
  184. na
  185.  
  186. int asiaEnd = na
  187. asiaEnd := if asiaSession
  188. if asiaNewbar
  189. time_close
  190. else
  191. max(asiaEnd[1],time_close)
  192. else
  193. na
  194.  
  195.  
  196. asiaBox = if asiaNewbar
  197. box.new(left=asiaStart, bottom=asiaLow, right=asiaEnd, top=asiaHigh,border_width=lineWidth,xloc=xloc.bar_time,border_style=line.style_solid, border_color=AsiaBorderColor, bgcolor=AsiaBackgroundColor )
  198.  
  199. if not asiaNewbar
  200. box.set_right(asiaBox[1], asiaEnd)
  201. box.set_top(asiaBox[1], asiaHigh)
  202. box.set_bottom(asiaBox[1], asiaLow)
  203.  
  204. if timeframe.period == "240"
  205. box.delete(asiaBox[maxBoxCount])
Advertisement
Add Comment
Please, Sign In to add comment