ORB 369 - Opening Range Breakout

Niko-picasso369 · study · 77 行 · 点赞 304 · TradingView 原页

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

Pine Script

//@version=6
indicator("ORB 369 - Opening Range Breakout", overlay = true, max_boxes_count = 500)
 
// --- Inputs ---
grp_orb = "ORB Settings"
orb_time = input.session("0930-0945", "ORB Time Session (NY Time)", group = grp_orb, tooltip = "The 15-minute window to establish the range.")
timezone = input.string("America/New_York", "Timezone", group = grp_orb)
 
grp_style = "Style & Colors"
up_color   = input.color(color.green, "Bullish Breakout Color", group = grp_style)
down_color = input.color(color.red, "Bearish Breakout Color", group = grp_style)
range_col  = input.color(color.new(color.gray, 50), "Range Border Color", group = grp_style)
mid_col    = input.color(color.new(color.gray, 70), "Midline Color", group = grp_style)
 
grp_sd = "Supply & Demand"
show_sd    = input.bool(true, "Detect S/D inside ORB?", group = grp_sd, tooltip = "Identifies unmitigated wicks/zones within the 15m range.")
sd_color   = input.color(color.new(color.blue, 80), "S/D Zone Color", group = grp_sd)
 
// --- Logic: Session & Range ---
// Check if we are within the specified session
in_session = not na(time(timeframe.period, orb_time, timezone))
is_new_day = ta.change(time("D", timezone)) != 0
 
var float orb_high = na
var float orb_low  = na
var float orb_mid  = na
var bool breakout_hit = false
 
// Reset at the start of a new day
if is_new_day
    orb_high := na
    orb_low  := na
    orb_mid  := na
    breakout_hit := false
 
// Capture High/Low during the 15m session
if in_session
    if na(orb_high) or high > orb_high
        orb_high := high
    if na(orb_low) or low < orb_low
        orb_low := low
    orb_mid := (orb_high + orb_low) / 2
 
// --- Logic: Supply & Demand (Inside Range) ---
// Simple logic: Identify aggressive moves or unmitigated wicks within the 15m window
var box sd_zone = na
if in_session and show_sd
    // Logic: If candle is bullish, potential demand at the bottom; if bearish, supply at top
    if close > open
        sd_zone := box.new(bar_index, high, bar_index, low, bgcolor = sd_color, border_color = na)
    else
        sd_zone := box.new(bar_index, high, bar_index, low, bgcolor = sd_color, border_color = na)
    box.delete(sd_zone[1]) // Keep only the most recent within the window
 
// --- Plotting the Range ---
plot(orb_high, "ORB High", color = range_col, style = plot.style_stepline, linewidth = 2)
plot(orb_low,  "ORB Low",  color = range_col, style = plot.style_stepline, linewidth = 2)
plot(orb_mid,  "ORB Mid",  color = mid_col,   style = plot.style_linebr,   linewidth = 1)
 
// --- Breakout Detection (5m timeframe recommended) ---
// Only trigger after the session has ended
session_ended = not in_session and not na(orb_high)
bull_break = session_ended and close > orb_high and close[1] <= orb_high
bear_break = session_ended and close < orb_low  and close[1] >= orb_low
 
// Color Bars
barcolor(bull_break ? up_color : bear_break ? down_color : na)
 
// --- Alerts ---
if bull_break
    alert("ORB Bullish Breakout: " + str.tostring(close), alert.freq_once_per_bar)
if bear_break
    alert("ORB Bearish Breakout: " + str.tostring(close), alert.freq_once_per_bar)
 
// --- Visual Cues ---
plotshape(bull_break, "Bull Break Label", shape.triangleup, location.belowbar, up_color, size = size.small)
plotshape(bear_break, "Bear Break Label", shape.triangledown, location.abovebar, down_color, size = size.small)

← 返回列表