PumpC Opening Range Breakout (ORB) Multi Range

PumpCTrader · study · 333 行 · 点赞 217 · TradingView 原页

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

Pine Script

//@version=5
indicator('PumpC Opening Range Breakout (ORB) 5min Range', shorttitle='PumpC 5min ORB', overlay=true)
 
 
// === ⏱️ 1. Mode Selection ===
var GROUP_MODE = "1. Mode Selection"
plotMode       = input.string("Futures", title="Show ORB for", options=["Futures", "Stocks"], group=GROUP_MODE)
isFutures      = plotMode == "Futures"
isStocks       = plotMode == "Stocks"
 
// === 📋 2. ORB Controls ===
var GROUP_CONTROLS = "2. ORB Controls"
daily              = "On"
custom_timeframe   = "D"
showOne            = input.bool(false, title="Delete Historic Extension Levels", group=GROUP_CONTROLS)
showLabels         = input.bool(true, title="Show Labels", group=GROUP_CONTROLS)
labelPosition      = input.string("Start", title="Label Position", options=["Start", "End"], group=GROUP_CONTROLS)
Orb_Line_Width     = input.int(2, title="ORB Line Width", minval=1, group=GROUP_CONTROLS)
Levels_Line_Width  = input.int(1, title="Levels Line Width", minval=1, group=GROUP_CONTROLS)
 
// === 📊 3. Stretch Levels ===
var GROUP_LEVELS = "3. ORB Levels"
color_ORB_Open     = input.color(color.green, title="ORB Open", inline="orbopen", group=GROUP_LEVELS)
 
show_level_1       = input.bool(true, title="ORB Range", inline="lvl1", group=GROUP_LEVELS)
color_level_1_plus = input.color(color.black, title="+ORB", inline="lvl1", group=GROUP_LEVELS)
color_level_1_minus= input.color(color.black, title="-ORB", inline="lvl1", group=GROUP_LEVELS)
 
show_level_2       = input.bool(true, title="Level 2", inline="lvl2", group=GROUP_LEVELS)
mult_level_2       = 0.5  // Fixed multiplier for Level 2
color_level_2_plus = input.color(color.red, title="0.5", inline="lvl2", group=GROUP_LEVELS)
 
show_level_3       = input.bool(true, title="Level 3", inline="lvl3", group=GROUP_LEVELS)
mult_level_3       = input.float(2, title="", step=0.01, inline="lvl3", group=GROUP_LEVELS)
color_level_3_plus = input.color(color.gray, title="+", inline="lvl3", group=GROUP_LEVELS)
color_level_3_minus= input.color(color.gray, title="-", inline="lvl3", group=GROUP_LEVELS)
 
// === 🧱 4. Box Overlay ===
var GROUP_BOX = "5. ORB Box Overlay"
showBox        = input.bool(true,  "Enable ORB Box", group=GROUP_BOX)
boxColor       = input.color(color.new(color.black, 95), "ORB Box Color", group=GROUP_BOX)
showBoxHistory = input.bool(false, "Show Historical ORB Boxes", group=GROUP_BOX)
 
// === 📐 5. ATR Table Display ===
var GROUP_TABLE = "4. ATR Table"
bg_col         = input.color(color.rgb(221, 212, 204), title="Table Background", group=GROUP_TABLE)
font_col       = input.color(color.black, title="Font Color", group=GROUP_TABLE)
show_empty_row = input.bool(true, title="Add Padding Row", group=GROUP_TABLE, tooltip="Prevents overlap with corner pane icons")
orbATRLength   = input.int(10, title="ORB ATR Length", minval=1, group=GROUP_TABLE)
showORBATR     = input.bool(true, title="Show ATR in Table", group=GROUP_TABLE)
 
// === 🔁 Miscellaneous Constants ===
color CLEAR    = color.rgb(0, 0, 0, 100)
_offset        = 1  // Reserved / unused
 
// === 🔧 Internal Time & Utility Variables ===
t = time(custom_timeframe)
TRANSPARENT = color.new(color.white, 100)
 
isNewbar = not na(t) and (na(t[1]) or t > t[1])
 
 
tfInMinutes(simple string tf = "") =>
    float chartTf =
      timeframe.multiplier * (
      timeframe.isseconds ? 1. / 60             :
      timeframe.isminutes ? 1.                  :
      timeframe.isdaily   ? 60. * 24            :
      timeframe.isweekly  ? 60. * 24 * 7        :
      timeframe.ismonthly ? 60. * 24 * 30.4375  : na)
    float result = tf == "" ? chartTf : request.security(syminfo.tickerid, tf, chartTf)
 
inTimeframe(_t) => tfInMinutes(_t) > tfInMinutes(timeframe.period)
 
GetPipSize() =>
    syminfo.mintick * (syminfo.type == "forex" ? 10 : 1)
 
 
