Average Range Lines
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © BigGuavaTrading

//@version=5
indicator("Average Range Lines", "Average Range Lines", true)

//Average Daily Range Lines
length = input(14, "Lookback Period", group = "Average Range")
timeframe = input.timeframe(defval = "W", title = "Input Timeframe")   
timehigh = request.security(syminfo.tickerid, timeframe, high)
timelow  = request.security(syminfo.tickerid, timeframe, low)
avgrange = ta.sma(timehigh,length)-ta.sma(timelow,length)

//Define Range Lines
openup2_0 = request.security(syminfo.tickerid, timeframe, (open + (avgrange*2.0)), barmerge.gaps_off, barmerge.lookahead_on)
openup1_75 = request.security(syminfo.tickerid, timeframe, (open + (avgrange*1.75)), barmerge.gaps_off, barmerge.lookahead_on)
openup1_5 = request.security(syminfo.tickerid, timeframe, (open + (avgrange*1.5)), barmerge.gaps_off, barmerge.lookahead_on)
openup1_25 = request.security(syminfo.tickerid, timeframe, (open + (avgrange*1.25)), barmerge.gaps_off, barmerge.lookahead_on)
openup1_0 = request.security(syminfo.tickerid, timeframe, (open + (avgrange*1)), barmerge.gaps_off, barmerge.lookahead_on)
openup0_75 = request.security(syminfo.tickerid, timeframe, (open + (avgrange*.75)), barmerge.gaps_off, barmerge.lookahead_on)
openup0_5 = request.security(syminfo.tickerid, timeframe, (open + (avgrange*.5)), barmerge.gaps_off, barmerge.lookahead_on)
openup0_25 = request.security(syminfo.tickerid, timeframe, (open + (avgrange*.25)), barmerge.gaps_off, barmerge.lookahead_on)
open0_0 = request.security(syminfo.tickerid, timeframe, open, barmerge.gaps_off, barmerge.lookahead_on)
opendown0_25 = request.security(syminfo.tickerid, timeframe, (open - (avgrange*.25)), barmerge.gaps_off, barmerge.lookahead_on)
opendown0_5 = request.security(syminfo.tickerid, timeframe, (open - (avgrange*.5)), barmerge.gaps_off, barmerge.lookahead_on)
opendown0_75 = request.security(syminfo.tickerid, timeframe, (open - (avgrange*.75)), barmerge.gaps_off, barmerge.lookahead_on)
opendown1_0 = request.security(syminfo.tickerid, timeframe, (open - (avgrange*1)), barmerge.gaps_off, barmerge.lookahead_on)
opendown1_25 = request.security(syminfo.tickerid, timeframe, (open - (avgrange*1.25)), barmerge.gaps_off, barmerge.lookahead_on)
opendown1_5 = request.security(syminfo.tickerid, timeframe, (open - (avgrange*1.5)), barmerge.gaps_off, barmerge.lookahead_on)
opendown1_75 = request.security(syminfo.tickerid, timeframe, (open - (avgrange*1.75)), barmerge.gaps_off, barmerge.lookahead_on)
opendown2_0 = request.security(syminfo.tickerid, timeframe, (open - (avgrange*2.0)), barmerge.gaps_off, barmerge.lookahead_on)

//Plot Range Lines
color = input(color.purple, "Apply same color to all lines")
plot(openup2_0, "+2.0 Range", color, 2, plot.style_cross)
plot(openup1_75, "+1.75 Range", color, 2, plot.style_circles)
plot(openup1_5, "+1.5 Range", color, 2, plot.style_cross)
plot(openup1_25, "+1.25 Range", color, 2, plot.style_circles)
plot(openup1_0, "+1.0 Range", color, 2, plot.style_cross)
plot(openup0_75, "+0.75 Range", color, 2, plot.style_circles)
plot(openup0_5, "+0.5 Range", color, 2, plot.style_cross)
plot(openup0_25, "+0.25 Range", color, 2, plot.style_circles)
plot(open0_0, "Timeframe Open", color, 2, plot.style_cross)
plot(opendown0_25, "-0.25 Range", color, 2, plot.style_circles)
plot(opendown0_5, "-0.5 Range", color, 2, plot.style_cross)
plot(opendown0_75, "-0.75 Range", color, 2, plot.style_circles)
plot(opendown1_0, "-1.0 Range", color, 2, plot.style_cross)
plot(opendown1_25, "-1.25 Range", color, 2, plot.style_circles)
plot(opendown1_5, "-1.5 Range", color, 2, plot.style_cross)
plot(opendown1_75, "-1.75 Range", color, 2, plot.style_circles)
plot(opendown2_0, "-2.0 Range", color, 2, plot.style_cross)

