Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //@version=5
- indicator('Session HL', overlay=true)
- ref_res = input.timeframe(title='Reference Resolution', defval='D')
- rth_ses = input(title='Cash Session', defval='0830-1500')
- rth_ses2 = input(title='Asian Session', defval='1500-0400')
- rth_ses3 = input(title='European Session', defval='0400-0830')
- rth_ses4 = input(title='offset Session', defval='0830-1100')
- open_bar(ses) =>
- t = time(ref_res, ses)
- na(t[1]) and not na(t) or t[1] < t
- is_open(ses) =>
- not na(time(timeframe.period, ses))
- rth_open_bar = open_bar(rth_ses)
- rth_is_open = is_open(rth_ses)
- rth_is_open4 = is_open(rth_ses4)
- rth_low = float(na)
- rth_low := rth_is_open ? rth_open_bar ? low : math.min(rth_low[1], low) : rth_low[1]
- rth_high = float(na)
- rth_high := rth_is_open ? rth_open_bar ? high : math.max(rth_high[1], high) : rth_high[1]
- rth_fill_color = rth_is_open ? color.blue : na
- rth_plot_low = plot(rth_low, title='RTH Low', color=color.new(color.blue, 0), linewidth=1)
- rth_plot_high = plot(rth_high, title='RTH High', color=color.new(color.blue, 0), linewidth=1)
- fill(rth_plot_low, rth_plot_high, title='RTH Range', color=rth_fill_color, transp=90)
- rth_open_bar2 = open_bar(rth_ses2)
- rth_is_open2 = is_open(rth_ses2)
- rth_low2 = float(na)
- rth_low2 := rth_is_open2 ? rth_open_bar2 ? low : math.min(rth_low2[1], low) : rth_low2[1]
- rth_high2 = float(na)
- rth_high2 := rth_is_open2 ? rth_open_bar2 ? high : math.max(rth_high2[1], high) : rth_high2[1]
- //rth_fill_color2 = iff (rth_is_open2, color.yellow,na)
- rth_fill_color2 = rth_is_open2 ? color.white : na
- rth_plot_low2 = plot(rth_low2, title='RTH Low2', color=color.new(color.white, 0), linewidth=1)
- rth_plot_high2 = plot(rth_high2, title='RTH High2', color=color.new(color.white, 0), linewidth=1)
- fill(rth_plot_low2, rth_plot_high2, title='RTH Range2', color=rth_fill_color2, transp=90)
- rth_open_bar3 = open_bar(rth_ses3)
- rth_is_open3 = is_open(rth_ses3)
- rth_low3 = float(na)
- rth_low3 := rth_is_open3 ? rth_open_bar3 ? low : math.min(rth_low3[1], low) : rth_low3[1]
- rth_high3 = float(na)
- rth_high3 := rth_is_open3 ? rth_open_bar3 ? high : math.max(rth_high3[1], high) : rth_high3[1]
- rth_fill_color3 = rth_is_open3 ? #964720 : na
- rth_plot_low3 = plot(rth_low3, title='RTH Low3', color=color.new(#964720, 0), linewidth=1)
- rth_plot_high3 = plot(rth_high3, title='RTH High3', color=color.new(#964720, 0), linewidth=1)
- fill(rth_plot_low3, rth_plot_high3, title='RTH Range3', color=rth_fill_color3, transp=90)
- dt = time - time[1]
- if barstate.islast
- line.new(time, rth_high2, time + 1000 * dt, rth_high2, xloc=xloc.bar_time, style=line.style_solid, color=color.white, width=1)
- line.new(time, rth_low2, time + 1000 * dt, rth_low2, xloc=xloc.bar_time, style=line.style_solid, color=color.white, width=1)
- line.new(time, rth_high3, time + 1000 * dt, rth_high3, xloc=xloc.bar_time, style=line.style_solid, color=#964720, width=1)
- line.new(time, rth_low3, time + 1000 * dt, rth_low3, xloc=xloc.bar_time, style=line.style_solid, color=#964720, width=1)
- if rth_is_open
- 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)
- 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)
- else
- na
- // 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
- // siiii = line.new(time, rth_high, time + 20*dt, rth_high, xloc=xloc.bar_time, style=line.style_solid, color=color.blue, width=1)
- // prueba = rth_is_open4 ? siiii : na
- timeIsAllowed1 = time(timeframe.period, rth_ses)
- timeIsAllowed2 = time(timeframe.period, rth_ses2)
- timeIsAllowed3 = time(timeframe.period, rth_ses3)
- //Add background color
- bgcolor(timeIsAllowed1 ? color.blue : na, title='Background 1 Color', transp=95)
- bgcolor(timeIsAllowed2 ? color.white : na, title='Background 2 Color', transp=95)
- bgcolor(timeIsAllowed3 ? #964720 : na, title='Background 3 Color', transp=95)
Advertisement
Add Comment
Please, Sign In to add comment