reso(exp, res) =>
    request.security(syminfo.tickerid, res, exp, lookahead=barmerge.lookahead_on)
 
getData(_t, _var) =>
    o = reso(open, _t)
    h = reso(high, _t)
    l = reso(low, _t)
    c = reso(close, _t)
    show = _var != "Off" and inTimeframe(_t)
    show_candle = show and str.contains(_var, "Candle")
    _time = time(_t)
    newbar = na(_time[1]) or _time > _time[1]
    hl = _var == 'HL' or _var == 'OHLC' or _var == 'OHLC + Candle'
    oc = _var == 'OC' or _var == 'OHLC' or _var == 'OHLC + Candle'
    [o, h, l, c, show, show_candle, newbar, hl, oc]
 
labelPos(_tf) =>
    labelPosition == "End" ? time_close(_tf) : time
 
// === 📌 Daily Line/Label Variables ===
var line d_o_line = na
var line d_o1_line = na
var line d_o2_line = na
var line d_m1p_line = na
var line d_m1m_line = na
var line d_m2p_line = na
var line d_m2m_line = na
var line d_m3p_line = na
var line d_m3m_line = na
 
var label d_o_label = na
var label d_o1_label = na
var label d_o2_label = na
var label d_m1p_label = na
var label d_m1m_label = na
var label d_m2p_label = na
var label d_m2m_label = na
var label d_m3p_label = na
var label d_m3m_label = na
 
[d_o, d_h, d_l, d_c, d_show, d_show_candle, d_newbar, d_hl, d_oc] = getData("D", daily)
 
// === 🕰️ ORB Range Functions (8:30 - 8:35 ET) ===
getORB830Range() =>
    orbHour = isFutures ? 8 : 9
    sess_start = timestamp("America/New_York", year, month, dayofmonth, orbHour, 30)
    sess_end   = timestamp("America/New_York", year, month, dayofmonth, orbHour, 35)
    in_window  = (time >= sess_start and time < sess_end)
    var float orbHigh = na
    var float orbLow  = na
    if (in_window and not na(high))
        orbHigh := na(orbHigh) ? high : math.max(orbHigh, high)
        orbLow  := na(orbLow)  ? low  : math.min(orbLow,  low)
    if (not in_window)
        orbHigh := na
        orbLow := na
    [orbHigh, orbLow]
 
// === ⌛ ORB Range Values from 5-min Chart ===
[orbHighRaw, orbLowRaw] = request.security(syminfo.tickerid, "5", getORB830Range(), lookahead=barmerge.lookahead_on)
 
// === ⏰ ORB Opening Timestamp (8:30 ET Candle) ===
get830Time() =>
    is830 = (hour == (isFutures ? 8 : 9) and minute == 30)
    is830 ? time : na
 
orbTimeRaw = request.security(syminfo.tickerid, "5", get830Time(), barmerge.gaps_off)
var int ORB_Time = na
if not na(orbTimeRaw)
    ORB_Time := orbTimeRaw
 
// === 📅 Session End Timestamp (4:00 PM ET) ===
getSessionEndTime() =>
    timestamp("America/New_York", year, month, dayofmonth, 16, 0)
 
sessionEndRaw = request.security(syminfo.tickerid, "5", getSessionEndTime(), barmerge.gaps_off)
var int Session_EndTime = na
if not na(sessionEndRaw)
    Session_EndTime := sessionEndRaw
 
// === 📦 8:30 Candle OHLC Extract ===
get830CandleFullValues() =>
    is830Candle = (hour == (isFutures ? 8 : 9) and minute == 30)
    o = is830Candle ? open : na
    h = is830Candle ? high : na
    l = is830Candle ? low  : na
    v = is830Candle ? volume : na
    [o, h, l, v]
 
// === 📥 Retrieve 8:30 OHLCV Values from 5-Min ===
[o830, h830, l830, v830] = request.security(syminfo.tickerid, "5", get830CandleFullValues(), barmerge.gaps_off)
 
// === 🗃️ ORB Value Trackers ===
var float ORB_Open  = na
var float ORB_High  = na
var float ORB_Low   = na
var box   orbBox    = na
 
if not na(o830)
    ORB_Open := o830
if not na(h830)
    ORB_High := h830
if not na(l830)
    ORB_Low  := l830
 
// === 📐 ORB Range Calculation ===
ORB_Range = ORB_High - ORB_Low
 
// === 🧠 Rolling ORB ATR & Volume History ===
var float   ORB_ATR         = na
var float[] orbRangeArray   = array.new_float()
var float   ORB_Volume      = na
var float   ORB_Volume_ATR  = na
var float[] orbVolumeArray  = array.new_float()
 
// === 🕒 End of ORB Detection (8:35 Candle Close) ===
is835CandleClose = (hour == (isFutures ? 8 : 9) and minute == 35)
justClosedORB = is835CandleClose and not na(ORB_Range) and not na(close[1])
 
