Prev  2M, 2W, 2D Lvls
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © SchroedingerzCat

//@version=5
indicator(title='Prev  2M, 2W, 2D Lvls', shorttitle = " ",overlay=true)

tfd = timeframe.isintraday?1:0
tfw = 1
if tfd!=1
    tfd:=timeframe.isdaily?1:0
    if tfd!=1
        tfw := timeframe.isweekly?1:0


show_last_2_mon = input(true,title="Show previous 2 month lines")
show_last_2_wk = input(true,title="Show previous 2 Week lines")
show_last_2_dy = input(true,title="Show previous 2 Day lines")

C1 = input.color(#00bcd4,"Select -1W color")
C2 = input.color(#006064,"Select -2W color")

C3 = input.color(#9c27b0,"Select -1D color")
C4 = input.color(#880e4f,"Select -2D color")

C5 = input.color(#ffffff, "Select -1M color")
C6 = input.color(#b2b5be, "Select -2M color")

pw1h = request.security(syminfo.tickerid, 'W', high[1])
pw1l = request.security(syminfo.tickerid, 'W', low[1])
pw2h = request.security(syminfo.tickerid, 'W', high[2])
pw2l = request.security(syminfo.tickerid, 'W', low[2])

pw2t = request.security(syminfo.tickerid, 'W', time[2])
pw1t = request.security(syminfo.tickerid, 'W', time[1])

pd1h = request.security(syminfo.tickerid, 'D', high[1])
pd1l = request.security(syminfo.tickerid, 'D', low[1])
pd2h = request.security(syminfo.tickerid, 'D', high[2])
pd2l = request.security(syminfo.tickerid, 'D', low[2])

pd2t = request.security(syminfo.tickerid, 'D', time[2])
pd1t = request.security(syminfo.tickerid, 'D', time[1])

pm1h = request.security(syminfo.tickerid, 'M', high[1])
pm1l = request.security(syminfo.tickerid, 'M', low[1])
pm2h = request.security(syminfo.tickerid, 'M', high[2])
pm2l = request.security(syminfo.tickerid, 'M', low[2])

pm2t = request.security(syminfo.tickerid, 'M', time[2])
pm1t = request.security(syminfo.tickerid, 'M', time[1])

W1H="-1W"+" H"
W1L="-1W"+" L"
W2H="-2W"+" H"
W2L="-2W"+" L"

D1H="-1D"+" H"
D1L="-1D"+" L"
D2H="-2D"+" H"
D2L="-2D"+" L"

M1H="-1M"+" H"
M2H="-2M"+" H"
M1L="-1M"+" L"
M2L="-2M"+" L"


if show_last_2_dy
    if tfd==1
        ld1h=line.new(x1=pd1t,y1=pd1h,x2=time, y2=pd1h,xloc=xloc.bar_time,extend=extend.right,color=C3,style=line.style_solid,width=1)
        ld1l=line.new(x1=pd1t,y1=pd1l,x2=time, y2=pd1l,xloc=xloc.bar_time,extend=extend.right,color=C3,style=line.style_solid,width=1)
        ld2h=line.new(x1=pd2t,y1=pd2h,x2=time, y2=pd2h,xloc=xloc.bar_time,extend=extend.right,color=C4,style=line.style_solid,width=1)
        ld2l=line.new(x1=pd2t,y1=pd2l,x2=time, y2=pd2l,xloc=xloc.bar_time,extend=extend.right,color=C4,style=line.style_solid,width=1)
    
        line.delete(ld1h[1])
        line.delete(ld1l[1])
        line.delete(ld2h[1]) 
        line.delete(ld2l[1])

plot(pd1h, title=D1H, editable=true, color=C3, linewidth=1, offset=-9999, display=display.none)
plot(pd1l, title=D1L, editable=true, color=C3, linewidth=1, offset=-9999, display=display.none)
plot(pd2h, title=D2H, editable=true, color=C4, linewidth=1, offset=-9999, display=display.none)
plot(pd2l, title=D2L, editable=true, color=C4, linewidth=1, offset=-9999, display=display.none)


if show_last_2_wk
    if tfw==1
        lw1h=line.new(x1=pw1t,y1=pw1h,x2=time, y2=pw1h,xloc=xloc.bar_time,extend=extend.right,color=C1,style=line.style_solid,width=0)
        lw1l=line.new(x1=pw1t,y1=pw1l,x2=time, y2=pw1l,xloc=xloc.bar_time,extend=extend.right,color=C1,style=line.style_solid,width=1)
        lw2h=line.new(x1=pw2t,y1=pw2h,x2=time, y2=pw2h,xloc=xloc.bar_time,extend=extend.right,color=C2,style=line.style_solid,width=1)
        lw2l=line.new(x1=pw2t,y1=pw2l,x2=time, y2=pw2l,xloc=xloc.bar_time,extend=extend.right,color=C2,style=line.style_solid,width=1)
    
        line.delete(lw1h[1])
        line.delete(lw1l[1])
        line.delete(lw2h[1]) 
        line.delete(lw2l[1])

plot(pw1h, title=W1H, editable=true, color=C1, linewidth=1, offset=-9999, display=display.none)
plot(pw1l, title=W1L, editable=true, color=C1, linewidth=1, offset=-9999, display=display.none)
plot(pw2h, title=W2H, editable=true, color=C2, linewidth=1, offset=-9999, display=display.none)
plot(pw2l, title=W2L, editable=true, color=C2, linewidth=1, offset=-9999, display=display.none)


if show_last_2_mon
    lm1h=line.new(x1=pm1t,y1=pm1h,x2=time, y2=pm1h,xloc=xloc.bar_time,extend=extend.right,color=C5,style=line.style_solid,width=1)
    lm1l=line.new(x1=pm1t,y1=pm1l,x2=time, y2=pm1l,xloc=xloc.bar_time,extend=extend.right,color=C5,style=line.style_solid,width=1)
    lm2h=line.new(x1=pm2t,y1=pm2h,x2=time, y2=pm2h,xloc=xloc.bar_time,extend=extend.right,color=C6,style=line.style_solid,width=1)
    lm2l=line.new(x1=pm2t,y1=pm2l,x2=time, y2=pm2l,xloc=xloc.bar_time,extend=extend.right,color=C6,style=line.style_solid,width=1)
    
    line.delete(lm1h[1])
    line.delete(lm2h[1])
    line.delete(lm1l[1])
    line.delete(lm2l[1])


plot(pm1h, title=M1H, editable=true, color=C5, linewidth=1, offset=-9999, display=display.none)
plot(pm1l, title=M1L, editable=true, color=C5, linewidth=1, offset=-9999, display=display.none)
plot(pm2h, title=M2H, editable=true, color=C6, linewidth=1, offset=-9999, display=display.none)
plot(pm2l, title=M2L, editable=true, color=C6, linewidth=1, offset=-9999, display=display.none)


