OPEN-SOURCE SCRIPT
Key Levels

// This Pine Script® code is subject to the terms of the Mozilla Public License 2.0 at mozilla.org/MPL/2.0/
// © kenmorley
// Key Levels Indicator
// This indicator plots key levels on the chart:
// Current session high (High of Day) and low (Low of Day)
// Previous day high (Prev Day High), low (Prev Day Low), and close (Prev Day Close)
// Overnight high (ONH) and low (ONL) based on a defined overnight window
// At the start of a new session (Day), the indicator resets its values and creates a new set of labels.
// These labels are positioned in a fixed horizontal column (offset from the current bar) and are updated each bar
// so that they remain vertically aligned with their corresponding level (with a small vertical offset).
//
// Inputs you can modify:
// - Futures Mode and session times for equities and futures.
// - Horizontal label offset (in bars) and vertical offset (price units) for label positioning.
// - Colors, line widths, and styles for each level (day high, day low, overnight high/low, previous day levels).
// Adjust these inputs to match your market hours and desired appearance.
//version=6
indicator("Key Levels", overlay=true, shorttitle="Key Levels", max_lines_count=500)
// ============================================================================
// Input: Futures Mode and Session Settings
// ============================================================================
futuresMode = input.bool(false, "Futures Mode", tooltip="Enable if running on futures contracts")
regularSessionEquity = input.session("0930-1600", title="Equity Regular Session")
regularSessionFut = input.session("0900-1600", title="Futures Regular Session")
regularSession = futuresMode ? regularSessionFut : regularSessionEquity
// ============================================================================
// Label Offset Inputs
// ============================================================================
labelOffset = input.int(50, "Horizontal Label Offset (bars)", minval=1)
labelVOffset = input.float(0.1, "Label Vertical Offset", step=0.1, tooltip="Distance above (for highs) or below (for lows) the corresponding line")
// ============================================================================
// Determine Session Membership and Overnight Window
// ============================================================================
inRegular = not na(time(timeframe.period, regularSession))
// For equities, define overnight as 04:00–09:29 (inclusive of 04:00)
// For futures, define overnight as from after session close (16:00) until session open (09:00)
overnightManual = futuresMode ? (hour >= 16 or hour < 9) : (hour >= 4 and (hour < 9 or (hour == 9 and minute <= 29)))
// ============================================================================
// New Day / Regular Session Start Detection
// ============================================================================
eqSessionStart = (not futuresMode) and (hour == 9 and minute == 30)
futSessionStart = futuresMode and (hour == 9 and minute == 0)
sessionStart = futuresMode ? futSessionStart : eqSessionStart
// Compute current day-of-year (as an integer)
currentDayOfYear = int((time - timestamp(year(time), 1, 1, 0, 0)) / 86400000) + 1
// Persistent variable to store the day-of-year of the current session.
var int sessionDay = na
// ============================================================================
// Style Inputs (group "Style")
// ============================================================================
regHighColor = input.color(color.green, "Day High Color", group="Style")
regHighWidth = input.int(2, "Day High Width", minval=1, group="Style")
regHighStyleStr = input.string("solid", "Day High Style", options=["solid", "dotted", "dashed"], group="Style")
regLowColor = input.color(color.red, "Day Low Color", group="Style")
regLowWidth = input.int(2, "Day Low Width", minval=1, group="Style")
regLowStyleStr = input.string("solid", "Day Low Style", options=["solid", "dotted", "dashed"], group="Style")
overnightHighColor = input.color(color.blue, "Overnight High Color", group="Style")
overnightHighWidth = input.int(2, "Overnight High Width", minval=1, group="Style")
overnightHighStyleStr = input.string("dotted", "Overnight High Style", options=["solid", "dotted", "dashed"], group="Style")
overnightLowColor = input.color(color.blue, "Overnight Low Color", group="Style")
overnightLowWidth = input.int(2, "Overnight Low Width", minval=1, group="Style")
overnightLowStyleStr = input.string("dotted", "Overnight Low Style", options=["solid", "dotted", "dashed"], group="Style")
prevCloseColor = input.color(color.yellow, "Previous Day Close Color", group="Style")
prevCloseWidth = input.int(2, "Previous Day Close Width", minval=1, group="Style")
prevCloseStyleStr = input.string("solid", "Previous Day Close Style", options=["solid", "dotted", "dashed"], group="Style")
prevHighColor = input.color(color.lime, "Previous Day High Color", group="Style")
prevHighWidth = input.int(2, "Previous Day High Width", minval=1, group="Style")
prevHighStyleStr = input.string("solid", "Previous Day High Style", options=["solid", "dotted", "dashed"], group="Style")
prevLowColor = input.color(color.red, "Previous Day Low Color", group="Style")
prevLowWidth = input.int(2, "Previous Day Low Width", minval=1, group="Style")
prevLowStyleStr = input.string("solid", "Previous Day Low Style", options=["solid", "dotted", "dashed"], group="Style")
// Helper function to convert style string to a line style constant.
f_line_style(str) =>
str == "solid" ? line.style_solid : str == "dotted" ? line.style_dotted : line.style_dashed
// ============================================================================
// Persistent Variables for Daily Values and Their Bar Indexes
// ============================================================================
// Current day regular session values.
var float curRegHigh = na
var float curRegLow = na
var int curRegHighBar = na
var int curRegLowBar = na
// Current day overnight values.
var float curOverHigh = na
var float curOverLow = na
var int curOverHighBar = na
var int curOverLowBar = na
// Previous day regular session values.
var float prevRegHigh = na
var float prevRegLow = na
var float prevRegClose = na
var int prevRegHighBar = na
var int prevRegLowBar = na
var int prevRegCloseBar = na
// Previous overnight values (from the previous session)
var float prevOverHigh = na
var float prevOverLow = na
var int prevOverHighBar = na
var int prevOverLowBar = na
// ============================================================================
// Persistent Label Variables (One set per day)
// ============================================================================
var label hodLabel = na
var label lodLabel = na
var label pdhLabel = na
var label pdlLabel = na
var label pdcLabel = na
var label onhLabel = na
var label onlLabel = na
// ============================================================================
// Persistent Variable for storing last regular session close
// ============================================================================
var float lastRegularClose = na
var int lastRegularCloseBar = na
// ============================================================================
// Reset on New Day / Session Start (Only Once Per Day)
// ============================================================================
if sessionStart and (na(sessionDay) or sessionDay != currentDayOfYear)
// Delete any existing labels from the previous day.
if not na(hodLabel)
label.delete(hodLabel)
if not na(lodLabel)
label.delete(lodLabel)
if not na(pdhLabel)
label.delete(pdhLabel)
if not na(pdlLabel)
label.delete(pdlLabel)
if not na(pdcLabel)
label.delete(pdcLabel)
if not na(onhLabel)
label.delete(onhLabel)
if not na(onlLabel)
label.delete(onlLabel)
// Store previous day's regular session values if available.
if not na(curRegHigh)
prevRegHigh := curRegHigh
prevRegHighBar := curRegHighBar
if not na(curRegLow)
prevRegLow := curRegLow
prevRegLowBar := curRegLowBar
if not na(lastRegularClose)
prevRegClose := lastRegularClose
prevRegCloseBar := lastRegularCloseBar
// Store previous overnight values.
if not na(curOverHigh)
prevOverHigh := curOverHigh
prevOverHighBar := curOverHighBar
if not na(curOverLow)
prevOverLow := curOverLow
prevOverLowBar := curOverLowBar
// Reset current day values.
curRegHigh := na
curRegLow := na
curRegHighBar := na
curRegLowBar := na
curOverHigh := na
curOverLow := na
curOverHighBar := na
curOverLowBar := na
// Create one set of labels only once per day.
hodLabel := label.new(bar_index+labelOffset, na, "HOD", color=color.new(color.white, 100), textcolor=regHighColor, size=size.small, style=label.style_label_right)
pdhLabel := label.new(bar_index+labelOffset, na, "PDH", color=color.new(color.white, 100), textcolor=prevHighColor, size=size.small, style=label.style_label_right)
onhLabel := label.new(bar_index+labelOffset, na, "ONH", color=color.new(color.white, 100), textcolor=overnightHighColor, size=size.small, style=label.style_label_right)
pdcLabel := label.new(bar_index+labelOffset, na, "PDC", color=color.new(color.white, 100), textcolor=prevCloseColor, size=size.small, style=label.style_label_right)
pdlLabel := label.new(bar_index+labelOffset, na, "PDL", color=color.new(color.white, 100), textcolor=prevLowColor, size=size.small, style=label.style_label_right)
onlLabel := label.new(bar_index+labelOffset, na, "ONL", color=color.new(color.white, 100), textcolor=overnightLowColor, size=size.small, style=label.style_label_right)
lodLabel := label.new(bar_index+labelOffset, na, "LOD", color=color.new(color.white, 100), textcolor=regLowColor, size=size.small, style=label.style_label_right)
sessionDay := currentDayOfYear
// ============================================================================
// Update Current Day Values
// ============================================================================
// During regular session, update HOD and LOD.
if inRegular
if na(curRegHigh) or high > curRegHigh
curRegHigh := high
curRegHighBar := bar_index
if na(curRegLow) or low < curRegLow
curRegLow := low
curRegLowBar := bar_index
// Continuously update last regular session close.
lastRegularClose := close
lastRegularCloseBar := bar_index
// Update overnight values during overnight period.
if overnightManual
if na(curOverHigh) or high > curOverHigh
curOverHigh := high
curOverHighBar := bar_index
if na(curOverLow) or low < curOverLow
curOverLow := low
curOverLowBar := bar_index
// ============================================================================
// Define Levels
// ============================================================================
// For overnight, if previous values exist, use them; otherwise use current ones.
onh_value = not na(prevOverHigh) ? prevOverHigh : curOverHigh
onh_bar = not na(prevOverHighBar) ? prevOverHighBar : curOverHighBar
onl_value = not na(prevOverLow) ? prevOverLow : curOverLow
onl_bar = not na(prevOverLowBar) ? prevOverLowBar : curOverLowBar
// ============================================================================
// Plot Horizontal Lines
// ============================================================================
var line regHighLine = na
var line regLowLine = na
var line onhLine = na
var line onlLine = na
var line prevCloseLine = na
var line prevHighLine = na
var line prevLowLine = na
if sessionStart and (sessionDay == currentDayOfYear)
if not na(regHighLine)
line.delete(regHighLine)
if not na(regLowLine)
line.delete(regLowLine)
if not na(onhLine)
line.delete(onhLine)
if not na(onlLine)
line.delete(onlLine)
if not na(prevCloseLine)
line.delete(prevCloseLine)
if not na(prevHighLine)
line.delete(prevHighLine)
if not na(prevLowLine)
line.delete(prevLowLine)
regHighLine := na
regLowLine := na
onhLine := na
onlLine := na
prevCloseLine := na
prevHighLine := na
prevLowLine := na
if not na(curRegHigh)
if na(regHighLine)
regHighLine := line.new(curRegHighBar, curRegHigh, bar_index+1, curRegHigh, extend=extend.right, color=regHighColor, style=f_line_style(regHighStyleStr), width=regHighWidth)
else
line.set_xy1(regHighLine, curRegHighBar, curRegHigh)
line.set_xy2(regHighLine, bar_index+1, curRegHigh)
if not na(curRegLow)
if na(regLowLine)
regLowLine := line.new(curRegLowBar, curRegLow, bar_index+1, curRegLow, extend=extend.right, color=regLowColor, style=f_line_style(regLowStyleStr), width=regLowWidth)
else
line.set_xy1(regLowLine, curRegLowBar, curRegLow)
line.set_xy2(regLowLine, bar_index+1, curRegLow)
if not na(onh_value)
if na(onhLine)
onhLine := line.new(onh_bar, onh_value, bar_index+1, onh_value, extend=extend.right, color=overnightHighColor, style=f_line_style(overnightHighStyleStr), width=overnightHighWidth)
else
line.set_xy1(onhLine, onh_bar, onh_value)
line.set_xy2(onhLine, bar_index+1, onh_value)
if not na(onl_value)
if na(onlLine)
onlLine := line.new(onl_bar, onl_value, bar_index+1, onl_value, extend=extend.right, color=overnightLowColor, style=f_line_style(overnightLowStyleStr), width=overnightLowWidth)
else
line.set_xy1(onlLine, onl_bar, onl_value)
line.set_xy2(onlLine, bar_index+1, onl_value)
if not na(prevRegClose)
if na(prevCloseLine)
prevCloseLine := line.new(prevRegCloseBar, prevRegClose, bar_index+1, prevRegClose, extend=extend.right, color=prevCloseColor, style=f_line_style(prevCloseStyleStr), width=prevCloseWidth)
else
line.set_xy1(prevCloseLine, prevRegCloseBar, prevRegClose)
line.set_xy2(prevCloseLine, bar_index+1, prevRegClose)
if not na(prevRegHigh)
if na(prevHighLine)
prevHighLine := line.new(prevRegHighBar, prevRegHigh, bar_index+1, prevRegHigh, extend=extend.right, color=prevHighColor, style=f_line_style(prevHighStyleStr), width=prevHighWidth)
else
line.set_xy1(prevHighLine, prevRegHighBar, prevRegHigh)
line.set_xy2(prevHighLine, bar_index+1, prevRegHigh)
if not na(prevRegLow)
if na(prevLowLine)
prevLowLine := line.new(prevRegLowBar, prevRegLow, bar_index+1, prevRegLow, extend=extend.right, color=prevLowColor, style=f_line_style(prevLowStyleStr), width=prevLowWidth)
else
line.set_xy1(prevLowLine, prevRegLowBar, prevRegLow)
line.set_xy2(prevLowLine, bar_index+1, prevRegLow)
// ============================================================================
// Update Label Positions Relative to Their Corresponding Levels
// ============================================================================
x_pos = bar_index + labelOffset
if not na(hodLabel) and not na(curRegHigh)
label.set_xy(hodLabel, x_pos, curRegHigh - labelVOffset)
if not na(lodLabel) and not na(curRegLow)
label.set_xy(lodLabel, x_pos, curRegLow + labelVOffset)
if not na(pdhLabel) and not na(prevRegHigh)
label.set_xy(pdhLabel, x_pos, prevRegHigh - labelVOffset)
if not na(pdlLabel) and not na(prevRegLow)
label.set_xy(pdlLabel, x_pos, prevRegLow + labelVOffset)
if not na(pdcLabel) and not na(prevRegClose)
label.set_xy(pdcLabel, x_pos, prevRegClose)
if not na(onhLabel) and not na(onh_value)
label.set_xy(onhLabel, x_pos, onh_value - labelVOffset)
if not na(onlLabel) and not na(onl_value)
label.set_xy(onlLabel, x_pos, onl_value + labelVOffset)
// © kenmorley
// Key Levels Indicator
// This indicator plots key levels on the chart:
// Current session high (High of Day) and low (Low of Day)
// Previous day high (Prev Day High), low (Prev Day Low), and close (Prev Day Close)
// Overnight high (ONH) and low (ONL) based on a defined overnight window
// At the start of a new session (Day), the indicator resets its values and creates a new set of labels.
// These labels are positioned in a fixed horizontal column (offset from the current bar) and are updated each bar
// so that they remain vertically aligned with their corresponding level (with a small vertical offset).
//
// Inputs you can modify:
// - Futures Mode and session times for equities and futures.
// - Horizontal label offset (in bars) and vertical offset (price units) for label positioning.
// - Colors, line widths, and styles for each level (day high, day low, overnight high/low, previous day levels).
// Adjust these inputs to match your market hours and desired appearance.
//version=6
indicator("Key Levels", overlay=true, shorttitle="Key Levels", max_lines_count=500)
// ============================================================================
// Input: Futures Mode and Session Settings
// ============================================================================
futuresMode = input.bool(false, "Futures Mode", tooltip="Enable if running on futures contracts")
regularSessionEquity = input.session("0930-1600", title="Equity Regular Session")
regularSessionFut = input.session("0900-1600", title="Futures Regular Session")
regularSession = futuresMode ? regularSessionFut : regularSessionEquity
// ============================================================================
// Label Offset Inputs
// ============================================================================
labelOffset = input.int(50, "Horizontal Label Offset (bars)", minval=1)
labelVOffset = input.float(0.1, "Label Vertical Offset", step=0.1, tooltip="Distance above (for highs) or below (for lows) the corresponding line")
// ============================================================================
// Determine Session Membership and Overnight Window
// ============================================================================
inRegular = not na(time(timeframe.period, regularSession))
// For equities, define overnight as 04:00–09:29 (inclusive of 04:00)
// For futures, define overnight as from after session close (16:00) until session open (09:00)
overnightManual = futuresMode ? (hour >= 16 or hour < 9) : (hour >= 4 and (hour < 9 or (hour == 9 and minute <= 29)))
// ============================================================================
// New Day / Regular Session Start Detection
// ============================================================================
eqSessionStart = (not futuresMode) and (hour == 9 and minute == 30)
futSessionStart = futuresMode and (hour == 9 and minute == 0)
sessionStart = futuresMode ? futSessionStart : eqSessionStart
// Compute current day-of-year (as an integer)
currentDayOfYear = int((time - timestamp(year(time), 1, 1, 0, 0)) / 86400000) + 1
// Persistent variable to store the day-of-year of the current session.
var int sessionDay = na
// ============================================================================
// Style Inputs (group "Style")
// ============================================================================
regHighColor = input.color(color.green, "Day High Color", group="Style")
regHighWidth = input.int(2, "Day High Width", minval=1, group="Style")
regHighStyleStr = input.string("solid", "Day High Style", options=["solid", "dotted", "dashed"], group="Style")
regLowColor = input.color(color.red, "Day Low Color", group="Style")
regLowWidth = input.int(2, "Day Low Width", minval=1, group="Style")
regLowStyleStr = input.string("solid", "Day Low Style", options=["solid", "dotted", "dashed"], group="Style")
overnightHighColor = input.color(color.blue, "Overnight High Color", group="Style")
overnightHighWidth = input.int(2, "Overnight High Width", minval=1, group="Style")
overnightHighStyleStr = input.string("dotted", "Overnight High Style", options=["solid", "dotted", "dashed"], group="Style")
overnightLowColor = input.color(color.blue, "Overnight Low Color", group="Style")
overnightLowWidth = input.int(2, "Overnight Low Width", minval=1, group="Style")
overnightLowStyleStr = input.string("dotted", "Overnight Low Style", options=["solid", "dotted", "dashed"], group="Style")
prevCloseColor = input.color(color.yellow, "Previous Day Close Color", group="Style")
prevCloseWidth = input.int(2, "Previous Day Close Width", minval=1, group="Style")
prevCloseStyleStr = input.string("solid", "Previous Day Close Style", options=["solid", "dotted", "dashed"], group="Style")
prevHighColor = input.color(color.lime, "Previous Day High Color", group="Style")
prevHighWidth = input.int(2, "Previous Day High Width", minval=1, group="Style")
prevHighStyleStr = input.string("solid", "Previous Day High Style", options=["solid", "dotted", "dashed"], group="Style")
prevLowColor = input.color(color.red, "Previous Day Low Color", group="Style")
prevLowWidth = input.int(2, "Previous Day Low Width", minval=1, group="Style")
prevLowStyleStr = input.string("solid", "Previous Day Low Style", options=["solid", "dotted", "dashed"], group="Style")
// Helper function to convert style string to a line style constant.
f_line_style(str) =>
str == "solid" ? line.style_solid : str == "dotted" ? line.style_dotted : line.style_dashed
// ============================================================================
// Persistent Variables for Daily Values and Their Bar Indexes
// ============================================================================
// Current day regular session values.
var float curRegHigh = na
var float curRegLow = na
var int curRegHighBar = na
var int curRegLowBar = na
// Current day overnight values.
var float curOverHigh = na
var float curOverLow = na
var int curOverHighBar = na
var int curOverLowBar = na
// Previous day regular session values.
var float prevRegHigh = na
var float prevRegLow = na
var float prevRegClose = na
var int prevRegHighBar = na
var int prevRegLowBar = na
var int prevRegCloseBar = na
// Previous overnight values (from the previous session)
var float prevOverHigh = na
var float prevOverLow = na
var int prevOverHighBar = na
var int prevOverLowBar = na
// ============================================================================
// Persistent Label Variables (One set per day)
// ============================================================================
var label hodLabel = na
var label lodLabel = na
var label pdhLabel = na
var label pdlLabel = na
var label pdcLabel = na
var label onhLabel = na
var label onlLabel = na
// ============================================================================
// Persistent Variable for storing last regular session close
// ============================================================================
var float lastRegularClose = na
var int lastRegularCloseBar = na
// ============================================================================
// Reset on New Day / Session Start (Only Once Per Day)
// ============================================================================
if sessionStart and (na(sessionDay) or sessionDay != currentDayOfYear)
// Delete any existing labels from the previous day.
if not na(hodLabel)
label.delete(hodLabel)
if not na(lodLabel)
label.delete(lodLabel)
if not na(pdhLabel)
label.delete(pdhLabel)
if not na(pdlLabel)
label.delete(pdlLabel)
if not na(pdcLabel)
label.delete(pdcLabel)
if not na(onhLabel)
label.delete(onhLabel)
if not na(onlLabel)
label.delete(onlLabel)
// Store previous day's regular session values if available.
if not na(curRegHigh)
prevRegHigh := curRegHigh
prevRegHighBar := curRegHighBar
if not na(curRegLow)
prevRegLow := curRegLow
prevRegLowBar := curRegLowBar
if not na(lastRegularClose)
prevRegClose := lastRegularClose
prevRegCloseBar := lastRegularCloseBar
// Store previous overnight values.
if not na(curOverHigh)
prevOverHigh := curOverHigh
prevOverHighBar := curOverHighBar
if not na(curOverLow)
prevOverLow := curOverLow
prevOverLowBar := curOverLowBar
// Reset current day values.
curRegHigh := na
curRegLow := na
curRegHighBar := na
curRegLowBar := na
curOverHigh := na
curOverLow := na
curOverHighBar := na
curOverLowBar := na
// Create one set of labels only once per day.
hodLabel := label.new(bar_index+labelOffset, na, "HOD", color=color.new(color.white, 100), textcolor=regHighColor, size=size.small, style=label.style_label_right)
pdhLabel := label.new(bar_index+labelOffset, na, "PDH", color=color.new(color.white, 100), textcolor=prevHighColor, size=size.small, style=label.style_label_right)
onhLabel := label.new(bar_index+labelOffset, na, "ONH", color=color.new(color.white, 100), textcolor=overnightHighColor, size=size.small, style=label.style_label_right)
pdcLabel := label.new(bar_index+labelOffset, na, "PDC", color=color.new(color.white, 100), textcolor=prevCloseColor, size=size.small, style=label.style_label_right)
pdlLabel := label.new(bar_index+labelOffset, na, "PDL", color=color.new(color.white, 100), textcolor=prevLowColor, size=size.small, style=label.style_label_right)
onlLabel := label.new(bar_index+labelOffset, na, "ONL", color=color.new(color.white, 100), textcolor=overnightLowColor, size=size.small, style=label.style_label_right)
lodLabel := label.new(bar_index+labelOffset, na, "LOD", color=color.new(color.white, 100), textcolor=regLowColor, size=size.small, style=label.style_label_right)
sessionDay := currentDayOfYear
// ============================================================================
// Update Current Day Values
// ============================================================================
// During regular session, update HOD and LOD.
if inRegular
if na(curRegHigh) or high > curRegHigh
curRegHigh := high
curRegHighBar := bar_index
if na(curRegLow) or low < curRegLow
curRegLow := low
curRegLowBar := bar_index
// Continuously update last regular session close.
lastRegularClose := close
lastRegularCloseBar := bar_index
// Update overnight values during overnight period.
if overnightManual
if na(curOverHigh) or high > curOverHigh
curOverHigh := high
curOverHighBar := bar_index
if na(curOverLow) or low < curOverLow
curOverLow := low
curOverLowBar := bar_index
// ============================================================================
// Define Levels
// ============================================================================
// For overnight, if previous values exist, use them; otherwise use current ones.
onh_value = not na(prevOverHigh) ? prevOverHigh : curOverHigh
onh_bar = not na(prevOverHighBar) ? prevOverHighBar : curOverHighBar
onl_value = not na(prevOverLow) ? prevOverLow : curOverLow
onl_bar = not na(prevOverLowBar) ? prevOverLowBar : curOverLowBar
// ============================================================================
// Plot Horizontal Lines
// ============================================================================
var line regHighLine = na
var line regLowLine = na
var line onhLine = na
var line onlLine = na
var line prevCloseLine = na
var line prevHighLine = na
var line prevLowLine = na
if sessionStart and (sessionDay == currentDayOfYear)
if not na(regHighLine)
line.delete(regHighLine)
if not na(regLowLine)
line.delete(regLowLine)
if not na(onhLine)
line.delete(onhLine)
if not na(onlLine)
line.delete(onlLine)
if not na(prevCloseLine)
line.delete(prevCloseLine)
if not na(prevHighLine)
line.delete(prevHighLine)
if not na(prevLowLine)
line.delete(prevLowLine)
regHighLine := na
regLowLine := na
onhLine := na
onlLine := na
prevCloseLine := na
prevHighLine := na
prevLowLine := na
if not na(curRegHigh)
if na(regHighLine)
regHighLine := line.new(curRegHighBar, curRegHigh, bar_index+1, curRegHigh, extend=extend.right, color=regHighColor, style=f_line_style(regHighStyleStr), width=regHighWidth)
else
line.set_xy1(regHighLine, curRegHighBar, curRegHigh)
line.set_xy2(regHighLine, bar_index+1, curRegHigh)
if not na(curRegLow)
if na(regLowLine)
regLowLine := line.new(curRegLowBar, curRegLow, bar_index+1, curRegLow, extend=extend.right, color=regLowColor, style=f_line_style(regLowStyleStr), width=regLowWidth)
else
line.set_xy1(regLowLine, curRegLowBar, curRegLow)
line.set_xy2(regLowLine, bar_index+1, curRegLow)
if not na(onh_value)
if na(onhLine)
onhLine := line.new(onh_bar, onh_value, bar_index+1, onh_value, extend=extend.right, color=overnightHighColor, style=f_line_style(overnightHighStyleStr), width=overnightHighWidth)
else
line.set_xy1(onhLine, onh_bar, onh_value)
line.set_xy2(onhLine, bar_index+1, onh_value)
if not na(onl_value)
if na(onlLine)
onlLine := line.new(onl_bar, onl_value, bar_index+1, onl_value, extend=extend.right, color=overnightLowColor, style=f_line_style(overnightLowStyleStr), width=overnightLowWidth)
else
line.set_xy1(onlLine, onl_bar, onl_value)
line.set_xy2(onlLine, bar_index+1, onl_value)
if not na(prevRegClose)
if na(prevCloseLine)
prevCloseLine := line.new(prevRegCloseBar, prevRegClose, bar_index+1, prevRegClose, extend=extend.right, color=prevCloseColor, style=f_line_style(prevCloseStyleStr), width=prevCloseWidth)
else
line.set_xy1(prevCloseLine, prevRegCloseBar, prevRegClose)
line.set_xy2(prevCloseLine, bar_index+1, prevRegClose)
if not na(prevRegHigh)
if na(prevHighLine)
prevHighLine := line.new(prevRegHighBar, prevRegHigh, bar_index+1, prevRegHigh, extend=extend.right, color=prevHighColor, style=f_line_style(prevHighStyleStr), width=prevHighWidth)
else
line.set_xy1(prevHighLine, prevRegHighBar, prevRegHigh)
line.set_xy2(prevHighLine, bar_index+1, prevRegHigh)
if not na(prevRegLow)
if na(prevLowLine)
prevLowLine := line.new(prevRegLowBar, prevRegLow, bar_index+1, prevRegLow, extend=extend.right, color=prevLowColor, style=f_line_style(prevLowStyleStr), width=prevLowWidth)
else
line.set_xy1(prevLowLine, prevRegLowBar, prevRegLow)
line.set_xy2(prevLowLine, bar_index+1, prevRegLow)
// ============================================================================
// Update Label Positions Relative to Their Corresponding Levels
// ============================================================================
x_pos = bar_index + labelOffset
if not na(hodLabel) and not na(curRegHigh)
label.set_xy(hodLabel, x_pos, curRegHigh - labelVOffset)
if not na(lodLabel) and not na(curRegLow)
label.set_xy(lodLabel, x_pos, curRegLow + labelVOffset)
if not na(pdhLabel) and not na(prevRegHigh)
label.set_xy(pdhLabel, x_pos, prevRegHigh - labelVOffset)
if not na(pdlLabel) and not na(prevRegLow)
label.set_xy(pdlLabel, x_pos, prevRegLow + labelVOffset)
if not na(pdcLabel) and not na(prevRegClose)
label.set_xy(pdcLabel, x_pos, prevRegClose)
if not na(onhLabel) and not na(onh_value)
label.set_xy(onhLabel, x_pos, onh_value - labelVOffset)
if not na(onlLabel) and not na(onl_value)
label.set_xy(onlLabel, x_pos, onl_value + labelVOffset)
オープンソーススクリプト
In true TradingView spirit, the creator of this script has made it open-source, so that traders can review and verify its functionality. Kudos to the author! While you can use it for free, remember that republishing the code is subject to our House Rules.
免責事項
The information and publications are not meant to be, and do not constitute, financial, investment, trading, or other types of advice or recommendations supplied or endorsed by TradingView. Read more in the Terms of Use.
オープンソーススクリプト
In true TradingView spirit, the creator of this script has made it open-source, so that traders can review and verify its functionality. Kudos to the author! While you can use it for free, remember that republishing the code is subject to our House Rules.
免責事項
The information and publications are not meant to be, and do not constitute, financial, investment, trading, or other types of advice or recommendations supplied or endorsed by TradingView. Read more in the Terms of Use.