Previous High/Low Levels
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © wolffnbear

//@version=4
study(title="Previous High/Low Levels", overlay=true)

WARNING = input(title='For Levels to work correctly, Right-click chart background, select Settings, Scales, tick “Indicator Last Value Label”', type=input.bool, defval=true, confirm=true)

res = input(title="High/Low Timeframe #1", type=input.resolution, defval="D", group = "Select Timeframe")
res2 = input(title="High/Low Timeframe #2", type=input.resolution, defval="W")
res3 = input(title="High/Low Timeframe #3", type=input.resolution, defval="M")
res4 = input(title="High/Low Timeframe #4", type=input.resolution, defval="3M")
res5 = input(title="High/Low Timeframe #5", type=input.resolution, defval="12M")

ddColor = input(title = "Timeframe #1", type = input.color, defval=#927e61, group = "Select Timeframe Color")
res2Color = input(title = "Timeframe #2", type = input.color, defval=color.blue)
res3Color = input(title = "Timeframe #3", type = input.color, defval=color.orange)
res4Color = input(title = "Timeframe #4", type = input.color, defval=color.purple)
res5Color = input(title = "Timeframe #5", type = input.color, defval=color.green)




//TIMEFRAME #1


show_dailyhl = input(title="High/Low Level", type=input.bool, defval=true, group = "TIMEFRAME #1 SETTINGS")
show_dailyhll = input(title="High/Low Label", type=input.bool, defval=false)

dayHH = security(syminfo.tickerid, res, high[1], lookahead=true)
dayHL = security(syminfo.tickerid, res, low[1], lookahead=true)

ildd = input(title="High/Low Label Offset (L-R, 0-50)", type=input.integer, defval=5, minval=1, maxval=70)
lwdhl = input(title="High/Low Level Linewidth (Small-Large, 1-5)", type=input.integer, defval=1, minval=1, maxval=5)


//TIMEFRAME #2


show_res2hl = input(title="High/Low Level", type=input.bool, defval=false, group="TIMEFRAME #2 SETTINGS")
show_res2hll = input(title="High/Low Label", type=input.bool, defval=false)

res2HH = security(syminfo.tickerid, res2, high[1], lookahead=true)
res2HL = security(syminfo.tickerid, res2, low[1], lookahead=true)

ilres2 = input(title="High/Low Label Offset (L-R, 0-50)", type=input.integer, defval=7, minval=1, maxval=70)
lwres2hl = input(title="High/Low Level Linewidth (Small-Large, 1-5)", type=input.integer, defval=1, minval=1, maxval=5)

//TIMEFRAME #3


show_res3hl = input(title="High/Low Level", type=input.bool, defval=false, group="TIMEFRAME #3 SETTINGS")
show_res3hll = input(title="High/Low Label", type=input.bool, defval=false)

res3HH = security(syminfo.tickerid, res3, high[1], lookahead=true)
res3HL = security(syminfo.tickerid, res3, low[1], lookahead=true)

ilres3 = input(title="High/Low Label Offset (L-R, 0-50)", type=input.integer, defval=9, minval=1, maxval=70)
lwres3hl = input(title="High/Low Level Linewidth (Small-Large, 1-5)", type=input.integer, defval=1, minval=1, maxval=5)

//TIMEFRAME #4


show_res4hl = input(title="High/Low Level", type=input.bool, defval=false, group="TIMEFRAME #4 SETTINGS")
show_res4hll = input(title="High/Low Label", type=input.bool, defval=false)

res4HH = security(syminfo.tickerid, res4, high[1], lookahead=true)
res4HL = security(syminfo.tickerid, res4, low[1], lookahead=true)

ilres4 = input(title="High/Low Label Offset (L-R, 0-50)", type=input.integer, defval=11, minval=1, maxval=70)
lwres4hl = input(title="High/Low Level Linewidth (Small-Large, 1-5)", type=input.integer, defval=1, minval=1, maxval=5)

//TIMEFRAME #5


show_res5hl = input(title="High/Low Level", type=input.bool, defval=false, group="TIMEFRAME #5 SETTINGS")
show_res5hll = input(title="High/Low Label", type=input.bool, defval=false)

res5HH = security(syminfo.tickerid, res5, high[1], lookahead=true)
res5HL = security(syminfo.tickerid, res5, low[1], lookahead=true)

ilres5 = input(title="High/Low Label Offset (L-R, 0-50)", type=input.integer, defval=14, minval=1, maxval=70)
lwres5hl = input(title="High/Low Level Linewidth (Small-Large, 1-5)", type=input.integer, defval=1, minval=1, maxval=5)



//OVERALL SETTINGS


txtcc = input(title="High/Low Label Text Color", type=input.color, defval=color.black, group="TEXT COLORS AND LINE STYLE SETTINGS")

hllstyle = input(title="High/Low Line Style", options=["solid (─)", "dotted (┈)", "dashed (╌)", "arrow left (←)", "arrow right (→)", "arrows both (↔)"], defval="solid (─)")

hlllist(s)=>(s == "dotted (┈)") ? line.style_dotted : (s == "dashed (╌)") ? line.style_dashed : (s == "arrow left (←)") ? line.style_arrow_left : (s == "arrow right (→)") ? line.style_arrow_right : (s == "arrows both (↔)") ? line.style_arrow_both : line.style_solid
wllist(s)=>(s == "dotted (┈)") ? line.style_dotted : (s == "dashed (╌)") ? line.style_dashed : (s == "arrow left (←)") ? line.style_arrow_left : (s == "arrow right (→)") ? line.style_arrow_right : (s == "arrows both (↔)") ? line.style_arrow_both : line.style_solid



// TIMEFRAME #1 LINES

//daily high and low labels
plotshape(show_dailyhll ? dayHH : na, style=shape.labeldown, size=size.tiny, location=location.absolute, color=ddColor, textcolor=txtcc,show_last=1, text="High", offset=ildd, title="High Label")
plotshape(show_dailyhll ? dayHL : na, style=shape.labelup, size=size.tiny, location=location.absolute, color=ddColor, textcolor=txtcc, show_last=1, text="Low", offset=ildd, title="Low Label")

//daily high and low level price tags
plot(show_dailyhl ? dayHH : na, style=plot.style_line, color=ddColor, show_last=1, linewidth=lwdhl, title="High Price")
plot(show_dailyhl ? dayHL : na, style=plot.style_line, color=ddColor, show_last=1, linewidth=lwdhl, title="Low Price")

// High and Low Levels

dopenPrice(tf) => security(syminfo.tickerid, tf, time[1])
dlowPrice(tf) => security(syminfo.tickerid, tf, low[1])
dhighPrice(tf) => security(syminfo.tickerid, tf, high[1])

ddayLow = show_dailyhl ? dlowPrice(res) : na
ddayHigh = show_dailyhl ? dhighPrice(res) : na
ddayOpen = show_dailyhl ? dopenPrice(res) : na
ddayLineLow = line.new(x1=ddayOpen, y1=ddayLow, x2=time, y2=ddayLow, xloc = xloc.bar_time, extend = extend.right, color=ddColor, width=lwdhl)
line.set_style(ddayLineLow,style=hlllist(hllstyle))
line.delete(ddayLineLow[1])
ddayLineHigh = line.new(x1=ddayOpen, y1=ddayHigh, x2=time,y2=ddayHigh, xloc = xloc.bar_time, extend = extend.right, color=ddColor, width=lwdhl)
line.set_style(ddayLineHigh,style=hlllist(hllstyle))
line.delete(ddayLineHigh[1])



// TIMEFRAME #2 LINES

//res2 high and low labels
plotshape(show_res2hll ? res2HH : na, style=shape.labeldown, size=size.tiny, location=location.absolute, color=res2Color, textcolor=txtcc,show_last=1, text="High", offset=ilres2, title="High Label")
plotshape(show_res2hll ? res2HL : na, style=shape.labelup, size=size.tiny, location=location.absolute, color=res2Color, textcolor=txtcc, show_last=1, text="Low", offset=ilres2, title="Low Label")

//daily high and low level price tags
plot(show_res2hl ? res2HH : na, style=plot.style_line, color=res2Color, show_last=1, linewidth=lwres2hl, title="High Price")
plot(show_res2hl ? res2HL : na, style=plot.style_line, color=res2Color, show_last=1, linewidth=lwres2hl, title="Low Price")

// High and Low Levels

res2openPrice(tf) => security(syminfo.tickerid, tf, time[1])
res2lowPrice(tf) => security(syminfo.tickerid, tf, low[1])
res2highPrice(tf) => security(syminfo.tickerid, tf, high[1])

res2ayLow = show_res2hl ? res2lowPrice(res2) : na
res2ayHigh = show_res2hl ? res2highPrice(res2) : na
res2ayOpen = show_res2hl ? res2openPrice(res2) : na
res2ayLineLow = line.new(x1=res2ayOpen, y1=res2ayLow, x2=time, y2=res2ayLow, xloc = xloc.bar_time, extend = extend.right, color=res2Color, width=lwres2hl)
line.set_style(res2ayLineLow,style=hlllist(hllstyle))
line.delete(res2ayLineLow[1])
res2ayLineHigh = line.new(x1=res2ayOpen, y1=res2ayHigh, x2=time,y2=res2ayHigh, xloc = xloc.bar_time, extend = extend.right, color=res2Color, width=lwres2hl)
line.set_style(res2ayLineHigh,style=hlllist(hllstyle))
line.delete(res2ayLineHigh[1])

// TIMEFRAME #3 LINES

//res3 high and low labels
plotshape(show_res3hll ? res3HH : na, style=shape.labeldown, size=size.tiny, location=location.absolute, color=res3Color, textcolor=txtcc,show_last=1, text="High", offset=ilres3, title="High Label")
plotshape(show_res3hll ? res3HL : na, style=shape.labelup, size=size.tiny, location=location.absolute, color=res3Color, textcolor=txtcc, show_last=1, text="Low", offset=ilres3, title="Low Label")

//daily high and low level price tags
plot(show_res3hl ? res3HH : na, style=plot.style_line, color=res3Color, show_last=1, linewidth=lwres3hl, title="High Price")
plot(show_res3hl ? res3HL : na, style=plot.style_line, color=res3Color, show_last=1, linewidth=lwres3hl, title="Low Price")

// High and Low Levels

res3openPrice(tf) => security(syminfo.tickerid, tf, time[1])
res3lowPrice(tf) => security(syminfo.tickerid, tf, low[1])
res3highPrice(tf) => security(syminfo.tickerid, tf, high[1])

res3ayLow = show_res3hl ? res3lowPrice(res3) : na
res3ayHigh = show_res3hl ? res3highPrice(res3) : na
res3ayOpen = show_res3hl ? res3openPrice(res3) : na
res3ayLineLow = line.new(x1=res3ayOpen, y1=res3ayLow, x2=time, y2=res3ayLow, xloc = xloc.bar_time, extend = extend.right, color=res3Color, width=lwres3hl)
line.set_style(res3ayLineLow,style=hlllist(hllstyle))
line.delete(res3ayLineLow[1])
res3ayLineHigh = line.new(x1=res3ayOpen, y1=res3ayHigh, x2=time,y2=res3ayHigh, xloc = xloc.bar_time, extend = extend.right, color=res3Color, width=lwres3hl)
line.set_style(res3ayLineHigh,style=hlllist(hllstyle))
line.delete(res3ayLineHigh[1])

// TIMEFRAME #4 LINES

//res4 high and low labels
plotshape(show_res4hll ? res4HH : na, style=shape.labeldown, size=size.tiny, location=location.absolute, color=res4Color, textcolor=txtcc,show_last=1, text="High", offset=ilres4, title="High Label")
plotshape(show_res4hll ? res4HL : na, style=shape.labelup, size=size.tiny, location=location.absolute, color=res4Color, textcolor=txtcc, show_last=1, text="Low", offset=ilres4, title="Low Label")

//daily high and low level price tags
plot(show_res4hl ? res4HH : na, style=plot.style_line, color=res4Color, show_last=1, linewidth=lwres4hl, title="High Price")
plot(show_res4hl ? res4HL : na, style=plot.style_line, color=res4Color, show_last=1, linewidth=lwres4hl, title="Low Price")

// High and Low Levels

res4openPrice(tf) => security(syminfo.tickerid, tf, time[1])
res4lowPrice(tf) => security(syminfo.tickerid, tf, low[1])
res4highPrice(tf) => security(syminfo.tickerid, tf, high[1])

res4ayLow = show_res4hl ? res4lowPrice(res4) : na
res4ayHigh = show_res4hl ? res4highPrice(res4) : na
res4ayOpen = show_res4hl ? res4openPrice(res4) : na
res4ayLineLow = line.new(x1=res4ayOpen, y1=res4ayLow, x2=time, y2=res4ayLow, xloc = xloc.bar_time, extend = extend.right, color=res4Color, width=lwres4hl)
line.set_style(res4ayLineLow,style=hlllist(hllstyle))
line.delete(res4ayLineLow[1])
res4ayLineHigh = line.new(x1=res4ayOpen, y1=res4ayHigh, x2=time,y2=res4ayHigh, xloc = xloc.bar_time, extend = extend.right, color=res4Color, width=lwres4hl)
line.set_style(res4ayLineHigh,style=hlllist(hllstyle))
line.delete(res4ayLineHigh[1])

// TIMEFRAME #5 LINES

//res5 high and low labels
plotshape(show_res5hll ? res5HH : na, style=shape.labeldown, size=size.tiny, location=location.absolute, color=res5Color, textcolor=txtcc,show_last=1, text="High", offset=ilres5, title="High Label")
plotshape(show_res5hll ? res5HL : na, style=shape.labelup, size=size.tiny, location=location.absolute, color=res5Color, textcolor=txtcc, show_last=1, text="Low", offset=ilres5, title="Low Label")

//daily high and low level price tags
plot(show_res5hl ? res5HH : na, style=plot.style_line, color=res5Color, show_last=1, linewidth=lwres5hl, title="High Price")
plot(show_res5hl ? res5HL : na, style=plot.style_line, color=res5Color, show_last=1, linewidth=lwres5hl, title="Low Price")

// High and Low Levels

res5openPrice(tf) => security(syminfo.tickerid, tf, time[1])
res5lowPrice(tf) => security(syminfo.tickerid, tf, low[1])
res5highPrice(tf) => security(syminfo.tickerid, tf, high[1])

res5ayLow = show_res5hl ? res5lowPrice(res5) : na
res5ayHigh = show_res5hl ? res5highPrice(res5) : na
res5ayOpen = show_res5hl ? res5openPrice(res5) : na
res5ayLineLow = line.new(x1=res5ayOpen, y1=res5ayLow, x2=time, y2=res5ayLow, xloc = xloc.bar_time, extend = extend.right, color=res5Color, width=lwres5hl)
line.set_style(res5ayLineLow,style=hlllist(hllstyle))
line.delete(res5ayLineLow[1])
res5ayLineHigh = line.new(x1=res5ayOpen, y1=res5ayHigh, x2=time,y2=res5ayHigh, xloc = xloc.bar_time, extend = extend.right, color=res5Color, width=lwres5hl)
line.set_style(res5ayLineHigh,style=hlllist(hllstyle))
line.delete(res5ayLineHigh[1])