//Labelling
var label label_openup2_0 = na
label.delete(label_openup2_0)
label_openup2_0 := label.new (barstate.islast ? bar_index : na, openup2_0, text="                        +2.0", style= label.style_none, textcolor = color, size = size.normal)

var label label_openup1_75 = na
label.delete(label_openup1_75)
label_openup1_75 := label.new (barstate.islast ? bar_index : na, openup1_75, text="                        +1.75", style= label.style_none, textcolor = color, size = size.normal)

var label label_openup1_5 = na
label.delete(label_openup1_5)
label_openup1_5 := label.new (barstate.islast ? bar_index : na, openup1_5, text="                        +1.5", style= label.style_none, textcolor = color, size = size.normal)

var label label_openup1_25 = na
label.delete(label_openup1_25)
label_openup1_25 := label.new (barstate.islast ? bar_index : na, openup1_25, text="                        +1.25", style= label.style_none, textcolor = color, size = size.normal)

var label label_openup1_0 = na
label.delete(label_openup1_0)
label_openup1_0 := label.new (barstate.islast ? bar_index : na, openup1_0, text="                        +1.0", style= label.style_none, textcolor = color, size = size.normal)

var label label_openup0_75 = na
label.delete(label_openup0_75)
label_openup0_75 := label.new (barstate.islast ? bar_index : na, openup0_75, text="                        +0.75", style= label.style_none, textcolor = color, size = size.normal)

var label label_openup0_5 = na
label.delete(label_openup0_5)
label_openup0_5 := label.new (barstate.islast ? bar_index : na, openup0_5, text="                        +0.5", style= label.style_none, textcolor = color, size = size.normal)

var label label_openup0_25 = na
label.delete(label_openup0_25)
label_openup0_25 := label.new (barstate.islast ? bar_index : na, openup0_25, text="                        +0.25", style= label.style_none, textcolor = color, size = size.normal)

var label label_open0_0 = na
label.delete(label_open0_0)
label_open0_0 := label.new (barstate.islast ? bar_index : na, open0_0, text="                        Open", style= label.style_none, textcolor = color, size = size.normal)

var label label_opendown0_25 = na
label.delete(label_opendown0_25)
label_opendown0_25 := label.new (barstate.islast ? bar_index : na, opendown0_25, text="                        -0.25", style= label.style_none, textcolor = color, size = size.normal)

var label label_opendown0_5 = na
label.delete(label_opendown0_5)
label_opendown0_5 := label.new (barstate.islast ? bar_index : na, opendown0_5, text="                        -0.5", style= label.style_none, textcolor = color, size = size.normal)

var label label_opendown0_75 = na
label.delete(label_opendown0_75)
label_opendown0_75 := label.new (barstate.islast ? bar_index : na, opendown0_75, text="                        -0.75", style= label.style_none, textcolor = color, size = size.normal)

var label label_opendown1_0 = na
label.delete(label_opendown1_0)
label_opendown1_0 := label.new (barstate.islast ? bar_index : na, opendown1_0, text="                        -1.0", style= label.style_none, textcolor = color, size = size.normal)

var label label_opendown1_25 = na
label.delete(label_opendown1_25)
label_opendown1_25 := label.new (barstate.islast ? bar_index : na, opendown1_25, text="                        -1.25", style= label.style_none, textcolor = color, size = size.normal)

var label label_opendown1_5 = na
label.delete(label_opendown1_5)
label_opendown1_5 := label.new (barstate.islast ? bar_index : na, opendown1_5, text="                        -1.5", style= label.style_none, textcolor = color, size = size.normal)

var label label_opendown1_75 = na
label.delete(label_opendown1_75)
label_opendown1_75 := label.new (barstate.islast ? bar_index : na, opendown1_75, text="                        -1.75", style= label.style_none, textcolor = color, size = size.normal)

var label label_opendown2_0 = na
label.delete(label_opendown2_0)
label_opendown2_0 := label.new (barstate.islast ? bar_index : na, opendown2_0, text="                        -2.0", style= label.style_none, textcolor = color, size = size.normal)