xmd79

Session HL

Apr 30th, 2023
122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.07 KB | None | 0 0
  1. //@version=5
  2. indicator('Session HL', overlay=true)
  3. ref_res = input.timeframe(title='Reference Resolution', defval='D')
  4. rth_ses = input(title='Cash Session', defval='0830-1500')
  5. rth_ses2 = input(title='Asian Session', defval='1500-0400')
  6. rth_ses3 = input(title='European Session', defval='0400-0830')
  7. rth_ses4 = input(title='offset Session', defval='0830-1100')
  8.  
  9. open_bar(ses) =>
  10. t = time(ref_res, ses)
  11. na(t[1]) and not na(t) or t[1] < t
  12.  
  13. is_open(ses) =>
  14. not na(time(timeframe.period, ses))
  15.  
  16. rth_open_bar = open_bar(rth_ses)
  17. rth_is_open = is_open(rth_ses)
  18. rth_is_open4 = is_open(rth_ses4)
  19. rth_low = float(na)
  20. rth_low := rth_is_open ? rth_open_bar ? low : math.min(rth_low[1], low) : rth_low[1]
  21. rth_high = float(na)
  22. rth_high := rth_is_open ? rth_open_bar ? high : math.max(rth_high[1], high) : rth_high[1]
  23. rth_fill_color = rth_is_open ? color.blue : na
  24. rth_plot_low = plot(rth_low, title='RTH Low', color=color.new(color.blue, 0), linewidth=1)
  25. rth_plot_high = plot(rth_high, title='RTH High', color=color.new(color.blue, 0), linewidth=1)
  26. fill(rth_plot_low, rth_plot_high, title='RTH Range', color=rth_fill_color, transp=90)
  27.  
  28.  
  29.  
  30.  
  31.  
  32.  
  33. rth_open_bar2 = open_bar(rth_ses2)
  34. rth_is_open2 = is_open(rth_ses2)
  35. rth_low2 = float(na)
  36. rth_low2 := rth_is_open2 ? rth_open_bar2 ? low : math.min(rth_low2[1], low) : rth_low2[1]
  37. rth_high2 = float(na)
  38. rth_high2 := rth_is_open2 ? rth_open_bar2 ? high : math.max(rth_high2[1], high) : rth_high2[1]
  39. //rth_fill_color2 = iff (rth_is_open2, color.yellow,na)
  40. rth_fill_color2 = rth_is_open2 ? color.white : na
  41. rth_plot_low2 = plot(rth_low2, title='RTH Low2', color=color.new(color.white, 0), linewidth=1)
  42. rth_plot_high2 = plot(rth_high2, title='RTH High2', color=color.new(color.white, 0), linewidth=1)
  43. fill(rth_plot_low2, rth_plot_high2, title='RTH Range2', color=rth_fill_color2, transp=90)
  44.  
  45. rth_open_bar3 = open_bar(rth_ses3)
  46. rth_is_open3 = is_open(rth_ses3)
  47. rth_low3 = float(na)
  48. rth_low3 := rth_is_open3 ? rth_open_bar3 ? low : math.min(rth_low3[1], low) : rth_low3[1]
  49. rth_high3 = float(na)
  50. rth_high3 := rth_is_open3 ? rth_open_bar3 ? high : math.max(rth_high3[1], high) : rth_high3[1]
  51. rth_fill_color3 = rth_is_open3 ? #964720 : na
  52. rth_plot_low3 = plot(rth_low3, title='RTH Low3', color=color.new(#964720, 0), linewidth=1)
  53. rth_plot_high3 = plot(rth_high3, title='RTH High3', color=color.new(#964720, 0), linewidth=1)
  54. fill(rth_plot_low3, rth_plot_high3, title='RTH Range3', color=rth_fill_color3, transp=90)
  55.  
  56. dt = time - time[1]
  57. if barstate.islast
  58. line.new(time, rth_high2, time + 1000 * dt, rth_high2, xloc=xloc.bar_time, style=line.style_solid, color=color.white, width=1)
  59. line.new(time, rth_low2, time + 1000 * dt, rth_low2, xloc=xloc.bar_time, style=line.style_solid, color=color.white, width=1)
  60. line.new(time, rth_high3, time + 1000 * dt, rth_high3, xloc=xloc.bar_time, style=line.style_solid, color=#964720, width=1)
  61. line.new(time, rth_low3, time + 1000 * dt, rth_low3, xloc=xloc.bar_time, style=line.style_solid, color=#964720, width=1)
  62. if rth_is_open
  63. line.new(time - 150 * dt, rth_high[800], time + 1000 * dt, rth_high[800], xloc=xloc.bar_time, style=line.style_solid, color=#29E1D5, width=1)
  64. line.new(time - 150 * dt, rth_low[800], time + 1000 * dt, rth_low[800], xloc=xloc.bar_time, style=line.style_solid, color=#29E1D5, width=1)
  65. else
  66.  
  67. na
  68. // prueba = rth_is_open ? line.new(time, rth_high, time + 100*dt, rth_high, xloc=xloc.bar_time, style=line.style_solid, color=color.blue, width=1) : na
  69.  
  70.  
  71. // siiii = line.new(time, rth_high, time + 20*dt, rth_high, xloc=xloc.bar_time, style=line.style_solid, color=color.blue, width=1)
  72. // prueba = rth_is_open4 ? siiii : na
  73.  
  74.  
  75.  
  76. timeIsAllowed1 = time(timeframe.period, rth_ses)
  77. timeIsAllowed2 = time(timeframe.period, rth_ses2)
  78. timeIsAllowed3 = time(timeframe.period, rth_ses3)
  79.  
  80. //Add background color
  81. bgcolor(timeIsAllowed1 ? color.blue : na, title='Background 1 Color', transp=95)
  82. bgcolor(timeIsAllowed2 ? color.white : na, title='Background 2 Color', transp=95)
  83. bgcolor(timeIsAllowed3 ? #964720 : na, title='Background 3 Color', transp=95)
  84.  
  85.  
  86.  
Advertisement
Add Comment
Please, Sign In to add comment