本页源码来自 TradingView 公开发布的开源脚本,版权归原作者所有, 请遵循其原始许可(Pine 脚本常见 CC BY-NC-SA / MPL-2.0 / MIT)。 本项目仅用于研究检索与许可范围内的移植。
//@version=6
indicator('OBR 15min Session Opening Range Breakout + Volume Trend Delta', overlay = true)
// === Display Toggles ===
inputMax = input(15, title = 'ORB Duration (minutes)', group='📦 Session ORB Settings 📦')
show_london_orb = input.bool(true, title = "Show London ORBs")
londonORB = input.session('0700-0715', title = 'London ORB Time (UTC)')
londonSession = input.session('0700-1600', title = 'London Session Time (UTC)')
show_ny_orb = input.bool(true, title = "Show New York ORB")
nyORB = input.session('1330-1345', title = 'New York ORB Time (UTC)')
nySession = input.session('1330-2100', title = 'New York Session Time (UTC)')
london_fill_color = input.color(color.rgb(255, 166, 0, 50), title="London ORB Color")
ny_fill_color = input.color(color.rgb(255, 0, 191, 50), title="New York ORB Color")
hide = timeframe.isintraday and timeframe.multiplier <= inputMax
// === Session Time Checks ===
t_london = time(timeframe.period, londonORB + ':1234567', 'UTC')
t_london_session= time(timeframe.period, londonSession + ':1234567', 'UTC')
t_ny = time(timeframe.period, nyORB + ':1234567', 'UTC')
t_ny_session = time(timeframe.period, nySession + ':1234567', 'UTC')
in_london = not na(t_london)
in_london_session = not na(t_london_session)
in_ny = not na(t_ny)
in_ny_session = not na(t_ny_session)
is_first_london = in_london and not in_london[1]
is_first_ny = in_ny and not in_ny[1]
var float london_high = na
var float london_low = na
var float ny_high = na
var float ny_low = na
if is_first_london
london_high := high
london_low := low
else
london_high := london_high[1]
london_low := london_low[1]
if high > london_high and in_london
london_high := high
if low < london_low and in_london
london_low := low
if is_first_ny
ny_high := high
ny_low := low
else
ny_high := ny_high[1]
ny_low := ny_low[1]
if high > ny_high and in_ny
ny_high := high
if low < ny_low and in_ny
ny_low := low
plot(hide and in_london_session and show_london_orb ? london_high : na, style=plot.style_line, color=london_high[1] != london_high ? na : #00ff6a00, title='London ORB High', linewidth=2)
plot(hide and in_london_session and show_london_orb ? london_low : na, style=plot.style_line, color=london_low[1] != london_low ? na : #00ff6a00, title='London ORB Low', linewidth=2)
plot(hide and in_ny_session and show_ny_orb ? ny_high : na, style=plot.style_line, color=ny_high[1] != ny_high ? na : #00ff6a00, title='New York ORB High', linewidth=2)
plot(hide and in_ny_session and show_ny_orb ? ny_low : na, style=plot.style_line, color=ny_low[1] != ny_low ? na : #00ff6a00, title='New York ORB Low', linewidth=2)
alertcondition(ta.crossover(high, london_high) and in_london_session and not in_london, title="London ORB High Break", message="Price crossed above London ORB High: {{ticker}} at {{close}}")
alertcondition(ta.crossunder(low, london_low) and in_london_session and not in_london, title="London ORB Low Break", message="Price crossed below London ORB Low: {{ticker}} at {{close}}")
alertcondition(ta.crossover(high, ny_high) and in_ny_session and not in_ny, title="New York ORB High Break", message="Price crossed above New York ORB High: {{ticker}} at {{close}}")
alertcondition(ta.crossunder(low, ny_low) and in_ny_session and not in_ny, title="New York ORB Low Break", message="Price crossed below New York ORB Low: {{ticker}} at {{close}}")
show_prev_daily = input.bool(true, title = "Show Previous Daily High/Low/Open", group='🔙 Previous Levels 🔙')
show_prev_4h = input.bool(true, title = "Show Previous 4H High/Low")
// === Previous Day + Previous 4H Data ===
prev_daily_high = request.security(syminfo.tickerid, "D", high[1])
prev_daily_low = request.security(syminfo.tickerid, "D", low[1])
prev_daily_open = request.security(syminfo.tickerid, "D", open[1])
prev_4h_high = request.security(syminfo.tickerid, "240", high[1])
prev_4h_low = request.security(syminfo.tickerid, "240", low[1])
// === Line/Label Handles ===
var line prevD_hi_ln = na
var line prevD_lo_ln = na
var line prevD_op_ln = na
var label prevD_hi_lbl = na
var label prevD_lo_lbl = na
var label prevD_op_lbl = na
var line prev4h_hi_ln = na
var line prev4h_lo_ln = na
var label prev4h_hi_lbl = na
var label prev4h_lo_lbl = na
len = 5
if barstate.islast
// --- Prev Daily ---
if not na(prevD_hi_ln)
line.delete(prevD_hi_ln)
if not na(prevD_lo_ln)
line.delete(prevD_lo_ln)
if not na(prevD_op_ln)
line.delete(prevD_op_ln)
if not na(prevD_hi_lbl)
label.delete(prevD_hi_lbl)
if not na(prevD_lo_lbl)
label.delete(prevD_lo_lbl)
if not na(prevD_op_lbl)
label.delete(prevD_op_lbl)
prevD_hi_ln := show_prev_daily ? line.new(bar_index - len, prev_daily_high, bar_index, prev_daily_high, color=color.rgb(255,255,255), width=2) : na
prevD_lo_ln := show_prev_daily ? line.new(bar_index - len, prev_daily_low, bar_index, prev_daily_low, color=color.rgb(255,255,255), width=2) : na
prevD_op_ln := show_prev_daily ? line.new(bar_index - len, prev_daily_open, bar_index, prev_daily_open, color=color.rgb(255,255,255), width=2) : na
prevD_hi_lbl := show_prev_daily ? label.new(bar_index, prev_daily_high, "Prev D High", style=label.style_label_left, textcolor=color.white, color=color.new(color.white, 100), size=size.small) : na
prevD_lo_lbl := show_prev_daily ? label.new(bar_index, prev_daily_low, "Prev D Low", style=label.style_label_left, textcolor=color.white, color=color.new(color.white, 100), size=size.small) : na
prevD_op_lbl := show_prev_daily ? label.new(bar_index, prev_daily_open, "Prev D Open", style=label.style_label_left, textcolor=color.white, color=color.new(color.rgb(0,128,255), 100), size=size.small) : na
// --- Prev 4H ---
if not na(prev4h_hi_ln)
line.delete(prev4h_hi_ln)
if not na(prev4h_lo_ln)
line.delete(prev4h_lo_ln)
if not na(prev4h_hi_lbl)
label.delete(prev4h_hi_lbl)
if not na(prev4h_lo_lbl)
label.delete(prev4h_lo_lbl)
prev4h_hi_ln := show_prev_4h ? line.new(bar_index - len, prev_4h_high, bar_index, prev_4h_high, color=#ffffff, width=2) : na
prev4h_lo_ln := show_prev_4h ? line.new(bar_index - len, prev_4h_low, bar_index, prev_4h_low, color=#ffffff, width=2) : na
prev4h_hi_lbl := show_prev_4h ? label.new(bar_index, prev_4h_high, "Prev 4H High", style=label.style_label_left, textcolor=color.white, color=color.new(color.rgb(0,255,0), 100), size=size.small) : na
prev4h_lo_lbl := show_prev_4h ? label.new(bar_index, prev_4h_low, "Prev 4H Low", style=label.style_label_left, textcolor=color.white, color=color.new(color.rgb(255,166,0), 100), size=size.small) : na
// === Fill ORBs ===
pLondonHigh = plot(hide and in_london_session and show_london_orb ? london_high : na, style=plot.style_line, color=london_high[1]!=london_high ? na : #00bfff00, title='London ORB High', linewidth=2)
pLondonLow = plot(hide and in_london_session and show_london_orb ? london_low : na, style=plot.style_line, color=london_low[1]!=london_low ? na : #00bfff00, title='London ORB Low', linewidth=2)
pNyHigh = plot(hide and in_ny_session and show_ny_orb ? ny_high : na, style=plot.style_line, color=ny_high[1]!=ny_high ? na : #00bfff00, title='New York ORB High', linewidth=2)
pNyLow = plot(hide and in_ny_session and show_ny_orb ? ny_low : na, style=plot.style_line, color=ny_low[1]!=ny_low ? na : #00bfff00, title='New York ORB Low', linewidth=2)
fill(pLondonHigh, pLondonLow, color=london_fill_color)
fill(pNyHigh, pNyLow, color=ny_fill_color)
// === PARAMETERS ===
len_trend = input.int(10, title = "Trend Period", group='💸Trend Volume Delta💸')
len_momentum = input.int(20, title = "Momentum Window")
price_src = input.source(close, "Price Source")
band_mult = 2
// === DYNAMIC TREND FILTER ===
dynamic_trend(pr, period, mom) =>
var float dyn = na
mom_diff = ta.change(pr)
up_sum = math.sum(mom_diff >= 0 ? mom_diff : 0.0, mom)
dn_sum = math.sum(mom_diff < 0 ? -mom_diff : 0.0, mom)
cmo_raw = nz(up_sum + dn_sum) == 0 ? 0 : math.abs(100 * (up_sum - dn_sum) / (up_sum + dn_sum))
k = 2 / (period + 1)
dyn := k * (cmo_raw / 100) * pr + (1 - k * (cmo_raw / 100)) * nz(dyn[1])
ta.sma(dyn, 15)
trend_ma = dynamic_trend(price_src, len_trend, len_momentum)
atr_basis = ta.atr(200)
band_top = trend_ma + atr_basis * band_mult
band_low = trend_ma - atr_basis * band_mult
// === STATE DETECTION ===
var bool bullish = false
if ta.crossover(price_src, band_top)
bullish := true
if ta.crossunder(price_src, band_low)
bullish := false
prev_bullish = bullish[1]
is_new_bull = bar_index > 0 ? (not prev_bullish and bullish) : false
is_new_bear = bar_index > 0 ? (prev_bullish and not bullish) : false
// === VOLUME ACCUMULATION BY TREND ===
var float bull_vol = 0.0
var float bear_vol = 0.0
if bar_index == 0 or is_new_bull or is_new_bear
bull_vol := 0.0
bear_vol := 0.0
else
bull_vol += close > open ? volume : 0
bear_vol += close < open ? volume : 0
mean_vol = (bull_vol + bear_vol) / 2.0
delta_ratio = mean_vol == 0 ? 0 : ((bull_vol - bear_vol) / mean_vol) * 100
delta_str = str.tostring(delta_ratio, format.percent)
// === TABLE OPTIONS ===
sideInput = input.string("Top Right", title = "Table Side",
options = ["Top Right", "Top Left", "Bottom Right", "Bottom Left"])
fontSizeInput = input.string("normal", title = "Table Size",
options = ["tiny", "small", "normal", "large"])
// pick position
tablePosition = switch sideInput
"Top Right" => position.top_right
"Top Left" => position.top_left
"Bottom Right" => position.bottom_right
=> position.bottom_left
// create / draw table
var table tbl = table.new(tablePosition, 2, 3, border_width = 1)
if barstate.islast
table.cell(tbl, 0, 1, str.tostring(bull_vol, format.volume),
text_color = color.rgb(0,132,255), bgcolor = color.new(#4b4b4b, 65),
text_halign = text.align_center, text_size = fontSizeInput)
table.cell(tbl, 1, 1, str.tostring(bear_vol, format.volume),
text_color = color.rgb(167,0,0), bgcolor = color.new(#4b4b4b, 65),
text_halign = text.align_center, text_size = fontSizeInput)
table.cell(tbl, 0, 2, "Delta:",
text_color = color.white, bgcolor = color.new(#4b4b4b, 65),
text_halign = text.align_center, text_size = fontSizeInput)
table.cell(tbl, 1, 2, delta_str,
text_color = delta_ratio < 0 ? color.rgb(167,0,0) : color.rgb(0,132,255),
bgcolor = color.new(#4b4b4b, 65), text_halign = text.align_center,
text_size = fontSizeInput)