if justClosedORB
    array.unshift(orbRangeArray, ORB_Range)
    array.unshift(orbVolumeArray, v830[1])
 
    if array.size(orbRangeArray) > orbATRLength
        array.pop(orbRangeArray)
    if array.size(orbVolumeArray) > orbATRLength
        array.pop(orbVolumeArray)
 
    // ⛓️ Calculate ORB ATR
    total = 0.0
    for i = 0 to array.size(orbRangeArray) - 1
        total += array.get(orbRangeArray, i)
    ORB_ATR := array.size(orbRangeArray) > 0 ? total / array.size(orbRangeArray) : na
 
    // 🔄 Calculate ORB Volume ATR
    volTotal = 0.0
    for i = 0 to array.size(orbVolumeArray) - 1
        volTotal += array.get(orbVolumeArray, i)
    ORB_Volume_ATR := array.size(orbVolumeArray) > 0 ? volTotal / array.size(orbVolumeArray) : na
 
    // 🎯 Capture Today’s ORB Volume
    ORB_Volume := v830[1]
 
 
// === 📦 Draw ORB Box ===
if justClosedORB and showBox
    if not showBoxHistory
        box.delete(orbBox)
 
    orbBox := box.new(left=ORB_Time, right=Session_EndTime, top=ORB_High, bottom=ORB_Low, xloc=xloc.bar_time, bgcolor=boxColor, border_color=boxColor)
 
// === 📐 Calculate Extension Levels ===
Level_two_plus  = ORB_Low + (ORB_Range * mult_level_2)
Level_two_minus = ORB_High - (ORB_Range * mult_level_2)
Level_three_plus = ORB_Low + (ORB_Range * mult_level_3)
Level_three_minus = ORB_High - (ORB_Range * mult_level_3)
 
// === 📈 Draw ORB + Levels Lines & Labels ===
if justClosedORB and d_show
    if showOne
        // Clean up previous lines
        line.delete(d_m1p_line)
        line.delete(d_m1m_line)
        line.delete(d_m2p_line)
        line.delete(d_m2m_line)
        line.delete(d_m3p_line)
        line.delete(d_m3m_line)
 
        // Clean up previous labels
        label.delete(d_m1p_label)
        label.delete(d_m1m_label)
        label.delete(d_m2p_label)
        label.delete(d_m2m_label)
        label.delete(d_m3p_label)
        label.delete(d_m3m_label)
 
    // ORB Open Line
    d_o_line := line.new(x1=ORB_Time, y1=ORB_Open, x2=Session_EndTime, y2=ORB_Open, xloc=xloc.bar_time, style=line.style_solid, color=color_ORB_Open)
 
    // ORB Range Lines
    if show_level_1
        d_o1_line := line.new(x1=ORB_Time, y1=ORB_High, x2=Session_EndTime, y2=ORB_High, xloc=xloc.bar_time, style=line.style_solid, color=color_level_1_plus, width=Orb_Line_Width)
        d_o2_line := line.new(x1=ORB_Time, y1=ORB_Low, x2=Session_EndTime, y2=ORB_Low, xloc=xloc.bar_time, style=line.style_solid, color=color_level_1_minus, width=Orb_Line_Width)
 
    // Extension Levels
    if show_level_2
        d_m2p_line := line.new(x1=ORB_Time, y1=Level_two_plus, x2=Session_EndTime, y2=Level_two_plus, xloc=xloc.bar_time, style=line.style_solid, color=color_level_2_plus, width=Levels_Line_Width)
 
    if show_level_3
        d_m3p_line := line.new(x1=ORB_Time, y1=Level_three_plus, x2=Session_EndTime, y2=Level_three_plus, xloc=xloc.bar_time, style=line.style_solid, color=color_level_3_plus, width=Levels_Line_Width)
        d_m3m_line := line.new(x1=ORB_Time, y1=Level_three_minus, x2=Session_EndTime, y2=Level_three_minus, xloc=xloc.bar_time, style=line.style_solid, color=color_level_3_minus, width=Levels_Line_Width)
 
    // Labels for ORB & Extensions
    if showLabels and show_level_1
        d_o1_label := label.new(x=labelPos("D"), y=ORB_High, xloc=xloc.bar_time, text="+OR [" + str.tostring(math.round(ORB_High, 2)) + "]", textcolor=color_level_1_plus, style=label.style_none, size=size.small)
        d_o2_label := label.new(x=labelPos("D"), y=ORB_Low, xloc=xloc.bar_time, text="-OR [" + str.tostring(math.round(ORB_Low, 2)) + "]", textcolor=color_level_1_minus, style=label.style_none, size=size.small)
 
    if showLabels and show_level_2
        d_m2p_label := label.new(x=labelPos("D"), y=Level_two_plus, xloc=xloc.bar_time, text="+" + str.tostring(mult_level_2) + " [" + str.tostring(math.round(Level_two_plus, 2)) + "]", textcolor=color_level_2_plus, style=label.style_none, size=size.small)
 
    if showLabels and show_level_3
        d_m3p_label := label.new(x=labelPos("D"), y=Level_three_plus, xloc=xloc.bar_time, text="+" + str.tostring(mult_level_3) + " [" + str.tostring(math.round(Level_three_plus, 2)) + "]", textcolor=color_level_3_plus, style=label.style_none, size=size.small)
        d_m3m_label := label.new(x=labelPos("D"), y=Level_three_minus, xloc=xloc.bar_time, text="-" + str.tostring(mult_level_3) + " [" + str.tostring(math.round(Level_three_minus, 2)) + "]", textcolor=color_level_3_minus, style=label.style_none, size=size.small)
 
