本页源码来自 TradingView 公开发布的开源脚本,版权归原作者所有, 请遵循其原始许可(Pine 脚本常见 CC BY-NC-SA / MPL-2.0 / MIT)。 本项目仅用于研究检索与许可范围内的移植。
// This Pine Script® code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © notprofessorgreen
//@version=5
indicator(title='Session Opening Bar Range', shorttitle='OBR', overlay=true, max_lines_count=500, max_labels_count=500, max_boxes_count = 500, max_bars_back = 5000)
//-------------------------------------------------------------------------------------------------
// Inputs
//-------------------------------------------------------------------------------------------------
// Session Selection
var g_SESSION = "Session Settings"
session_choice = input.string("New York RTH (9.30am - 4pm)", "Session",
options=["New York RTH (9.30am - 4pm)", "New York Futures (8am - 5pm)",
"London (2am - 8am)", "Asia (7pm - 2am)", "Midnight to 5pm",
"ZB/Gold/Silver OR (8.20am - 4pm)", "CL (9am - 4pm)", "Custom"],
group=g_SESSION, tooltip="Select the trading session")
// Custom Session Settings
var g_CUSTOM_SESSION = "Custom Session Settings"
custom_session_start = input.string("0900", "Custom Session Start (HHMM)",
group=g_CUSTOM_SESSION, tooltip="Start time for custom session in HHMM format (e.g., 0900 for 9:00 AM)")
custom_session_end = input.string("1200", "Custom Session End (HHMM)",
group=g_CUSTOM_SESSION, tooltip="End time for custom session in HHMM format (e.g., 1200 for 12:00 PM)")
time_zone = input.string("America/New_York", "Timezone",
group=g_CUSTOM_SESSION, tooltip="Timezone for the session")
timeframe = input.timeframe("5", "Timeframe", tooltip="Chart timeframe for first bar high/low calculation", group="Opening bar format")
midLine = input.bool(true, "Show Midline", group="Opening bar format")
hist = input.bool(true, "Show Historical Ranges", group="Opening bar format")
max_history = input.int(20, "Maximum Historical Ranges", minval=1, maxval=500, group="Opening bar format")
showL = input.bool(true, "Show High/Low/Mid Labels", inline="Labels", group="Opening bar format")
showP = input.bool(false, "Show Prices", inline="Labels", group="Opening bar format")
pos = input.string("Left", "Position", options=["Left", "Right"], group="Opening bar format")
boxStyle = input.string("Solid", "Range Style", options=["Solid", "Dashed", "Dotted"], inline="Box", group="Opening bar format")
borderWidth = input.int(1, ' / Width ', 1, 10, inline="Box", group="Opening bar format")
lineStyle = input.string("Dashed", "MidLine Style", options=["Solid", "Dashed", "Dotted"], inline="Line", group="Opening bar format")
lineWidth = input.int(1, ' / Width ', 1, 10, inline="Line", group="Opening bar format")
_color = input.color(color.rgb(4, 54, 146), "Color : ", inline="Color", group="Opening bar format")
_fillcolor = input.color(color.rgb(9, 136, 209, 85), " / ", inline="Color", group="Opening bar format")
// Inputs for statistical levels
lookback = input.int(60, "Lookback Periods for Stats", minval=1, group="Statistical Levels")
show_stats = input.bool(false, "Show Statistical Levels", group="Statistical Levels")
show_stats_labels = input.bool(false, "Show Statistical Labels", group="Statistical Levels")
std_mult1 = input.float(1.0, "Std Dev Multiplier 1", minval=0, step=0.5, group="Statistical Levels")
std_mult2 = input.float(2.0, "Std Dev Multiplier 2", minval=0, step=0.5, group="Statistical Levels")
stats_line_color = input.color(color.purple, "Stats Line Color", group="Statistical Levels")
stats_line_width = input.int(1, "Stats Line Width", minval=1, maxval=10, group="Statistical Levels")
stats_label_color = input.color(color.purple, "Stats Label Color", group="Statistical Levels")
stats_label_size = input.string("Normal", "Stats Label Size", options=["Tiny", "Small", "Normal", "Large", "Huge"], group="Statistical Levels")
// Inputs for Fibonacci Extensions
show_mm = input.bool(false, title="Show Fib Extensions", group="Fibonacci Extensions")
show_mm_labels = input.bool(false, title="Show Fib Labels", group="Fibonacci Extensions")
mm_line_color = input.color(color.teal, "Fib Line Color", group="Fibonacci Extensions")
mm_line_width = input.int(1, "Fib Line Width", minval=1, maxval=10, group="Fibonacci Extensions")
mm_label_color = input.color(color.teal, "Fib Label Color", group="Fibonacci Extensions")
mm_label_size = input.string("Normal", "Fib Label Size", options=["Tiny", "Small", "Normal", "Large", "Huge"], group="Fibonacci Extensions")
// Inputs for OR Rotations
show_rotations = input.bool(true, title="Show OR Rotations", group="OR Rotations")
rotation_increment = input.float(65.0, title="Rotation Increment (Points)", minval=0.01, step=0.25, group="OR Rotations", tooltip="Point increment for each rotation level (e.g., 65 for NQ, 15 for ES)")
show_rotation_labels = input.bool(true, title="Show Rotation Labels", group="OR Rotations")
rotation_line_color = input.color(color.gray, "Rotation Line Color", group="OR Rotations")
rotation_line_style = input.string("Dotted", "Line Style", options=["Solid", "Dashed", "Dotted"], group="OR Rotations")
rotation_line_width = input.int(1, "Rotation Line Width", minval=1, maxval=10, group="OR Rotations")
rotation_label_color = input.color(color.gray, "Rotation Label Color", group="OR Rotations")
rotation_label_size = input.string("Small", "Rotation Label Size", options=["Tiny", "Small", "Normal", "Large", "Huge"], group="OR Rotations")
//-------------------------------------------------------------------------------------------------
// Functions / Calculations
//-------------------------------------------------------------------------------------------------
get_style(style) =>
switch style
"──────" => line.style_solid
"─ ─ ─ ─" => line.style_dashed
"· · · · · ·" => line.style_dotted
"Solid" => line.style_solid
"Dashed" => line.style_dashed
"Dotted" => line.style_dotted
get_label_size(size) =>
switch size
"Tiny" => size.tiny
"Small" => size.small
"Normal" => size.normal
"Large" => size.large
"Huge" => size.huge
// Determine session time based on selection
var string session_time = ""
switch session_choice
"New York RTH (9.30am - 4pm)" =>
session_time := "0930-1600"
"New York Futures (8am - 5pm)" =>
session_time := "0800-1700"
"London (2am - 8am)" =>
session_time := "0200-0800"
"Asia (7pm - 2am)" =>
session_time := "1900-0200"
"Midnight to 5pm" =>
session_time := "0000-1700"
"ZB/Gold/Silver OR (8.20am - 4pm)" =>
session_time := "0820-1600"
"CL OR (9am - 4pm)" =>
session_time := "0900-1600"
"Custom session" =>
session_time := custom_session_start + "-" + custom_session_end
// Session Detection
is_in_session = not na(time(timeframe.period, session_time, time_zone))
is_session_start = is_in_session and not is_in_session[1]
// Get high, low, mid from the selected timeframe
[H, L, M] = request.security(ticker.standard(syminfo.tickerid), timeframe, [high, low, hl2], lookahead=barmerge.lookahead_on)
_style = pos == "Left" ? label.style_label_right : label.style_label_left
// Arrays to store drawing objects for better management
var line_array = array.new<line>()
var label_array = array.new<label>()
var linefill_array = array.new<linefill>()
// Store current session's drawing objects
var line current_top_line = na
var line current_bot_line = na
var line current_mid_line = na
var linefill current_fill = na
var label current_high_label = na
var label current_low_label = na
var label current_mid_label = na
// Store current session's stat lines
var line current_stat1_up = na
var line current_stat1_dn = na
var line current_stat2_up = na
var line current_stat2_dn = na
var label current_stat1_up_label = na
var label current_stat1_dn_label = na
var label current_stat2_up_label = na
var label current_stat2_dn_label = na
// Store current session's fib lines
var line current_mm_200 = na
var line current_mm_300 = na
var line current_mm_400 = na
var line current_mm_500 = na
var line current_mm_neg_200 = na
var line current_mm_neg_300 = na
var line current_mm_neg_400 = na
var line current_mm_neg_500 = na
var label current_mm_200_label = na
var label current_mm_300_label = na
var label current_mm_400_label = na
var label current_mm_500_label = na
var label current_mm_neg_200_label = na
var label current_mm_neg_300_label = na
var label current_mm_neg_400_label = na
var label current_mm_neg_500_label = na
// Store current session's rotation lines - using individual variables like Fibonacci
var line current_rot1_up = na
var line current_rot2_up = na
var line current_rot3_up = na
var line current_rot4_up = na
var line current_rot5_up = na
var line current_rot1_dn = na
var line current_rot2_dn = na
var line current_rot3_dn = na
var line current_rot4_dn = na
var line current_rot5_dn = na
var label current_rot1_up_label = na
var label current_rot2_up_label = na
var label current_rot3_up_label = na
var label current_rot4_up_label = na
var label current_rot5_up_label = na
var label current_rot1_dn_label = na
var label current_rot2_dn_label = na
var label current_rot3_dn_label = na
var label current_rot4_dn_label = na
var label current_rot5_dn_label = na
// Calculate statistical levels based on past ranges
var float[] range_array = array.new_float(0)
// Range and Percentage Calculations
mm_1 = input.float(1.618, 'Measured move extension 1', group='Fibonacci Extensions')
mm_2 = input.float(2.618, 'Measured move extension 2', group='Fibonacci Extensions')
mm_3 = input.float(3.618, 'Measured move extension 3', group='Fibonacci Extensions')
mm_4 = input.float(4.618, 'Measured move extension 4', group='Fibonacci Extensions')
mm_5 = input.float(5.618, 'Measured move extension 5', group='Fibonacci Extensions')
// Function to manage array size
manage_array_size(arr, max_size) =>
while array.size(arr) > max_size
old_element = array.shift(arr)
line.delete(old_element)
manage_label_array_size(arr, max_size) =>
while array.size(arr) > max_size
old_element = array.shift(arr)
label.delete(old_element)
manage_linefill_array_size(arr, max_size) =>
while array.size(arr) > max_size
old_element = array.shift(arr)
linefill.delete(old_element)
//-------------------------------------------------------------------------------------------------
// Outputs
//-------------------------------------------------------------------------------------------------
// Draw elements on session start - capture FIRST BAR values only
if is_session_start and not na(H) and not na(L)
// Store the range from first bar for statistics
array.push(range_array, H - L)
if array.size(range_array) > lookback
array.shift(range_array)
// Calculate statistical levels
avg_range = array.avg(range_array)
std_dev = array.stdev(range_array)
stat_level1_up = H + avg_range + std_dev * std_mult1
stat_level1_dn = L - (avg_range + std_dev * std_mult1)
stat_level2_up = H + avg_range + std_dev * std_mult2
stat_level2_dn = L - (avg_range + std_dev * std_mult2)
// Calculate Fibonacci levels
_range = H - L
range_200 = H + _range
range_300 = H + _range * mm_1
range_400 = H + _range * mm_2
range_500 = H + _range * mm_3
neg_range_200 = L - _range
neg_range_300 = L - _range * mm_1
neg_range_400 = L - _range * mm_2
neg_range_500 = L - _range * mm_3
// Calculate rotation levels (fixed point increments)
rot1_up = H + rotation_increment
rot2_up = H + (rotation_increment * 2)
rot3_up = H + (rotation_increment * 3)
rot4_up = H + (rotation_increment * 4)
rot5_up = H + (rotation_increment * 5)
rot1_dn = L - rotation_increment
rot2_dn = L - (rotation_increment * 2)
rot3_dn = L - (rotation_increment * 3)
rot4_dn = L - (rotation_increment * 4)
rot5_dn = L - (rotation_increment * 5)
// Calculate how many objects we'll create per session
rotation_count = show_rotations ? 10 : 0 // 5 up + 5 down
rotation_label_count = (show_rotations and show_rotation_labels) ? 10 : 0
objects_per_session = 2 + (midLine ? 1 : 0) + (show_stats ? 4 : 0) + (show_mm ? 8 : 0) + rotation_count
labels_per_session = (showL ? (2 + (midLine ? 1 : 0)) : 0) + (show_stats_labels ? 4 : 0) + (show_mm_labels ? 8 : 0) + rotation_label_count
// Adjust max_history based on object count to stay within limits
adjusted_max_history = math.max(1, math.min(max_history, math.floor(450 / math.max(objects_per_session, 1))))
adjusted_max_labels = math.max(1, math.min(max_history, math.floor(450 / math.max(labels_per_session, 1))))
// Draw high, low, and midline - these are FIXED from first bar
// Delete old lines/fills before creating new ones
if not na(current_top_line)
line.delete(current_top_line)
if not na(current_bot_line)
line.delete(current_bot_line)
if not na(current_fill)
linefill.delete(current_fill)
if not na(current_mid_line)
line.delete(current_mid_line)
current_top_line := line.new(time, H, time, H, color=_color, style=get_style(boxStyle), width=borderWidth, xloc=xloc.bar_time)
current_bot_line := line.new(time, L, time, L, color=_color, style=get_style(boxStyle), width=borderWidth, xloc=xloc.bar_time)
current_fill := linefill.new(current_top_line, current_bot_line, _fillcolor)
array.push(line_array, current_top_line)
array.push(line_array, current_bot_line)
array.push(linefill_array, current_fill)
if midLine
current_mid_line := line.new(time, M, time, M, color=_color, style=get_style(lineStyle), width=lineWidth, xloc=xloc.bar_time)
array.push(line_array, current_mid_line)
x = pos == "Left" ? time : time
if showL
// Delete old labels before creating new ones
if not na(current_high_label)
label.delete(current_high_label)
if not na(current_low_label)
label.delete(current_low_label)
if not na(current_mid_label)
label.delete(current_mid_label)
current_high_label := label.new(x, H, "High" + (showP ? " (" + str.tostring(H, format.mintick) + ")" : ""), style=_style, color=color.new(_color, 100), textcolor=_color, xloc=xloc.bar_time, size=get_label_size("Normal"))
current_low_label := label.new(x, L, "Low" + (showP ? " (" + str.tostring(L, format.mintick) + ")" : ""), style=_style, color=color.new(_color, 100), textcolor=_color, xloc=xloc.bar_time, size=get_label_size("Normal"))
array.push(label_array, current_high_label)
array.push(label_array, current_low_label)
if midLine
current_mid_label := label.new(x, M, "Mid" + (showP ? " (" + str.tostring(M, format.mintick) + ")" : ""), style=_style, color=color.new(_color, 100), textcolor=_color, xloc=xloc.bar_time, size=get_label_size("Normal"))
array.push(label_array, current_mid_label)
// Draw Fibonacci extensions
if show_mm
// Delete old lines before creating new ones
if not na(current_mm_200)
line.delete(current_mm_200)
if not na(current_mm_300)
line.delete(current_mm_300)
if not na(current_mm_400)
line.delete(current_mm_400)
if not na(current_mm_500)
line.delete(current_mm_500)
if not na(current_mm_neg_200)
line.delete(current_mm_neg_200)
if not na(current_mm_neg_300)
line.delete(current_mm_neg_300)
if not na(current_mm_neg_400)
line.delete(current_mm_neg_400)
if not na(current_mm_neg_500)
line.delete(current_mm_neg_500)
current_mm_200 := line.new(time, range_200, time, range_200, color=mm_line_color, width=mm_line_width, xloc=xloc.bar_time)
current_mm_300 := line.new(time, range_300, time, range_300, color=mm_line_color, width=mm_line_width, xloc=xloc.bar_time)
current_mm_400 := line.new(time, range_400, time, range_400, color=mm_line_color, width=mm_line_width, xloc=xloc.bar_time)
current_mm_500 := line.new(time, range_500, time, range_500, color=mm_line_color, width=mm_line_width, xloc=xloc.bar_time)
current_mm_neg_200 := line.new(time, neg_range_200, time, neg_range_200, color=mm_line_color, width=mm_line_width, xloc=xloc.bar_time)
current_mm_neg_300 := line.new(time, neg_range_300, time, neg_range_300, color=mm_line_color, width=mm_line_width, xloc=xloc.bar_time)
current_mm_neg_400 := line.new(time, neg_range_400, time, neg_range_400, color=mm_line_color, width=mm_line_width, xloc=xloc.bar_time)
current_mm_neg_500 := line.new(time, neg_range_500, time, neg_range_500, color=mm_line_color, width=mm_line_width, xloc=xloc.bar_time)
array.push(line_array, current_mm_200)
array.push(line_array, current_mm_300)
array.push(line_array, current_mm_400)
array.push(line_array, current_mm_500)
array.push(line_array, current_mm_neg_200)
array.push(line_array, current_mm_neg_300)
array.push(line_array, current_mm_neg_400)
array.push(line_array, current_mm_neg_500)
if show_mm_labels
// Delete old labels before creating new ones
if not na(current_mm_200_label)
label.delete(current_mm_200_label)
if not na(current_mm_300_label)
label.delete(current_mm_300_label)
if not na(current_mm_400_label)
label.delete(current_mm_400_label)
if not na(current_mm_500_label)
label.delete(current_mm_500_label)
if not na(current_mm_neg_200_label)
label.delete(current_mm_neg_200_label)
if not na(current_mm_neg_300_label)
label.delete(current_mm_neg_300_label)
if not na(current_mm_neg_400_label)
label.delete(current_mm_neg_400_label)
if not na(current_mm_neg_500_label)
label.delete(current_mm_neg_500_label)
current_mm_200_label := label.new(x, range_200, "100%", style=_style, color=color.new(mm_label_color, 100), textcolor=mm_label_color, xloc=xloc.bar_time, size=get_label_size(mm_label_size))
current_mm_300_label := label.new(x, range_300, str.tostring(mm_1, "#.###") + "x", style=_style, color=color.new(mm_label_color, 100), textcolor=mm_label_color, xloc=xloc.bar_time, size=get_label_size(mm_label_size))
current_mm_400_label := label.new(x, range_400, str.tostring(mm_2, "#.###") + "x", style=_style, color=color.new(mm_label_color, 100), textcolor=mm_label_color, xloc=xloc.bar_time, size=get_label_size(mm_label_size))
current_mm_500_label := label.new(x, range_500, str.tostring(mm_3, "#.###") + "x", style=_style, color=color.new(mm_label_color, 100), textcolor=mm_label_color, xloc=xloc.bar_time, size=get_label_size(mm_label_size))
current_mm_neg_200_label := label.new(x, neg_range_200, "-100%", style=_style, color=color.new(mm_label_color, 100), textcolor=mm_label_color, xloc=xloc.bar_time, size=get_label_size(mm_label_size))
current_mm_neg_300_label := label.new(x, neg_range_300, "-" + str.tostring(mm_1, "#.###") + "x", style=_style, color=color.new(mm_label_color, 100), textcolor=mm_label_color, xloc=xloc.bar_time, size=get_label_size(mm_label_size))
current_mm_neg_400_label := label.new(x, neg_range_400, "-" + str.tostring(mm_2, "#.###") + "x", style=_style, color=color.new(mm_label_color, 100), textcolor=mm_label_color, xloc=xloc.bar_time, size=get_label_size(mm_label_size))
current_mm_neg_500_label := label.new(x, neg_range_500, "-" + str.tostring(mm_3, "#.###") + "x", style=_style, color=color.new(mm_label_color, 100), textcolor=mm_label_color, xloc=xloc.bar_time, size=get_label_size(mm_label_size))
array.push(label_array, current_mm_200_label)
array.push(label_array, current_mm_300_label)
array.push(label_array, current_mm_400_label)
array.push(label_array, current_mm_500_label)
array.push(label_array, current_mm_neg_200_label)
array.push(label_array, current_mm_neg_300_label)
array.push(label_array, current_mm_neg_400_label)
array.push(label_array, current_mm_neg_500_label)
// Draw statistical levels
if show_stats and not na(avg_range) and not na(std_dev)
// Delete old lines before creating new ones
if not na(current_stat1_up)
line.delete(current_stat1_up)
if not na(current_stat1_dn)
line.delete(current_stat1_dn)
if not na(current_stat2_up)
line.delete(current_stat2_up)
if not na(current_stat2_dn)
line.delete(current_stat2_dn)
current_stat1_up := line.new(time, stat_level1_up, time, stat_level1_up, color=stats_line_color, style=line.style_dashed, width=stats_line_width, xloc=xloc.bar_time)
current_stat1_dn := line.new(time, stat_level1_dn, time, stat_level1_dn, color=stats_line_color, style=line.style_dashed, width=stats_line_width, xloc=xloc.bar_time)
current_stat2_up := line.new(time, stat_level2_up, time, stat_level2_up, color=stats_line_color, style=line.style_dotted, width=stats_line_width, xloc=xloc.bar_time)
current_stat2_dn := line.new(time, stat_level2_dn, time, stat_level2_dn, color=stats_line_color, style=line.style_dotted, width=stats_line_width, xloc=xloc.bar_time)
array.push(line_array, current_stat1_up)
array.push(line_array, current_stat1_dn)
array.push(line_array, current_stat2_up)
array.push(line_array, current_stat2_dn)
if show_stats_labels
// Delete old labels before creating new ones
if not na(current_stat1_up_label)
label.delete(current_stat1_up_label)
if not na(current_stat1_dn_label)
label.delete(current_stat1_dn_label)
if not na(current_stat2_up_label)
label.delete(current_stat2_up_label)
if not na(current_stat2_dn_label)
label.delete(current_stat2_dn_label)
current_stat1_up_label := label.new(x, stat_level1_up, "+" + str.tostring(std_mult1) + "σ", style=_style, color=color.new(stats_label_color, 100), textcolor=stats_label_color, xloc=xloc.bar_time, size=get_label_size(stats_label_size))
current_stat1_dn_label := label.new(x, stat_level1_dn, "-" + str.tostring(std_mult1) + "σ", style=_style, color=color.new(stats_label_color, 100), textcolor=stats_label_color, xloc=xloc.bar_time, size=get_label_size(stats_label_size))
current_stat2_up_label := label.new(x, stat_level2_up, "+" + str.tostring(std_mult2) + "σ", style=_style, color=color.new(stats_label_color, 100), textcolor=stats_label_color, xloc=xloc.bar_time, size=get_label_size(stats_label_size))
current_stat2_dn_label := label.new(x, stat_level2_dn, "-" + str.tostring(std_mult2) + "σ", style=_style, color=color.new(stats_label_color, 100), textcolor=stats_label_color, xloc=xloc.bar_time, size=get_label_size(stats_label_size))
array.push(label_array, current_stat1_up_label)
array.push(label_array, current_stat1_dn_label)
array.push(label_array, current_stat2_up_label)
array.push(label_array, current_stat2_dn_label)
// Draw OR Rotation levels - using Fibonacci approach with individual variables
if show_rotations and rotation_increment > 0
// Delete old rotation lines before creating new ones
if not na(current_rot1_up)
line.delete(current_rot1_up)
if not na(current_rot2_up)
line.delete(current_rot2_up)
if not na(current_rot3_up)
line.delete(current_rot3_up)
if not na(current_rot4_up)
line.delete(current_rot4_up)
if not na(current_rot5_up)
line.delete(current_rot5_up)
if not na(current_rot1_dn)
line.delete(current_rot1_dn)
if not na(current_rot2_dn)
line.delete(current_rot2_dn)
if not na(current_rot3_dn)
line.delete(current_rot3_dn)
if not na(current_rot4_dn)
line.delete(current_rot4_dn)
if not na(current_rot5_dn)
line.delete(current_rot5_dn)
// Create rotation lines
current_rot1_up := line.new(time, rot1_up, time, rot1_up, color=rotation_line_color, style=get_style(rotation_line_style), width=rotation_line_width, xloc=xloc.bar_time)
current_rot2_up := line.new(time, rot2_up, time, rot2_up, color=rotation_line_color, style=get_style(rotation_line_style), width=rotation_line_width, xloc=xloc.bar_time)
current_rot3_up := line.new(time, rot3_up, time, rot3_up, color=rotation_line_color, style=get_style(rotation_line_style), width=rotation_line_width, xloc=xloc.bar_time)
current_rot4_up := line.new(time, rot4_up, time, rot4_up, color=rotation_line_color, style=get_style(rotation_line_style), width=rotation_line_width, xloc=xloc.bar_time)
current_rot5_up := line.new(time, rot5_up, time, rot5_up, color=rotation_line_color, style=get_style(rotation_line_style), width=rotation_line_width, xloc=xloc.bar_time)
current_rot1_dn := line.new(time, rot1_dn, time, rot1_dn, color=rotation_line_color, style=get_style(rotation_line_style), width=rotation_line_width, xloc=xloc.bar_time)
current_rot2_dn := line.new(time, rot2_dn, time, rot2_dn, color=rotation_line_color, style=get_style(rotation_line_style), width=rotation_line_width, xloc=xloc.bar_time)
current_rot3_dn := line.new(time, rot3_dn, time, rot3_dn, color=rotation_line_color, style=get_style(rotation_line_style), width=rotation_line_width, xloc=xloc.bar_time)
current_rot4_dn := line.new(time, rot4_dn, time, rot4_dn, color=rotation_line_color, style=get_style(rotation_line_style), width=rotation_line_width, xloc=xloc.bar_time)
current_rot5_dn := line.new(time, rot5_dn, time, rot5_dn, color=rotation_line_color, style=get_style(rotation_line_style), width=rotation_line_width, xloc=xloc.bar_time)
array.push(line_array, current_rot1_up)
array.push(line_array, current_rot2_up)
array.push(line_array, current_rot3_up)
array.push(line_array, current_rot4_up)
array.push(line_array, current_rot5_up)
array.push(line_array, current_rot1_dn)
array.push(line_array, current_rot2_dn)
array.push(line_array, current_rot3_dn)
array.push(line_array, current_rot4_dn)
array.push(line_array, current_rot5_dn)
if show_rotation_labels
// Delete old labels before creating new ones
if not na(current_rot1_up_label)
label.delete(current_rot1_up_label)
if not na(current_rot2_up_label)
label.delete(current_rot2_up_label)
if not na(current_rot3_up_label)
label.delete(current_rot3_up_label)
if not na(current_rot4_up_label)
label.delete(current_rot4_up_label)
if not na(current_rot5_up_label)
label.delete(current_rot5_up_label)
if not na(current_rot1_dn_label)
label.delete(current_rot1_dn_label)
if not na(current_rot2_dn_label)
label.delete(current_rot2_dn_label)
if not na(current_rot3_dn_label)
label.delete(current_rot3_dn_label)
if not na(current_rot4_dn_label)
label.delete(current_rot4_dn_label)
if not na(current_rot5_dn_label)
label.delete(current_rot5_dn_label)
// Create rotation labels with rotation level and point value
current_rot1_up_label := label.new(x, rot1_up, "R+1 (" + str.tostring(rotation_increment, "#.##") + ")", style=_style, color=color.new(rotation_label_color, 100), textcolor=rotation_label_color, xloc=xloc.bar_time, size=get_label_size(rotation_label_size))
current_rot2_up_label := label.new(x, rot2_up, "R+2 (" + str.tostring(rotation_increment * 2, "#.##") + ")", style=_style, color=color.new(rotation_label_color, 100), textcolor=rotation_label_color, xloc=xloc.bar_time, size=get_label_size(rotation_label_size))
current_rot3_up_label := label.new(x, rot3_up, "R+3 (" + str.tostring(rotation_increment * 3, "#.##") + ")", style=_style, color=color.new(rotation_label_color, 100), textcolor=rotation_label_color, xloc=xloc.bar_time, size=get_label_size(rotation_label_size))
current_rot4_up_label := label.new(x, rot4_up, "R+4 (" + str.tostring(rotation_increment * 4, "#.##") + ")", style=_style, color=color.new(rotation_label_color, 100), textcolor=rotation_label_color, xloc=xloc.bar_time, size=get_label_size(rotation_label_size))
current_rot5_up_label := label.new(x, rot5_up, "R+5 (" + str.tostring(rotation_increment * 5, "#.##") + ")", style=_style, color=color.new(rotation_label_color, 100), textcolor=rotation_label_color, xloc=xloc.bar_time, size=get_label_size(rotation_label_size))
current_rot1_dn_label := label.new(x, rot1_dn, "R-1 (" + str.tostring(rotation_increment, "#.##") + ")", style=_style, color=color.new(rotation_label_color, 100), textcolor=rotation_label_color, xloc=xloc.bar_time, size=get_label_size(rotation_label_size))
current_rot2_dn_label := label.new(x, rot2_dn, "R-2 (" + str.tostring(rotation_increment * 2, "#.##") + ")", style=_style, color=color.new(rotation_label_color, 100), textcolor=rotation_label_color, xloc=xloc.bar_time, size=get_label_size(rotation_label_size))
current_rot3_dn_label := label.new(x, rot3_dn, "R-3 (" + str.tostring(rotation_increment * 3, "#.##") + ")", style=_style, color=color.new(rotation_label_color, 100), textcolor=rotation_label_color, xloc=xloc.bar_time, size=get_label_size(rotation_label_size))
current_rot4_dn_label := label.new(x, rot4_dn, "R-4 (" + str.tostring(rotation_increment * 4, "#.##") + ")", style=_style, color=color.new(rotation_label_color, 100), textcolor=rotation_label_color, xloc=xloc.bar_time, size=get_label_size(rotation_label_size))
current_rot5_dn_label := label.new(x, rot5_dn, "R-5 (" + str.tostring(rotation_increment * 5, "#.##") + ")", style=_style, color=color.new(rotation_label_color, 100), textcolor=rotation_label_color, xloc=xloc.bar_time, size=get_label_size(rotation_label_size))
array.push(label_array, current_rot1_up_label)
array.push(label_array, current_rot2_up_label)
array.push(label_array, current_rot3_up_label)
array.push(label_array, current_rot4_up_label)
array.push(label_array, current_rot5_up_label)
array.push(label_array, current_rot1_dn_label)
array.push(label_array, current_rot2_dn_label)
array.push(label_array, current_rot3_dn_label)
array.push(label_array, current_rot4_dn_label)
array.push(label_array, current_rot5_dn_label)
// Manage array sizes to prevent hitting limits
if not hist or array.size(line_array) > adjusted_max_history * objects_per_session
manage_array_size(line_array, adjusted_max_history * objects_per_session)
if not hist or array.size(label_array) > adjusted_max_labels * labels_per_session
manage_label_array_size(label_array, adjusted_max_labels * labels_per_session)
if not hist or array.size(linefill_array) > adjusted_max_history
manage_linefill_array_size(linefill_array, adjusted_max_history)
// Extend lines to the right as time progresses (but keep Y values fixed)
if is_in_session and not is_session_start
if not na(current_top_line)
line.set_x2(current_top_line, time)
if not na(current_bot_line)
line.set_x2(current_bot_line, time)
if not na(current_mid_line) and midLine
line.set_x2(current_mid_line, time)
// Update label position if set to "Right"
if showL and pos == "Right"
if not na(current_high_label)
label.set_x(current_high_label, time)
if not na(current_low_label)
label.set_x(current_low_label, time)
if not na(current_mid_label) and midLine
label.set_x(current_mid_label, time)
// Extend Fibonacci lines
if show_mm
if not na(current_mm_200)
line.set_x2(current_mm_200, time)
if not na(current_mm_300)
line.set_x2(current_mm_300, time)
if not na(current_mm_400)
line.set_x2(current_mm_400, time)
if not na(current_mm_500)
line.set_x2(current_mm_500, time)
if not na(current_mm_neg_200)
line.set_x2(current_mm_neg_200, time)
if not na(current_mm_neg_300)
line.set_x2(current_mm_neg_300, time)
if not na(current_mm_neg_400)
line.set_x2(current_mm_neg_400, time)
if not na(current_mm_neg_500)
line.set_x2(current_mm_neg_500, time)
if show_mm_labels and pos == "Right"
if not na(current_mm_200_label)
label.set_x(current_mm_200_label, time)
if not na(current_mm_300_label)
label.set_x(current_mm_300_label, time)
if not na(current_mm_400_label)
label.set_x(current_mm_400_label, time)
if not na(current_mm_500_label)
label.set_x(current_mm_500_label, time)
if not na(current_mm_neg_200_label)
label.set_x(current_mm_neg_200_label, time)
if not na(current_mm_neg_300_label)
label.set_x(current_mm_neg_300_label, time)
if not na(current_mm_neg_400_label)
label.set_x(current_mm_neg_400_label, time)
if not na(current_mm_neg_500_label)
label.set_x(current_mm_neg_500_label, time)
// Extend statistical lines
if show_stats
if not na(current_stat1_up)
line.set_x2(current_stat1_up, time)
if not na(current_stat1_dn)
line.set_x2(current_stat1_dn, time)
if not na(current_stat2_up)
line.set_x2(current_stat2_up, time)
if not na(current_stat2_dn)
line.set_x2(current_stat2_dn, time)
if show_stats_labels and pos == "Right"
if not na(current_stat1_up_label)
label.set_x(current_stat1_up_label, time)
if not na(current_stat1_dn_label)
label.set_x(current_stat1_dn_label, time)
if not na(current_stat2_up_label)
label.set_x(current_stat2_up_label, time)
if not na(current_stat2_dn_label)
label.set_x(current_stat2_dn_label, time)
// Extend rotation lines
if show_rotations and rotation_increment > 0
if not na(current_rot1_up)
line.set_x2(current_rot1_up, time)
if not na(current_rot2_up)
line.set_x2(current_rot2_up, time)
if not na(current_rot3_up)
line.set_x2(current_rot3_up, time)
if not na(current_rot4_up)
line.set_x2(current_rot4_up, time)
if not na(current_rot5_up)
line.set_x2(current_rot5_up, time)
if not na(current_rot1_dn)
line.set_x2(current_rot1_dn, time)
if not na(current_rot2_dn)
line.set_x2(current_rot2_dn, time)
if not na(current_rot3_dn)
line.set_x2(current_rot3_dn, time)
if not na(current_rot4_dn)
line.set_x2(current_rot4_dn, time)
if not na(current_rot5_dn)
line.set_x2(current_rot5_dn, time)
if show_rotation_labels and pos == "Right"
if not na(current_rot1_up_label)
label.set_x(current_rot1_up_label, time)
if not na(current_rot2_up_label)
label.set_x(current_rot2_up_label, time)
if not na(current_rot3_up_label)
label.set_x(current_rot3_up_label, time)
if not na(current_rot4_up_label)
label.set_x(current_rot4_up_label, time)
if not na(current_rot5_up_label)
label.set_x(current_rot5_up_label, time)
if not na(current_rot1_dn_label)
label.set_x(current_rot1_dn_label, time)
if not na(current_rot2_dn_label)
label.set_x(current_rot2_dn_label, time)
if not na(current_rot3_dn_label)
label.set_x(current_rot3_dn_label, time)
if not na(current_rot4_dn_label)
label.set_x(current_rot4_dn_label, time)
if not na(current_rot5_dn_label)
label.set_x(current_rot5_dn_label, time)