Opening Range Breakout

vasireddiramu78 · study · 52 行 · 点赞 128 · TradingView 原页

本页源码来自 TradingView 公开发布的开源脚本,版权归原作者所有, 请遵循其原始许可(Pine 脚本常见 CC BY-NC-SA / MPL-2.0 / MIT)。 本项目仅用于研究检索与许可范围内的移植。

Pine Script

//@version=5
indicator("Opening Range Breakout", overlay=true)
 
// === Inputs ===
inputMax = input.int(15, "ORB Time Limit (minutes)")
sess = input.session("0915-0930", "ORB Session Time")
showBG = input.bool(true, "Show Breakout Background")
showLbl = input.bool(true, "Show Breakout Labels")
showLineLabels = input.bool(true, "Show ORB High/Low Text Labels")
 
// === Visibility & Session Logic ===
hide = timeframe.isintraday and timeframe.multiplier <= inputMax
in_session = not na(time(timeframe.period, sess + ":1234567"))
is_first = in_session and not in_session[1]
 
// === ORB High/Low Capture ===
var float orb_high = na, var float orb_low = na
if is_first
    orb_high := high
    orb_low := low
else if in_session
    orb_high := math.max(orb_high, high)
    orb_low := math.min(orb_low, low)
 
// === Plot ORB Lines ===
plot(hide and not na(orb_high) ? orb_high : na, "ORB High", color=orb_high != orb_high[1] ? na : color.green, linewidth=2)
plot(hide and not na(orb_low) ? orb_low : na, "ORB Low", color=orb_low != orb_low[1] ? na : color.red, linewidth=2)
 
// === Breakout Conditions ===
breaksAbove = ta.crossover(close, orb_high)
breaksBelow = ta.crossunder(close, orb_low)
 
// === Background Highlights ===
bgcolor(showBG and breaksAbove ? color.new(color.green, 85) : na)
bgcolor(showBG and breaksBelow ? color.new(color.red, 85) : na)
 
// === Breakout Labels (Optional) ===
if showLbl and breaksAbove
    label.new(bar_index, high, "Breakout ↑ " + str.tostring(close), style=label.style_label_left, color=color.green, textcolor=color.white, size=size.small)
if showLbl and breaksBelow
    label.new(bar_index, low, "Breakout ↓ " + str.tostring(close), style=label.style_label_left, color=color.red, textcolor=color.white, size=size.small)
 
// === Live Line-Attached Labels (Right Aligned, 1 per bar) ===
var label orbHighLabel = na, var label orbLowLabel = na
if showLineLabels
    label.delete(orbHighLabel), label.delete(orbLowLabel)
    orbHighLabel := label.new(x=bar_index, y=orb_high, text="ORB High", style=label.style_label_right, textcolor=color.white, color=color.green, size=size.small)
    orbLowLabel := label.new(x=bar_index, y=orb_low, text="ORB Low", style=label.style_label_right, textcolor=color.white, color=color.red, size=size.small)
 
// === Alerts ===
alertcondition(breaksAbove, title="Breakout Above ORB High", message="🔼 Price broke above ORB High: {{close}}")
alertcondition(breaksBelow, title="Breakout Below ORB Low", message="🔽 Price broke below ORB Low: {{close}}")

← 返回列表