//paste everything below into pine
//
@version=6
indicator("Session Range Lines Extensions", overlay=true, max_lines_count=500)
// โโโ Inputs โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
startHour =
input.int(0, "Start Hour (EST)", minval=0, maxval=23)
startMin =
input.int(0, "Start Minute (EST)", minval=0, maxval=59)
endHour =
input.int(6, "End Hour (EST)", minval=0, maxval=23)
endMin =
input.int(0, "End Minute (EST)", minval=0, maxval=59)
extendHours =
input.int(6, "Extend Lines (hours)", minval=0, maxval=48)
showMidline = input.bool(true, "Show Midline")
showOpenLine = input.bool(true, "Show Open Line")
showLabels = input.bool(true, "Show Labels")
highColor = input.color(
color.new(#808080, 0), "High Line Color")
lowColor = input.color(
color.new(#808080, 0), "Low Line Color")
midColor = input.color(
color.new(#808080, 0), "Mid Line Color")
openColor = input.color(
color.new(#808080, 0), "Open Line Color")
lineWidth =
input.int(2, "Line Width", minval=1, maxval=4)
lineStyle_sel = input.string("Solid", "Line Style", options=["Solid", "Dashed", "Dotted"])
// โโโ Helpers โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
f_lineStyle() =>
switch lineStyle_sel
"Dashed" =>
line.style_dashed
"Dotted" =>
line.style_dotted
=>
line.style_solid
f_pad(n) =>
n < 10 ? "0" str.tostring(n) : str.tostring(n)
sessionStr = f_pad(startHour) f_pad(startMin) "-" f_pad(endHour) f_pad(endMin) ":1234567"
inRange = not na(time("", sessionStr, "America/New_York"))
// โโโ State โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
var float rangeHigh = na
var float rangeLow = na
var float rangeOpen = na
var int sessionStartBar = na
var bool lineDrawn = false
var line hiLine = na
var line loLine = na
var line midLine = na
var line openLine = na
var label hiLabel = na
var label loLabel = na
var label midLabel = na
var label openLabel = na
isSessionStart = inRange and not inRange[1]
if isSessionStart
rangeHigh := high
rangeLow := low
rangeOpen := open // capture open of first bar
sessionStartBar := bar_index
lineDrawn := false
if inRange
rangeHigh := math.max(rangeHigh, high)
rangeLow := math.min(rangeLow, low)
isSessionEnd = not inRange and inRange[1] and not na(rangeHigh) and not lineDrawn
if isSessionEnd
lineDrawn := true
extendBars = math.round((extendHours * 60 * 60) /
timeframe.in_seconds())
x1 = sessionStartBar
x2 = bar_index extendBars
if not na(hiLine)
line.delete(hiLine)
if not na(loLine)
line.delete(loLine)
if not na(midLine)
line.delete(midLine)
if not na(openLine)
line.delete(openLine)
if not na(hiLabel)
label.delete(hiLabel)
if not na(loLabel)
label.delete(loLabel)
if not na(midLabel)
label.delete(midLabel)
if not na(openLabel)
label.delete(openLabel)
hiLine :=
line.new(x1, rangeHigh, x2, rangeHigh,
xloc=
xloc.bar_index, extend=extend.none,
color=highColor, width=lineWidth, style=f_lineStyle())
loLine :=
line.new(x1, rangeLow, x2, rangeLow,
xloc=
xloc.bar_index, extend=extend.none,
color=lowColor, width=lineWidth, style=f_lineStyle())
if showOpenLine
openLine :=
line.new(x1, rangeOpen, x2, rangeOpen,
xloc=
xloc.bar_index, extend=extend.none,
color=openColor, width=lineWidth, style=f_lineStyle())
if showLabels
hiLabel :=
label.new(x2, rangeHigh,
" H " str.tostring(rangeHigh, "#.##"),
color=
color.new(highColor, 80), textcolor=highColor,
style=
label.style_label_right, size=size.small)
loLabel :=
label.new(x2, rangeLow,
" L " str.tostring(rangeLow, "#.##"),
color=
color.new(lowColor, 80), textcolor=lowColor,
style=
label.style_label_right, size=size.small)
if showOpenLine
openLabel :=
label.new(x2, rangeOpen,
" O " str.tostring(rangeOpen, "#.##"),
color=
color.new(openColor, 80), textcolor=openColor,
style=
label.style_label_right, size=size.small)
if showMidline
mid = (rangeHigh rangeLow) / 2
midLine :=
line.new(x1, mid, x2, mid,
xloc=
xloc.bar_index, extend=extend.none,
color=midColor, width=lineWidth, style=f_lineStyle())
if showLabels
midLabel :=
label.new(x2, mid,
" M " str.tostring(mid, "#.##"),
color=
color.new(midColor, 80), textcolor=midColor,
style=
label.style_label_right, size=size.small)