// === 🔔 ORB Breakout Confirmed by Close ===
alertcondition(close > ORB_High,  title="🔔 ORB Breakout: Close Above High", message="{{ticker}} {{interval}} ➔ Price closed ABOVE ORB High.")
 
alertcondition(close < ORB_Low, title="🔔 ORB Breakdown: Close Below Low", message="{{ticker}} {{interval}} ➔ Price closed BELOW ORB Low.")
 
// === 🔔 ORB Fallout (Wick Break but Close Back Inside ORB) ===
alertcondition(high > ORB_High and close <= ORB_High, title= "⚠️ ORB Fallout: Wick Above High", message="{{ticker}} {{interval}} ➔ Wick broke ORB High but closed BACK inside.")
 
alertcondition(low < ORB_Low and close >= ORB_Low, title= "⚠️ ORB Fallout: Wick Below Low", message="{{ticker}} {{interval}} ➔ Wick broke ORB Low but closed BACK inside.")
 
// === 🎨 Highlight ORB Bar Background ===
is830Bar = time == ORB_Time
bgcolor(is830Bar and ORB_Range > ORB_ATR ? color.new(color.blue, 80) : is830Bar and ORB_Range < ORB_ATR ? color.new(color.orange, 80) : na)
 
// === 🔹 Format Volume K/M ===
formatVolume(vol) =>
    vol >= 1e6 ? str.tostring(vol / 1e6, "#.##") + "M" : vol >= 1e3 ? str.tostring(vol / 1e3, "#.#") + "K" : str.tostring(vol)
 
// === 📊 ORB Metrics Table ===
var table orb_t = table.new(position.top_right, 3, 19, bgcolor=bg_col)
 
if (barstate.islast)
    if (show_empty_row)
        table.cell(orb_t, 0, 0, "")  // Spacer row
 
    if (showORBATR)
        // ORB ATR
        valueStr = na(ORB_ATR) ? "…" : str.tostring(math.round(ORB_ATR, 2))
        table.cell(orb_t, 0, 3, "ORB ATR (" + str.tostring(orbATRLength) + ")", text_color=font_col, text_size=size.small)
        table.cell(orb_t, 1, 3, valueStr, text_color=font_col, text_size=size.small)
 
        // ORB ATR in Ticks
        atrTicks = na(ORB_ATR) ? na : math.round(ORB_ATR / syminfo.mintick)
        ticksStr = na(atrTicks) ? "…" : str.tostring(atrTicks)
        table.cell(orb_t, 0, 4, "ORB ATR (Ticks)", text_color=font_col, text_size=size.small)
        table.cell(orb_t, 1, 4, ticksStr, text_color=font_col, text_size=size.small)
 
        // Today ORB Range
        orbRangeStr = na(ORB_Range) ? "…" : str.tostring(math.round(ORB_Range, 2))
        table.cell(orb_t, 0, 5, "Today ORB Range", text_color=font_col, text_size=size.small)
        table.cell(orb_t, 1, 5, orbRangeStr, text_color=font_col, text_size=size.small)
 
        // ORB Volume ATR
        orbVolumeATRStr = na(ORB_Volume_ATR) ? "…" : formatVolume(ORB_Volume_ATR)
        table.cell(orb_t, 0, 6, "ORB Vol ATR (" + str.tostring(orbATRLength) + ")", text_color=font_col, text_size=size.small)
        table.cell(orb_t, 1, 6, orbVolumeATRStr, text_color=font_col, text_size=size.small)
 
        // Today ORB Volume
        orbVolumeTodayStr = na(ORB_Volume) ? "…" : formatVolume(ORB_Volume)
        table.cell(orb_t, 0, 7, "Today ORB Volume", text_color=font_col, text_size=size.small)
        table.cell(orb_t, 1, 7, orbVolumeTodayStr, text_color=font_col, text_size=size.small)

← 返回列表