xmd79

AsianRange and KillZones

Nov 22nd, 2021
163
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.21 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. // © rjgtrader
  3.  
  4. //@version=5
  5. indicator(title='AsianRange and KillZones', shorttitle='WinMoreFX', overlay=true)
  6.  
  7. displayZonesLimit = input.int(title='Max Timeframe To Display (Minutes)', defval=60, minval=1, maxval=1440)
  8.  
  9. //ASIA
  10. asiashow = input(true, title='Display Asia Range', group="Asia Session")
  11. asiashowdeviations = input(false, title='Display Asia Range Deviations', group="Asia Session")
  12. asiadeviations = input.int(title='Asia Deviations', defval=2, minval=1, group="Asia Session")
  13. asiacolor = input(color.new(color.aqua, 70), 'Asia Range Color', group="Asia Session")
  14. asia = input.session(title='Asia Session', defval='1900-0001', group="Asia Session")
  15.  
  16. //LONDON OPEN
  17. loshow = input(true, title='Display London Open', group="London Session")
  18. locolor = input(color.new(color.gray, 50), 'London Open Range Color', group="London Session")
  19. lo = input.session(title='London Open Session', defval='0200-0600', group="London Session")
  20.  
  21. //NY OPEN
  22. nyshow = input(true, title='Display New York Open')
  23. nycolor = input(color.new(color.gray, 50), 'New York Open Range Color', group="New York Session")
  24. ny = input.session(title='New York Open Session', defval='0700-1000', group="New York Session")
  25.  
  26. //LONDON CLOSE
  27. lcshow = input(true, title='Display London Close', group="London Close Session")
  28. lccolor = input(color.new(color.red, 50), 'London Close Range Color', group="London Close Session")
  29. lc = input.session(title='London Close Session', defval='1000-1300', group="London CLose Session")
  30.  
  31. //NY CLOSE
  32. nycshow = input(false, title='Display New York Close', group="New York Close Session")
  33. nyccolor = input(color.new(color.gray, 50), 'New York Close Range Color', group="New York Close Session")
  34. nyc = input.session(title='New York Close Session', defval='1400-1600', group="New York Close Session")
  35.  
  36. // FUNCTIONS
  37. in_session(sess) =>
  38. not na(time(timeframe.period, sess))
  39.  
  40. start_time(sess) =>
  41. int startTime = na
  42. startTime := in_session(sess) and not in_session(sess)[1] ? time : startTime[1]
  43. startTime
  44.  
  45. is_new_session(res, sess) =>
  46. t = time(res, sess)
  47. na(t[1]) and not na(t) or t[1] < t
  48.  
  49. BarInSession(sess) =>
  50. time(timeframe.period, sess) != 0
  51.  
  52. _hline(StartTime, EndTime, Price, Color, Style, Width) =>
  53. return_1 = line.new(StartTime, Price, EndTime, Price, xloc=xloc.bar_time, extend=extend.none, color=Color, style=Style, width=Width)
  54.  
  55. //PARAMS
  56. indexHighTF = barstate.isrealtime ? 0 : 0
  57. indexCurrTF = barstate.isrealtime ? 0 : 0
  58. dailyhigh = request.security(syminfo.tickerid, 'D', high, lookahead=barmerge.lookahead_on)[indexHighTF]
  59. dailylow = request.security(syminfo.tickerid, 'D', low[indexCurrTF], lookahead=barmerge.lookahead_on)[indexCurrTF]
  60.  
  61. displayZones = timeframe.isintraday and (timeframe.multiplier > displayZonesLimit ? false : true)
  62.  
  63. //ASIA BOX
  64. asia_session = is_new_session('1440', asia)
  65.  
  66. float _asialow = na
  67. float _asiahigh = na
  68. _asiabox = box(na)
  69.  
  70. _asiastart = start_time(asia)
  71. _asialow := asia_session ? low : in_session(asia) ? math.min(low, _asialow[1]) : na
  72. _asiahigh := asia_session ? high : in_session(asia) ? math.max(high, _asiahigh[1]) : na
  73. diff = _asiahigh[1] - _asialow[1]
  74.  
  75. if in_session(asia)
  76. if in_session(asia)[1]
  77. box.delete(_asiabox[1])
  78.  
  79. if low < _asialow
  80. _asialow := low
  81. _asialow
  82. if high > _asiahigh
  83. _asiahigh := high
  84. _asiahigh
  85.  
  86. if asiashow
  87. _asiabox := box.new(_asiastart, _asiahigh, time, _asialow, xloc=xloc.bar_time, bgcolor=asiacolor, border_color=asiacolor, border_style=line.style_solid)
  88. _asiabox
  89.  
  90. if asiashowdeviations and not in_session(asia) and in_session(asia)[1]
  91. for s = 1 to asiadeviations by 1
  92. _hline(_asiastart, time, _asiahigh[1] + diff * s, color.new(color.black, 0), line.style_solid, 1)
  93. _hline(_asiastart, time, _asialow[1] - diff * s, color.new(color.black, 0), line.style_solid, 1)
  94.  
  95.  
  96. //LONDON OPEN
  97. lo_session = is_new_session('1440', lo)
  98.  
  99. line _lolinelow = na
  100. line _lolinehigh = na
  101. _lostart = start_time(lo)
  102.  
  103. if in_session(lo)
  104. if in_session(lo)[1]
  105. line.delete(_lolinelow[1])
  106. line.delete(_lolinehigh[1])
  107.  
  108. if loshow
  109. _lolinehigh := line.new(_lostart, dailyhigh, time, dailyhigh, xloc=xloc.bar_time, color=locolor, style=line.style_solid, width=3)
  110. _lolinelow := line.new(_lostart, dailylow, time, dailylow, xloc=xloc.bar_time, color=locolor, style=line.style_solid, width=3)
  111. _lolinelow
  112.  
  113. //NEW YORK OPEN
  114. ny_session = is_new_session('1440', ny)
  115.  
  116. line _nylinelow = na
  117. line _nylinehigh = na
  118. _nystart = start_time(ny)
  119.  
  120. if in_session(ny)
  121. if in_session(ny)[1]
  122. line.delete(_nylinelow[1])
  123. line.delete(_nylinehigh[1])
  124.  
  125. if nyshow
  126. _nylinehigh := line.new(_nystart, dailyhigh, time, dailyhigh, xloc=xloc.bar_time, color=nycolor, style=line.style_solid, width=3)
  127. _nylinelow := line.new(_nystart, dailylow, time, dailylow, xloc=xloc.bar_time, color=nycolor, style=line.style_solid, width=3)
  128. _nylinelow
  129.  
  130. //LONDON CLOSE
  131. lc_session = is_new_session('1440', lc)
  132.  
  133. line _lclinelow = na
  134. line _lclinehigh = na
  135. _lcstart = start_time(lc)
  136.  
  137. if in_session(lc)
  138. if in_session(lc)[1]
  139. line.delete(_lclinelow[1])
  140. line.delete(_lclinehigh[1])
  141.  
  142. if lcshow
  143. _lclinehigh := line.new(_lcstart, dailyhigh, time, dailyhigh, xloc=xloc.bar_time, color=lccolor, style=line.style_solid, width=3)
  144. _lclinelow := line.new(_lcstart, dailylow, time, dailylow, xloc=xloc.bar_time, color=lccolor, style=line.style_solid, width=3)
  145. _lclinelow
  146.  
  147. //NEW YORK CLOSE
  148. nyc_session = is_new_session('1440', nyc)
  149.  
  150. line _nyclinelow = na
  151. line _nyclinehigh = na
  152. _nycstart = start_time(nyc)
  153.  
  154. if in_session(nyc)
  155. if in_session(nyc)[1]
  156. line.delete(_nyclinelow[1])
  157. line.delete(_nyclinehigh[1])
  158.  
  159. if nycshow
  160. _nyclinehigh := line.new(_nycstart, dailyhigh, time, dailyhigh, xloc=xloc.bar_time, color=nyccolor, style=line.style_solid, width=3)
  161. _nyclinelow := line.new(_nycstart, dailylow, time, dailylow, xloc=xloc.bar_time, color=nyccolor, style=line.style_solid, width=3)
  162. _nyclinelow
  163.  
  164.  
Advertisement
Add Comment
Please, Sign In to add comment