本页源码来自 TradingView 公开发布的开源脚本,版权归原作者所有, 请遵循其原始许可(Pine 脚本常见 CC BY-NC-SA / MPL-2.0 / MIT)。 本项目仅用于研究检索与许可范围内的移植。
//@version=6
indicator("TradeBee Opening Range Liquidity Mean Reversal", shorttitle="TBORLMR", overlay=true, max_lines_count=100, max_labels_count=100)
//=============================================================================
// TBORLMR v1.3.8
// - Custom session inputs enabled only when Custom preset is selected
// - Dynamic level line extension
// - Independent level and confirmation label controls
// - Levels and dashboard display on all intraday chart timeframes
// - Dashboard prioritizes entry and trade levels; range/ATR qualification metrics appear at the bottom
// - Configuration groups follow the same priority: trade monitoring before informational ATR qualification
// - Dashboard table bounds consistent
//=============================================================================
//-----------------------------------------------------------------------------
// 1. SESSION SETTINGS
//-----------------------------------------------------------------------------
groupSession = "01. Session Settings"
sessionPreset = input.string("US Regular", "Session Preset", options=["US Regular", "Europe", "Asia", "India", "Custom"], group=groupSession, tooltip="Select a market session. Standard presets automatically determine session hours and time zone. Select Custom to configure them manually.")
isCustomSession = sessionPreset == "Custom"
customSession = input.session("0930-1600:23456", "Custom Session Hours", group=groupSession, active=isCustomSession, tooltip="Only editable when Session Preset is Custom.")
customTimezone = input.string("New York", "Custom Session Time Zone", options=["Exchange", "New York", "London", "Tokyo", "Kolkata"], group=groupSession, active=isCustomSession, tooltip="Only editable when Session Preset is Custom.")
activeSession = switch sessionPreset
"US Regular" => "0930-1600:23456"
"Europe" => "0800-1630:23456"
"Asia" => "0900-1500:23456"
"India" => "0915-1530:23456"
=> customSession
activeTimezone = switch sessionPreset
"US Regular" => "America/New_York"
"Europe" => "Europe/London"
"Asia" => "Asia/Tokyo"
"India" => "Asia/Kolkata"
=> customTimezone == "New York" ? "America/New_York" : customTimezone == "London" ? "Europe/London" : customTimezone == "Tokyo" ? "Asia/Tokyo" : customTimezone == "Kolkata" ? "Asia/Kolkata" : syminfo.timezone
inSession = not na(time(timeframe.period, activeSession, activeTimezone))
sessionEnded = not inSession and inSession[1]
//-----------------------------------------------------------------------------
// 2. DAILY ATR LIQUIDITY FILTER
//-----------------------------------------------------------------------------
groupTrade = "02. Trade Monitoring"
entryTouchMode = input.string("Wick", "1-Minute Entry Touch Method", options=["Wick", "Body"], group=groupTrade, tooltip="Wick (default): an entry is touched when the 1-minute candle's high-low range crosses the entry price. Body: the candle's open-close body must cross the entry price.")
//-----------------------------------------------------------------------------
// 3. OPENING 15-MINUTE CANDLE DATA
//-----------------------------------------------------------------------------
f_openingData() =>
bool inSession15 = not na(time("15", activeSession, activeTimezone))
bool firstSessionBar = inSession15 and not inSession15[1]
int openingTime = firstSessionBar ? time : na
float openingO = firstSessionBar ? open : na
float openingH = firstSessionBar ? high : na
float openingL = firstSessionBar ? low : na
float openingC = firstSessionBar ? close : na
[openingTime, openingO, openingH, openingL, openingC]
[openingTime15, openingOpen15, openingHigh15, openingLow15, openingClose15] = request.security(syminfo.tickerid, "15", f_openingData(), gaps=barmerge.gaps_off, lookahead=barmerge.lookahead_off)
is1m = timeframe.isminutes and timeframe.multiplier == 1
isIntraday = timeframe.isintraday
var int lastProcessedOpeningTime = na
// The first session candle opens at 09:30 and is not confirmed until its 15-minute close (09:45 for US Regular).
// Processing occurs on the 1-minute bar whose close timestamp equals the 15-minute candle's close timestamp.
newOpeningConfirmed = isIntraday and barstate.isconfirmed and not na(openingTime15) and time_close >= openingTime15 + 15 * 60 * 1000 and (na(lastProcessedOpeningTime) or openingTime15 != lastProcessedOpeningTime)
//-----------------------------------------------------------------------------
// 4. LEVEL DISPLAY AND LABEL SETTINGS
//-----------------------------------------------------------------------------
groupDisplay = "03. Level Display"
showRangeHigh = input.bool(true, "Show Opening Range High", group=groupDisplay, tooltip="Display the opening candle high level.")
showRangeLow = input.bool(true, "Show Opening Range Low", group=groupDisplay, tooltip="Display the opening candle low level.")
showTP1 = input.bool(true, "Show Fibonacci 38.2% (TP1)", group=groupDisplay, tooltip="Display the first Fibonacci retracement target.")
showTP2 = input.bool(true, "Show Fibonacci 61.8% (TP2)", group=groupDisplay, tooltip="Display the second Fibonacci retracement target.")
showTP3 = input.bool(true, "Show TP3 (Midpoint to Opposite Range Boundary)", group=groupDisplay, tooltip="Display TP3 halfway between TP2 and the opposite opening-range boundary: Range High for LONG trades and Range Low for SHORT trades.")
showStop = input.bool(true, "Show Stop Loss", group=groupDisplay, tooltip="Display the calculated stop-loss level.")
showEntry = input.bool(true, "Show Entry Level", group=groupDisplay, tooltip="Display the entry price at the opening range boundary.")
showRangeFill = input.bool(false, "Fill Opening Range", group=groupDisplay, tooltip="Shade the area between the opening range high and low.")
showLevelLabels = input.bool(true, "Show Level Name and Price Labels", group=groupDisplay, tooltip="Enable or disable all Range, Entry, TP and Stop Loss labels. The lines remain visible when labels are disabled.")
showSignalLabels = input.bool(true, "Show Confirmation Labels", group=groupDisplay, tooltip="Enable or disable LONG and SHORT confirmation labels independently of level labels.")
lineWidth = input.int(1, "Line Width", minval=1, maxval=4, group=groupDisplay, tooltip="Thickness of level lines.")
lineLength = input.int(5, "Minimum Line Length (Bars)", minval=1, maxval=100, group=groupDisplay, tooltip="Minimum line length after a line's starting bar. Lines also extend dynamically through the latest bar.")
extraRightBars = input.int(5, "Extension Beyond Latest Bar", minval=0, maxval=100, group=groupDisplay, tooltip="Number of bars to extend levels beyond the latest chart bar. Default is 5.")
lineStyleInput = input.string("Solid", "Line Style", options=["Solid", "Dashed", "Dotted"], group=groupDisplay, tooltip="Choose the line style used consistently by all level lines.")
levelLabelSizeInput = input.string("Small", "Level Label Size", options=["Tiny", "Small", "Normal", "Large"], group=groupDisplay, tooltip="Text size for level-name and price labels.")
signalLabelSizeInput = input.string("Small", "Confirmation Label Size", options=["Tiny", "Small", "Normal", "Large"], group=groupDisplay, tooltip="Text size for LONG and SHORT confirmation labels.")
levelLabelTextColor = input.color(color.white, "Level Label Text Color", group=groupDisplay, tooltip="Text color for Range, Entry, TP and Stop Loss labels.")
confirmationTextColor = input.color(color.white, "Confirmation Label Text Color", group=groupDisplay, tooltip="Text color for LONG and SHORT confirmation labels.")
rangeHighColor = input.color(color.red, "Range High / Resistance", group=groupDisplay, tooltip="Line and label background color for Range High.")
rangeLowColor = input.color(#388E3C, "Range Low / Support", group=groupDisplay, tooltip="Line and label background color for Range Low. Default #388E3C.")
entryColor = input.color(color.yellow, "Entry Level", group=groupDisplay, tooltip="Line and label background color for Entry.")
tp1Color = input.color(#7CFC00, "TP1 Color", group=groupDisplay, tooltip="Color for the 38.2% target. Default #7CFC00.")
tp2Color = input.color(#388E3C, "TP2 Color", group=groupDisplay, tooltip="Color for the 61.8% target. Default #388E3C.")
tp3Color = input.color(#0097a7, "TP3 Color", group=groupDisplay, tooltip="Color for TP3, halfway between TP2 and the opposite opening-range boundary.")
stopColor = input.color(color.fuchsia, "Stop Loss Color", group=groupDisplay, tooltip="Line and label background color for Stop Loss.")
bullLabelColor = input.color(color.green, "Long Confirmation Background", group=groupDisplay, tooltip="Background color for the LONG confirmation label.")
bearLabelColor = input.color(color.red, "Short Confirmation Background", group=groupDisplay, tooltip="Background color for the SHORT confirmation label.")
f_lineStyle(string style) =>
style == "Dashed" ? line.style_dashed : style == "Dotted" ? line.style_dotted : line.style_solid
f_labelSize(string s) =>
s == "Tiny" ? size.tiny : s == "Normal" ? size.normal : s == "Large" ? size.large : size.small
f_price(float price) =>
na(price) ? "—" : "$" + str.tostring(price, format.mintick)
f_createLevel(float price, string levelName, color levelColor) =>
int endBar = bar_index + math.max(lineLength, extraRightBars)
line newLine = line.new(bar_index, price, endBar, price, extend=extend.none, color=levelColor, width=lineWidth, style=f_lineStyle(lineStyleInput))
label startLabel = na
label endLabel = na
if showLevelLabels
startLabel := label.new(bar_index, price, levelName, xloc=xloc.bar_index, yloc=yloc.price, style=label.style_label_right, color=levelColor, textcolor=levelLabelTextColor, size=f_labelSize(levelLabelSizeInput))
endLabel := label.new(endBar, price, f_price(price), xloc=xloc.bar_index, yloc=yloc.price, style=label.style_label_left, color=levelColor, textcolor=levelLabelTextColor, size=f_labelSize(levelLabelSizeInput))
[newLine, startLabel, endLabel]
//-----------------------------------------------------------------------------
// 5. DASHBOARD SETTINGS
//-----------------------------------------------------------------------------
groupDash = "04. Dashboard"
showDashboard = input.bool(true, "Show Dashboard", group=groupDash, tooltip="Show or hide the information panel.")
showTableHeader = input.bool(true, "Show Table Header", group=groupDash, tooltip="Show or hide the dashboard title row.")
// Independent visibility controls for each dashboard row.
showStatusRow = input.bool(true, "Show Setup Status Row", group=groupDash, tooltip="Show or hide the Setup Status row in the dashboard.")
showBiasRow = input.bool(true, "Show Detected Bias Row", group=groupDash, tooltip="Show or hide the opening 15-minute candle bias row.")
showDirectionRow = input.bool(true, "Show Trade Direction Row", group=groupDash, tooltip="Show or hide the trade direction row.")
showSessionRow = input.bool(true, "Show Session Row", group=groupDash, tooltip="Show or hide the selected session row.")
showEntryRow = input.bool(true, "Show Entry Row", group=groupDash, tooltip="Show or hide the entry price row.")
showTouchesRow = input.bool(true, "Show 1m Entry Touches Row", group=groupDash, tooltip="Show or hide the 1-minute entry touch count and selected touch method.")
showTP1Row = input.bool(true, "Show TP1 Row", group=groupDash, tooltip="Show or hide the 38.2% target row.")
showTP2Row = input.bool(true, "Show TP2 Row", group=groupDash, tooltip="Show or hide the 61.8% target row.")
showTP3Row = input.bool(true, "Show TP3 Row", group=groupDash, tooltip="Show or hide the TP3 target row.")
showStopRow = input.bool(true, "Show Stop Loss Row", group=groupDash, tooltip="Show or hide the stop-loss row.")
showRangeHighRow = input.bool(true, "Show Range High Row", group=groupDash, tooltip="Show or hide the opening range high row.")
showRangeLowRow = input.bool(true, "Show Range Low Row", group=groupDash, tooltip="Show or hide the opening range low row.")
showRangeSizeRow = input.bool(true, "Show Range Size Row", group=groupDash, tooltip="Show or hide the opening range size row.")
showATRRow = input.bool(true, "Show Daily ATR Row", group=groupDash, tooltip="Show or hide the previous completed daily ATR row.")
showRequiredRangeRow = input.bool(true, "Show Required Range Row", group=groupDash, tooltip="Show or hide the minimum range required by the ATR filter row.")
dashboardPosition = input.string("Middle Right", "Panel Position", options=["Top Right", "Top Left", "Middle Right", "Middle Left", "Bottom Right", "Bottom Left"], group=groupDash, tooltip="Choose the dashboard location.")
dashboardSize = input.string("Small", "Text Size", options=["Tiny", "Small", "Normal"], group=groupDash, tooltip="Dashboard text size.")
headerBg = input.color(color.rgb(35, 45, 65), "Header Background", group=groupDash, tooltip="Dashboard header background.")
headerText = input.color(color.white, "Header Text", group=groupDash, tooltip="Dashboard header text.")
panelBg = input.color(color.rgb(25, 28, 35), "Panel Background", group=groupDash, tooltip="Default dashboard row background.")
panelText = input.color(color.white, "Panel Text", group=groupDash, tooltip="Dashboard row text.")
supportRowBg = input.color(color.new(#388E3C, 78), "Support Row Background", group=groupDash, tooltip="Range Low row background.")
resistanceRowBg = input.color(color.new(color.red, 78), "Resistance Row Background", group=groupDash, tooltip="Range High row background.")
signalRowBg = input.color(color.new(color.blue, 78), "Neutral Signal Row Background", group=groupDash, tooltip="Background used for direction and entry rows when no confirmed LONG or SHORT setup is available. Confirmed LONG rows use the long color; confirmed SHORT rows use the short color.")
targetRowBg = input.color(color.new(#388E3C, 82), "Target Row Background", group=groupDash, tooltip="TP1 and TP2 row background.")
stopRowBg = input.color(color.new(color.purple, 80), "Stop Row Background", group=groupDash, tooltip="Stop-loss row background.")
bullBiasBg = input.color(color.new(#388E3C, 65), "Bullish Bias Background", group=groupDash, tooltip="Background for bullish opening bias.")
bearBiasBg = input.color(color.new(color.red, 65), "Bearish Bias Background", group=groupDash, tooltip="Background for bearish opening bias.")
neutralBiasBg = input.color(color.new(color.gray, 65), "Doji / No Bias Background", group=groupDash, tooltip="Background for doji or no directional bias.")
// Informational / qualification settings are grouped last to match the dashboard.
groupATR = "05. Range Qualification"
atrLength = input.int(14, "Daily ATR Length", minval=1, group=groupATR, tooltip="Number of daily candles used to calculate ATR. The previous completed daily ATR is used.")
atrPercent = input.float(25.0, "Minimum Opening Range (% of Daily ATR)", minval=0.1, maxval=100.0, step=0.5, group=groupATR, tooltip="Minimum opening 15-minute range required as a percentage of the previous completed daily ATR.")
// Calculate the previous completed daily ATR after its length input has been declared.
dailyATR = request.security(syminfo.tickerid, "D", ta.atr(atrLength)[1], gaps=barmerge.gaps_off, lookahead=barmerge.lookahead_on)
f_position(string p) =>
switch p
"Top Left" => position.top_left
"Middle Right" => position.middle_right
"Middle Left" => position.middle_left
"Bottom Right" => position.bottom_right
"Bottom Left" => position.bottom_left
=> position.top_right
f_textSize(string s) =>
s == "Tiny" ? size.tiny : s == "Normal" ? size.normal : size.small
//-----------------------------------------------------------------------------
// 6. PERSISTENT SETUP STATE
//-----------------------------------------------------------------------------
var float rangeHigh = na
var float rangeLow = na
var float rangeSize = na
var float openingOpen = na
var float openingClose = na
var float entryPrice = na
var float target1 = na
var float target2 = na
var float target3 = na
var float stopPrice = na
var float atrAtSetup = na
var float requiredAtSetup = na
var int setupBarIndex = na
var int touchCount = 0
var bool setupValid = false
var bool isLong = false
var bool entryFilled = false
var bool tp1Hit = false
var bool tp2Hit = false
var bool tp3Hit = false
var bool stopHit = false
var bool setupExpired = false
var bool setupDone = false
var string biasText = "Waiting for opening candle"
var string statusText = "Waiting for opening candle"
var line highLine = na
var line lowLine = na
var line entryLine = na
var line tp1Line = na
var line tp2Line = na
var line tp3Line = na
var line stopLine = na
var linefill rangeFill = na
var label setupLabel = na
var label highStartLabel = na
var label highEndLabel = na
var label lowStartLabel = na
var label lowEndLabel = na
var label entryStartLabel = na
var label entryEndLabel = na
var label tp1StartLabel = na
var label tp1EndLabel = na
var label tp2StartLabel = na
var label tp2EndLabel = na
var label tp3StartLabel = na
var label tp3EndLabel = na
var label stopStartLabel = na
var label stopEndLabel = na
bool setupConfirmedAlert = false
bool entryTouchedAlert = false
bool tp1Alert = false
bool tp2Alert = false
bool tp3Alert = false
bool stopAlert = false
//-----------------------------------------------------------------------------
// 7. CONFIRM AND PROCESS OPENING CANDLE
//-----------------------------------------------------------------------------
if newOpeningConfirmed
lastProcessedOpeningTime := openingTime15
if not na(highLine)
line.delete(highLine)
if not na(lowLine)
line.delete(lowLine)
if not na(entryLine)
line.delete(entryLine)
if not na(tp1Line)
line.delete(tp1Line)
if not na(tp2Line)
line.delete(tp2Line)
if not na(tp3Line)
line.delete(tp3Line)
if not na(stopLine)
line.delete(stopLine)
if not na(rangeFill)
linefill.delete(rangeFill)
if not na(setupLabel)
label.delete(setupLabel)
if not na(highStartLabel)
label.delete(highStartLabel)
if not na(highEndLabel)
label.delete(highEndLabel)
if not na(lowStartLabel)
label.delete(lowStartLabel)
if not na(lowEndLabel)
label.delete(lowEndLabel)
if not na(entryStartLabel)
label.delete(entryStartLabel)
if not na(entryEndLabel)
label.delete(entryEndLabel)
if not na(tp1StartLabel)
label.delete(tp1StartLabel)
if not na(tp1EndLabel)
label.delete(tp1EndLabel)
if not na(tp2StartLabel)
label.delete(tp2StartLabel)
if not na(tp2EndLabel)
label.delete(tp2EndLabel)
if not na(tp3StartLabel)
label.delete(tp3StartLabel)
if not na(tp3EndLabel)
label.delete(tp3EndLabel)
if not na(stopStartLabel)
label.delete(stopStartLabel)
if not na(stopEndLabel)
label.delete(stopEndLabel)
rangeHigh := openingHigh15
rangeLow := openingLow15
rangeSize := rangeHigh - rangeLow
openingOpen := openingOpen15
openingClose := openingClose15
atrAtSetup := dailyATR
requiredAtSetup := not na(dailyATR) ? dailyATR * atrPercent / 100.0 : na
entryPrice := na
target1 := na
target2 := na
target3 := na
stopPrice := na
setupBarIndex := bar_index
touchCount := 0
setupValid := false
isLong := false
entryFilled := false
tp1Hit := false
tp2Hit := false
tp3Hit := false
stopHit := false
setupExpired := false
setupDone := false
biasText := openingClose15 < openingOpen15 ? "BEARISH DETECTED" : openingClose15 > openingOpen15 ? "BULLISH DETECTED" : "DOJI - NO DIRECTION"
bool directionalCandle = openingClose15 != openingOpen15
bool liquidityQualified = not na(requiredAtSetup) and rangeSize >= requiredAtSetup
if directionalCandle and liquidityQualified
setupValid := true
isLong := openingClose15 < openingOpen15
entryPrice := isLong ? rangeLow : rangeHigh
target1 := isLong ? rangeLow + rangeSize * 0.382 : rangeHigh - rangeSize * 0.382
target2 := isLong ? rangeLow + rangeSize * 0.618 : rangeHigh - rangeSize * 0.618
target3 := isLong ? target2 + (rangeHigh - target2) / 2.0 : target2 - (target2 - rangeLow) / 2.0
stopPrice := isLong ? entryPrice - (target1 - entryPrice) / 2.0 : entryPrice + (entryPrice - target1) / 2.0
statusText := "Waiting for 1m Entry"
setupConfirmedAlert := true
if showSignalLabels
setupLabel := label.new(bar_index, isLong ? rangeLow : rangeHigh, isLong ? "LONG\n15m Confirmed" : "SHORT\n15m Confirmed", style=isLong ? label.style_label_up : label.style_label_down, color=isLong ? bullLabelColor : bearLabelColor, textcolor=confirmationTextColor, size=f_labelSize(signalLabelSizeInput))
else
statusText := not directionalCandle ? "Doji - No Setup" : na(dailyATR) ? "Daily ATR Unavailable" : "Liquidity Not Confirmed"
if showRangeHigh
[newHighLine, newHighStartLabel, newHighEndLabel] = f_createLevel(rangeHigh, "Range High / Resistance", rangeHighColor)
highLine := newHighLine
highStartLabel := newHighStartLabel
highEndLabel := newHighEndLabel
if showRangeLow
[newLowLine, newLowStartLabel, newLowEndLabel] = f_createLevel(rangeLow, "Range Low / Support", rangeLowColor)
lowLine := newLowLine
lowStartLabel := newLowStartLabel
lowEndLabel := newLowEndLabel
if showRangeFill and not na(highLine) and not na(lowLine)
rangeFill := linefill.new(highLine, lowLine, color=color.new(color.blue, 92))
if setupValid
if showEntry
[newEntryLine, newEntryStartLabel, newEntryEndLabel] = f_createLevel(entryPrice, "Entry", entryColor)
entryLine := newEntryLine
entryStartLabel := newEntryStartLabel
entryEndLabel := newEntryEndLabel
if showTP1
[newTP1Line, newTP1StartLabel, newTP1EndLabel] = f_createLevel(target1, "TP1 - 38.2%", tp1Color)
tp1Line := newTP1Line
tp1StartLabel := newTP1StartLabel
tp1EndLabel := newTP1EndLabel
if showTP2
[newTP2Line, newTP2StartLabel, newTP2EndLabel] = f_createLevel(target2, "TP2 - 61.8%", tp2Color)
tp2Line := newTP2Line
tp2StartLabel := newTP2StartLabel
tp2EndLabel := newTP2EndLabel
if showTP3
[newTP3Line, newTP3StartLabel, newTP3EndLabel] = f_createLevel(target3, "TP3", tp3Color)
tp3Line := newTP3Line
tp3StartLabel := newTP3StartLabel
tp3EndLabel := newTP3EndLabel
if showStop
[newStopLine, newStopStartLabel, newStopEndLabel] = f_createLevel(stopPrice, "Stop Loss", stopColor)
stopLine := newStopLine
stopStartLabel := newStopStartLabel
stopEndLabel := newStopEndLabel
//-----------------------------------------------------------------------------
// 8. DYNAMIC LINE EXTENSION AND END-PRICE LABELS
//-----------------------------------------------------------------------------
int dynamicEndBar = bar_index + extraRightBars
if not na(highLine)
line.set_x2(highLine, math.max(line.get_x1(highLine) + lineLength, dynamicEndBar))
if not na(lowLine)
line.set_x2(lowLine, math.max(line.get_x1(lowLine) + lineLength, dynamicEndBar))
if not na(entryLine)
line.set_x2(entryLine, math.max(line.get_x1(entryLine) + lineLength, dynamicEndBar))
if not na(tp1Line)
line.set_x2(tp1Line, math.max(line.get_x1(tp1Line) + lineLength, dynamicEndBar))
if not na(tp2Line)
line.set_x2(tp2Line, math.max(line.get_x1(tp2Line) + lineLength, dynamicEndBar))
if not na(tp3Line)
line.set_x2(tp3Line, math.max(line.get_x1(tp3Line) + lineLength, dynamicEndBar))
if not na(stopLine)
line.set_x2(stopLine, math.max(line.get_x1(stopLine) + lineLength, dynamicEndBar))
if not na(highEndLabel) and not na(highLine)
label.set_x(highEndLabel, line.get_x2(highLine))
if not na(lowEndLabel) and not na(lowLine)
label.set_x(lowEndLabel, line.get_x2(lowLine))
if not na(entryEndLabel) and not na(entryLine)
label.set_x(entryEndLabel, line.get_x2(entryLine))
if not na(tp1EndLabel) and not na(tp1Line)
label.set_x(tp1EndLabel, line.get_x2(tp1Line))
if not na(tp2EndLabel) and not na(tp2Line)
label.set_x(tp2EndLabel, line.get_x2(tp2Line))
if not na(tp3EndLabel) and not na(tp3Line)
label.set_x(tp3EndLabel, line.get_x2(tp3Line))
if not na(stopEndLabel) and not na(stopLine)
label.set_x(stopEndLabel, line.get_x2(stopLine))
//-----------------------------------------------------------------------------
// 9. 1-MINUTE ENTRY TOUCHES AND TRADE MONITORING
//-----------------------------------------------------------------------------
if is1m and barstate.isconfirmed and setupValid and not setupDone and not na(setupBarIndex) and bar_index > setupBarIndex
bool touchesEntry = entryTouchMode == "Wick" ? (low <= entryPrice and high >= entryPrice) : (math.min(open, close) <= entryPrice and math.max(open, close) >= entryPrice)
if touchesEntry
touchCount += 1
if not entryFilled
entryFilled := true
entryTouchedAlert := true
statusText := "Entry Filled"
// Conservative same-candle rule: stop takes precedence over targets.
if entryFilled and not setupDone
bool touchesStop = isLong ? low <= stopPrice : high >= stopPrice
if touchesStop
stopHit := true
setupDone := true
statusText := "Stop Loss Hit"
stopAlert := true
else
bool touchesTP1 = isLong ? high >= target1 : low <= target1
bool touchesTP2 = isLong ? high >= target2 : low <= target2
bool touchesTP3 = isLong ? high >= target3 : low <= target3
if touchesTP1 and not tp1Hit
tp1Hit := true
statusText := "TP1 Hit - Runner Active"
tp1Alert := true
if touchesTP2 and not tp2Hit
tp2Hit := true
statusText := "TP2 Hit - TP3 Runner Active"
tp2Alert := true
if touchesTP3 and not tp3Hit
tp3Hit := true
setupDone := true
statusText := "TP3 Hit - Complete"
tp3Alert := true
if is1m and barstate.isconfirmed and sessionEnded and setupValid and not entryFilled and not setupDone
setupExpired := true
setupDone := true
statusText := "Unfilled - Session End"
//-----------------------------------------------------------------------------
// 10. DASHBOARD
//-----------------------------------------------------------------------------
var table dash = table.new(f_position(dashboardPosition), 2, 16, border_width=1, frame_color=color.gray, border_color=color.new(color.gray, 50))
if barstate.islast
table.clear(dash, 0, 0, 1, 15)
if showDashboard
int r = 0
txtSize = f_textSize(dashboardSize)
if showTableHeader
table.cell(dash, 0, r, "TBORLMR", bgcolor=headerBg, text_color=headerText, text_size=txtSize)
table.cell(dash, 1, r, "Range Reversal", bgcolor=headerBg, text_color=headerText, text_size=txtSize)
r += 1
string displayedStatus = not isIntraday ? "USE INTRADAY CHART" : not is1m and setupValid and not entryFilled and not setupDone ? statusText + " (1m touch tracking)" : statusText
// Dashboard trade rows use the Dashboard Bias Background inputs, not confirmation-label colors.
color directionBg = setupValid ? (isLong ? bullBiasBg : bearBiasBg) : neutralBiasBg
color statusBg = not isIntraday ? color.orange : stopHit ? stopRowBg : tp2Hit ? targetRowBg : setupValid ? directionBg : neutralBiasBg
if showStatusRow
table.cell(dash, 0, r, "Setup Status", bgcolor=statusBg, text_color=panelText, text_size=txtSize)
table.cell(dash, 1, r, displayedStatus, bgcolor=statusBg, text_color=panelText, text_size=txtSize)
r += 1
if showBiasRow
color biasBg = str.contains(biasText, "BULLISH") ? bullBiasBg : str.contains(biasText, "BEARISH") ? bearBiasBg : neutralBiasBg
table.cell(dash, 0, r, "Detected Bias (15m)", bgcolor=biasBg, text_color=panelText, text_size=txtSize)
table.cell(dash, 1, r, biasText, bgcolor=biasBg, text_color=panelText, text_size=txtSize)
r += 1
if showDirectionRow
table.cell(dash, 0, r, "Trade Direction", bgcolor=directionBg, text_color=panelText, text_size=txtSize)
table.cell(dash, 1, r, setupValid ? (isLong ? "LONG (opposite bias)" : "SHORT (opposite bias)") : "No confirmed setup", bgcolor=directionBg, text_color=panelText, text_size=txtSize)
r += 1
if showSessionRow
table.cell(dash, 0, r, "Session", bgcolor=panelBg, text_color=panelText, text_size=txtSize)
table.cell(dash, 1, r, sessionPreset, bgcolor=panelBg, text_color=panelText, text_size=txtSize)
r += 1
if showEntryRow
table.cell(dash, 0, r, "Entry", bgcolor=directionBg, text_color=panelText, text_size=txtSize)
table.cell(dash, 1, r, na(entryPrice) ? "—" : f_price(entryPrice) + (entryFilled ? " FILLED" : ""), bgcolor=directionBg, text_color=panelText, text_size=txtSize)
r += 1
if showTouchesRow
table.cell(dash, 0, r, "1m Entry Touches", bgcolor=panelBg, text_color=panelText, text_size=txtSize)
table.cell(dash, 1, r, str.tostring(touchCount) + " (" + entryTouchMode + ")", bgcolor=panelBg, text_color=panelText, text_size=txtSize)
r += 1
if showTP1Row
table.cell(dash, 0, r, "TP1 - 38.2%", bgcolor=targetRowBg, text_color=panelText, text_size=txtSize)
table.cell(dash, 1, r, na(target1) ? "—" : f_price(target1) + (tp1Hit ? " HIT" : ""), bgcolor=targetRowBg, text_color=panelText, text_size=txtSize)
r += 1
if showTP2Row
table.cell(dash, 0, r, "TP2 - 61.8%", bgcolor=targetRowBg, text_color=panelText, text_size=txtSize)
table.cell(dash, 1, r, na(target2) ? "—" : f_price(target2) + (tp2Hit ? " HIT" : ""), bgcolor=targetRowBg, text_color=panelText, text_size=txtSize)
r += 1
if showTP3Row
table.cell(dash, 0, r, "TP3", bgcolor=targetRowBg, text_color=panelText, text_size=txtSize)
table.cell(dash, 1, r, na(target3) ? "—" : f_price(target3) + (tp3Hit ? " HIT" : ""), bgcolor=targetRowBg, text_color=panelText, text_size=txtSize)
r += 1
if showStopRow
table.cell(dash, 0, r, "Stop Loss (2:1 TP1)", bgcolor=stopRowBg, text_color=panelText, text_size=txtSize)
table.cell(dash, 1, r, na(stopPrice) ? "—" : f_price(stopPrice) + (stopHit ? " HIT" : ""), bgcolor=stopRowBg, text_color=panelText, text_size=txtSize)
r += 1
if showRangeHighRow
table.cell(dash, 0, r, "Range High", bgcolor=resistanceRowBg, text_color=panelText, text_size=txtSize)
table.cell(dash, 1, r, f_price(rangeHigh), bgcolor=resistanceRowBg, text_color=panelText, text_size=txtSize)
r += 1
if showRangeLowRow
table.cell(dash, 0, r, "Range Low", bgcolor=supportRowBg, text_color=panelText, text_size=txtSize)
table.cell(dash, 1, r, f_price(rangeLow), bgcolor=supportRowBg, text_color=panelText, text_size=txtSize)
r += 1
if showRangeSizeRow
table.cell(dash, 0, r, "Range Size", bgcolor=panelBg, text_color=panelText, text_size=txtSize)
table.cell(dash, 1, r, f_price(rangeSize), bgcolor=panelBg, text_color=panelText, text_size=txtSize)
r += 1
if showATRRow
table.cell(dash, 0, r, "Daily ATR (" + str.tostring(atrLength) + ")", bgcolor=panelBg, text_color=panelText, text_size=txtSize)
table.cell(dash, 1, r, f_price(atrAtSetup), bgcolor=panelBg, text_color=panelText, text_size=txtSize)
r += 1
if showRequiredRangeRow
table.cell(dash, 0, r, "Required Range", bgcolor=panelBg, text_color=panelText, text_size=txtSize)
table.cell(dash, 1, r, f_price(requiredAtSetup), bgcolor=panelBg, text_color=panelText, text_size=txtSize)
r += 1
// 11. ALERTS
//-----------------------------------------------------------------------------
alertcondition(setupConfirmedAlert, title="TBORLMR Liquidity Setup Confirmed", message="TBORLMR: The confirmed 15-minute opening candle passed the daily ATR liquidity filter.")
alertcondition(entryTouchedAlert, title="TBORLMR Entry Touched", message="TBORLMR: The 1-minute candle touched the opening-range entry price.")
alertcondition(tp1Alert, title="TBORLMR TP1 Hit", message="TBORLMR: The 38.2% Fibonacci target was reached.")
alertcondition(tp2Alert, title="TBORLMR TP2 Hit", message="TBORLMR: The 61.8% Fibonacci target was reached; TP3 monitoring continues.")
alertcondition(tp3Alert, title="TBORLMR TP3 Hit", message="TBORLMR: TP3, halfway between TP2 and the opposite opening-range boundary, was reached.")
alertcondition(stopAlert, title="TBORLMR Stop Loss Hit", message="TBORLMR: The stop-loss level was reached.")