Open Range Breakout (ORB) with Alerts

ChartsAlgo · study · 76 行 · 点赞 1,121 · TradingView 原页

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

Pine Script

//@version=6
//@description The Open Range Breakout (ORB) Indicator identifies user-defined numbers of price breakouts from a daily opening range, ideal for intraday trading MNQ, MES, or other instruments. It plots high/low range lines, optional background fill, breakout signals with triangles, and triggers alerts, with flexible session times and visuals.
indicator("Open Range Breakout (ORB) with Alerts", overlay=true)
 
/// === USER INPUTS ===
rangeSession = input.session("0930-0945", title="Range Session (e.g., 09:30–09:45)", group="Session Settings")
timezone = input.string("America/New_York", title="Timezone", options=["America/New_York", "GMT+0"], group="Session Settings")
signalsUp = input.int(1, title="Number of Bullish Breakout Signals", minval=1, maxval=20, group="Breakout Settings")
signalsDn = input.int(1, title="Number of Bearish Breakout Signals", minval=1, maxval=20, group="Breakout Settings")
showRangeFill = input.bool(true, title="Show Background Fill?", group="Display Settings")
showSignals = input.bool(true, title="Show Breakout Signals?", group="Display Settings")
todayOnly = input.bool(true, title="Only Show Today's Range?", group="Display Settings")
rangeHighColor = input.color(color.green, title="Range High Line Color", group="Color Settings")
rangeLowColor = input.color(color.red, title="Range Low Line Color", group="Color Settings")
rangeFillColor = input.color(color.teal, title="Background Fill Color", group="Color Settings")
 
/// === TIME CONTROLS ===
day_id = time("D", timezone)
isNewDay = day_id != day_id[1]
var float rangeHigh = na
var float rangeLow = na
var bool rangeSet = false
var int currentDay = na
var int countUp = 0
var int countDn = 0
 
inRangeSession = not na(time("", rangeSession, timezone))
currentDay := day_id
 
// Reset range and breakout counts at new day
if isNewDay
    rangeHigh := na
    rangeLow := na
    rangeSet := false
    countUp := 0
    countDn := 0
 
// Build range during session
if inRangeSession
    rangeHigh := na(rangeHigh) ? high : math.max(rangeHigh, high)
    rangeLow := na(rangeLow) ? low : math.min(rangeLow, low)
    rangeSet := false
else
    if not rangeSet and not na(rangeHigh) and not na(rangeLow)
        rangeSet := true
 
/// === BREAKOUT CONDITIONS ===
breakoutUp = rangeSet and close > rangeHigh and countUp < signalsUp
breakoutDn = rangeSet and close < rangeLow and countDn < signalsDn
 
// Update breakout counts
if breakoutUp
    countUp := countUp + 1
if breakoutDn
    countDn := countDn + 1
 
/// === PLOT RANGE LINES ===
plotRangeHigh = todayOnly and currentDay != day_id ? na : rangeHigh
plotRangeLow = todayOnly and currentDay != day_id ? na : rangeLow
 
plot(plotRangeHigh, title="Range High", color=rangeHighColor, linewidth=2, style=plot.style_linebr)
plot(plotRangeLow, title="Range Low", color=rangeLowColor, linewidth=2, style=plot.style_linebr)
 
/// === BACKGROUND FILL ===
fillColor = showRangeFill and rangeSet ? color.new(rangeFillColor, 90) : na
bg_fill = plot(showRangeFill ? rangeHigh : na, title="High Fill", display=display.none)
bg_base = plot(showRangeFill ? rangeLow : na, title="Low Fill", display=display.none)
fill(bg_fill, bg_base, color=fillColor)
 
/// === BREAKOUT SIGNAL SHAPES ===
plotshape(showSignals and breakoutUp, location=location.belowbar, color=color.green, style=shape.triangleup, size=size.small, title="Breakout Up")
plotshape(showSignals and breakoutDn, location=location.abovebar, color=color.red, style=shape.triangledown, size=size.small, title="Breakout Down")
 
/// === ALERT CONDITIONS ===
alertcondition(breakoutUp, title="ORB Breakout Up", message="Bullish Breakout above Open Range on {{ticker}}!")
alertcondition(breakoutDn, title="ORB Breakout Down", message="Bearish Breakout below Open Range on {{ticker}}!")

← 返回列表