Saturnian Volume Anomalies [Pane]

VORSwingTrading · study · 199 行 · 点赞 12 · TradingView 原页

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

Pine Script

//@version=6
indicator("Saturnian Volume Anomalies [Pane]", overlay=false, format=format.volume, max_labels_count=500)
 
// =============================================================================
// 1. INPUT CONFIGURATION
// =============================================================================
grp_tf      = "Timeframe Settings"
useHtf      = input.bool(false, "Use Higher Timeframe?", group=grp_tf)
htfRes      = input.timeframe("240", "HTF Resolution", group=grp_tf)
htfMode     = input.string("HTF Aggregate Blocks", "HTF Volume Bar Height", options=["HTF Aggregate Blocks", "LTF Bar Heights"], group=grp_tf)
 
grp_vol     = "Volume Anomaly Thresholds (Synced to Main Engine)"
volMaType   = input.string("SMA", "Volume MA Type", options=["SMA", "RMA (Wilder's)"], group=grp_vol)
smaLen      = input.int(15, "Volume MA Length (15 = Synced to Main Engine)", minval=1, group=grp_vol)
atrLen      = input.int(15, "ATR Length (15 = Synced to Main Engine)", minval=1, group=grp_vol)
normThresh  = input.float(0.8, "Normal Vol Minimum (Breakout Gate)", step=0.1, group=grp_vol)
lowThresh   = input.float(0.5, "Low Vol Maximum", step=0.1, group=grp_vol)
hThresh     = input.float(1.2, "High (H) Min", step=0.1, group=grp_vol)
vhThresh    = input.float(2.2, "Very High (VH) Min", step=0.1, group=grp_vol)
uhThresh    = input.float(3.2, "Ultra High (UH) Min", step=0.1, group=grp_vol)
 
grp_fp      = "TradingView Premium Footprint & VSA Absorption"
useFp       = input.bool(true, "Use Premium Footprint Delta for Absorption & HUD", group=grp_fp)
ticksPerRow = input.int(75, "Footprint Ticks Per Row", minval=10, group=grp_fp)
aggThresh   = input.float(15.0, "Aggressive Delta Ignition Threshold (%)", minval=5.0, maxval=50.0, step=1.0, group=grp_fp)
showAbsorb  = input.bool(true, "Flag High-RVOL Wick, Squat & Delta Absorption (◆)?", group=grp_fp)
wickPctMin  = input.float(0.45, "Min Rejection Wick Ratio (0.3 - 0.8)", minval=0.2, maxval=0.9, step=0.05, group=grp_fp)
squatAtrMax = input.float(0.55, "Max VSA Squat Spread (x ATR)", minval=0.2, maxval=1.0, step=0.05, group=grp_fp)
 
grp_vis     = "Reference Lines & AMOLED HUD"
showMaLine  = input.bool(true, "Show 1.0x Volume MA & 1.5x High-Vol Threshold Lines", group=grp_vis)
showHud     = input.bool(true, "Show Compact AMOLED RVOL & Order-Flow HUD?", group=grp_vis)
hudPosInput = input.string("Top Right", "HUD Position", options=["Top Right", "Bottom Right", "Top Left", "Bottom Left"], group=grp_vis)
 
grp_col     = "Institutional Palette (Synced to Main Engine)"
colorMode   = input.string("Match Main Anomaly Engine (Exact Unified)", "Volume Color Mode", options=["Match Main Anomaly Engine (Exact Unified)", "Split Bull/Bear Shades"], group=grp_col, tooltip="When set to 'Match Main Anomaly Engine (Exact Unified)', volume bars use the EXACT identical 4 colors as the main chart overlay: Fuchsia for UH (≥3.5x), Red for VH (≥2.5x), Orange for H (≥1.5x), and Aqua for Low (≤0.5x). Normal volume bars use neutral muted slate/gray so that red is never confused with a Very High anomaly.")
colUH       = input.color(color.fuchsia,             "Ultra High Anomaly (UH ≥ 3.5x)", group=grp_col)
colVH       = input.color(color.red,                 "Very High Anomaly (VH ≥ 2.5x)",  group=grp_col)
colH        = input.color(color.orange,              "High Anomaly (H ≥ 1.5x)",        group=grp_col)
colL        = input.color(color.aqua,                "Low Vol / Dry (< 0.5x)",         group=grp_col)
c_norm_bull = input.color(color.new(#4ade80, 50),    "Normal Bull (0.8x - 1.5x)",       group=grp_col)
c_norm_bear = input.color(color.new(#94a3b8, 50),    "Normal Bear (0.8x - 1.5x)",       group=grp_col)
c_sub       = input.color(color.new(color.gray, 65), "Sub-Normal Vol (0.5x - 0.8x)",   group=grp_col)
c_uh_bear   = input.color(color.rgb(186, 0, 255),    "UH Bear (Split Mode)",           group=grp_col)
c_vh_bear   = input.color(color.rgb(180, 20, 20),    "VH Bear (Split Mode)",           group=grp_col)
c_h_bear    = input.color(color.rgb(204, 102, 0),    "H Bear (Split Mode)",            group=grp_col)
 
// =============================================================================
// 2. HELPER FUNCTIONS & DATA EXTRACTION (PINE v6 WARNING-FREE)
// =============================================================================
f_get_hud_pos(string pos) =>
    pos == "Top Right" ? position.top_right : pos == "Top Left" ? position.top_left : pos == "Bottom Left" ? position.bottom_left : position.bottom_right
 
// Unconditional extraction eliminates CW10004
f_get_vol_ma(float src, int len, string mType) =>
    float s = ta.sma(src, len)
    float r = ta.rma(src, len)
    mType == "RMA (Wilder's)" ? r : s
 
f_get_vol_htf(int len, string mType, int aLen) =>
    float v   = volume
    float s   = ta.sma(v, len)
    float r   = ta.rma(v, len)
    float ma  = mType == "RMA (Wilder's)" ? r : s
    float rat = ma > 0 ? v / ma : 0.0
    float atr = ta.atr(aLen)
    [v[1], ma[1], rat[1], open[1], high[1], low[1], close[1], atr[1]]
 
int tfSec       = timeframe.in_seconds(timeframe.period)
int htfSec      = timeframe.in_seconds(htfRes)
bool isValidHtf = useHtf and htfSec > tfSec
 
float ltfVol = volume
float ltfMa  = f_get_vol_ma(ltfVol, smaLen, volMaType)
float ltfRat = ltfMa > 0 ? ltfVol / ltfMa : 0.0
float ltfAtr = ta.atr(atrLen)
 
[htfVol, htfMa, htfRat, htfO, htfH, htfL, htfC, htfAtr] = request.security(syminfo.tickerid, htfRes, f_get_vol_htf(smaLen, volMaType, atrLen), barmerge.gaps_off, lookahead=barmerge.lookahead_on)
 
// Footprint Delta Calculation (TradingView Premium)
footprint rawFp = request.footprint(ticksPerRow, 70, 300)
bool hasFp      = useFp and not isValidHtf and not na(rawFp)
 
float fpBuy      = hasFp ? footprint.buy_volume(rawFp)  : na
float fpSell     = hasFp ? footprint.sell_volume(rawFp) : na
float fpTot      = hasFp ? (fpBuy + fpSell)             : na
float fpDelta    = hasFp ? (fpBuy - fpSell)             : na
float fpDeltaPct = (hasFp and fpTot > 0) ? (fpDelta / fpTot) * 100.0 : na
 
float activeRat = isValidHtf ? nz(htfRat, ltfRat) : ltfRat
float activeMa  = (isValidHtf and htfMode == "HTF Aggregate Blocks") ? nz(htfMa, ltfMa)   : ltfMa
float plotVol   = (isValidHtf and htfMode == "HTF Aggregate Blocks") ? nz(htfVol, ltfVol) : ltfVol
 
float actO   = isValidHtf ? nz(htfO, open)    : open
float actH   = isValidHtf ? nz(htfH, high)    : high
float actL   = isValidHtf ? nz(htfL, low)     : low
float actC   = isValidHtf ? nz(htfC, close)   : close
float actAtr = isValidHtf ? nz(htfAtr, ltfAtr) : ltfAtr
 
bool isUh   = activeRat >= uhThresh
bool isVh   = not isUh and activeRat >= vhThresh
bool isH    = not isUh and not isVh and activeRat >= hThresh
bool isNorm = not isUh and not isVh and not isH and activeRat >= normThresh
bool isLow  = activeRat <= lowThresh
 
bool isBullBar = actC >= actO
bool useUnified = colorMode == "Match Main Anomaly Engine (Exact Unified)"
color uhCol = useUnified ? colUH : (isBullBar ? colUH : c_uh_bear)
color vhCol = useUnified ? colVH : (isBullBar ? colVH : c_vh_bear)
color hCol  = useUnified ? colH  : (isBullBar ? colH  : c_h_bear)
color normCol = isBullBar ? c_norm_bull : c_norm_bear
 
color barCol = isUh ? uhCol : isVh ? vhCol : isH ? hCol : isNorm ? normCol : isLow ? colL : c_sub
 
// =============================================================================
// 3. VSA ABSORPTION & VOLUME IGNITION MECHANICS
// =============================================================================
float actRng    = math.max(actH - actL, syminfo.mintick)
float upperWick = (actH - math.max(actO, actC)) / actRng
float lowerWick = (math.min(actO, actC) - actL) / actRng
float closePos  = (actC - actL) / actRng
 
bool isHighRvol = activeRat >= hThresh
float spreadRat = actAtr > 0 ? actRng / actAtr : 1.0
bool isSquat    = actRng > 0 and actAtr > 0 and spreadRat <= squatAtrMax
 
// Wick Absorption: Requires dominant rejection wick and confirmation
bool bullWickAbs = lowerWick >= wickPctMin and lowerWick > upperWick and closePos >= 0.45
bool bearWickAbs = upperWick >= wickPctMin and upperWick > lowerWick and closePos <= 0.55
 
// Squat Absorption: Effort vs. No Result
bool bullSquatAbs = isSquat and (closePos > 0.50 or (closePos == 0.50 and actC >= actO))
bool bearSquatAbs = isSquat and (closePos < 0.50 or (closePos == 0.50 and actC < actO))
 
// Footprint Delta Absorption: Aggressive market orders trapped into reverse candle
bool bullFpAbs = hasFp and fpDeltaPct <= -10.0 and actC > actO and closePos >= 0.50 and upperWick < 0.45
bool bearFpAbs = hasFp and fpDeltaPct >= 10.0  and actC < actO and closePos <= 0.50 and lowerWick < 0.45
 
bool rawBullAbs = showAbsorb and isHighRvol and (bullWickAbs or bullSquatAbs or bullFpAbs)
bool rawBearAbs = showAbsorb and isHighRvol and (bearWickAbs or bearSquatAbs or bearFpAbs)
 
// Strict mutual exclusion prevents simultaneous double-diamond collisions
bool bullAbsorb = rawBullAbs and (not rawBearAbs or closePos >= 0.50)
bool bearAbsorb = not bullAbsorb and rawBearAbs and (not rawBullAbs or closePos < 0.50)
 
// Volume Ignition: Breakout follow-through with aggressive volume & delta
bool isBullIgnition = isHighRvol and not isSquat and not bullAbsorb and not bearAbsorb and closePos >= 0.55 and (not hasFp or fpDeltaPct >= aggThresh)
bool isBearIgnition = isHighRvol and not isSquat and not bullAbsorb and not bearAbsorb and closePos <= 0.45 and (not hasFp or fpDeltaPct <= -aggThresh)
 
// =============================================================================
// 4. PLOTTING & AMOLED HUD
// =============================================================================
plot(plotVol, title="Volume Histogram", style=plot.style_columns, color=barCol)
plot(showMaLine ? activeMa : na, title="1.0x Volume MA", color=color.new(color.white, 35), linewidth=1)
plot(showMaLine ? activeMa * hThresh : na, title="1.5x High-Vol Threshold", color=color.new(color.orange, 30), linewidth=1, style=plot.style_circles)
 
// Restored: Diamonds float right above the volume bar (location.absolute at plotVol * 1.08)
plotshape(bullAbsorb ? plotVol * 1.08 : na, title="Bullish VSA/FP Absorption (Put Wall Hold)", style=shape.diamond, location=location.absolute, color=color.lime, size=size.tiny)
plotshape(bearAbsorb ? plotVol * 1.08 : na, title="Bearish VSA/FP Absorption (Call Wall Hold)", style=shape.diamond, location=location.absolute, color=color.fuchsia, size=size.tiny)
 
if showHud
    var table hud = table.new(f_get_hud_pos(hudPosInput), 2, 5, bgcolor=color.new(color.black, 12), border_color=color.rgb(48, 54, 61), border_width=1)
    if barstate.islast
        string tierTxt  = isUh ? "🔥 ULTRA HIGH (UH)" : isVh ? "⚡ VERY HIGH (VH)" : isH ? "🟢 HIGH VOL (H)" : isNorm ? "✔️ NORMAL (≥0.8x)" : isLow ? "❄️ LOW (<0.5x)" : "⚪ SUB-NORMAL"
        color tierCol   = isUh ? uhCol : isVh ? vhCol : isH ? hCol : isNorm ? color.silver : isLow ? colL : color.gray
        
        string vState   = bullAbsorb ? "🟢 BULL ABSORB (◆)" : bearAbsorb ? "🔴 BEAR ABSORB (◆)" : isBullIgnition ? "🚀 BULL IGNITION" : isBearIgnition ? "💥 BEAR IGNITION" : activeRat >= normThresh ? "✔️ BREAKOUT READY" : "⚠️ BLOCKED (<0.8x)"
        color vStateCol = (bullAbsorb or isBullIgnition) ? color.lime : (bearAbsorb or isBearIgnition) ? color.red : activeRat >= normThresh ? color.aqua : color.gray
        
        string fpTxt    = hasFp ? ((fpDeltaPct > 0 ? "+" : "") + str.tostring(fpDeltaPct, "#.#") + "% Delta") : isValidHtf ? ("HTF (" + htfRes + ") Confirmed") : "Standard OHLCV"
        color  fpCol    = hasFp ? (fpDeltaPct >= aggThresh ? color.lime : fpDeltaPct <= -aggThresh ? color.red : color.silver) : isValidHtf ? color.aqua : color.gray
        
        float sprAtrRat = actAtr > 0 ? actRng / actAtr : 0.0
        string sprTxt   = str.tostring(sprAtrRat, "#.##") + "x ATR" + (isSquat ? " (SQUAT)" : "")
        color  sprCol   = isSquat ? color.orange : sprAtrRat >= 1.0 ? color.aqua : color.silver
 
        string rvolLabel = isValidHtf ? "HTF (" + htfRes + ") RVOL" : "RVOL Multiple"
        string tierLabel = isValidHtf ? "HTF Anomaly Tier" : "Anomaly Tier"
 
        table.cell(hud, 0, 0, rvolLabel, text_color=color.gray, text_size=size.tiny)
        table.cell(hud, 1, 0, str.tostring(activeRat, "#.##") + "x MA", text_color=tierCol, text_size=size.tiny)
        table.cell(hud, 0, 1, tierLabel, text_color=color.gray, text_size=size.tiny)
        table.cell(hud, 1, 1, tierTxt, text_color=tierCol, text_size=size.tiny)
        table.cell(hud, 0, 2, "VSA / Engine Gate", text_color=color.gray, text_size=size.tiny)
        table.cell(hud, 1, 2, vState, text_color=vStateCol, text_size=size.tiny)
        table.cell(hud, 0, 3, "Spread vs ATR", text_color=color.gray, text_size=size.tiny)
        table.cell(hud, 1, 3, sprTxt, text_color=sprCol, text_size=size.tiny)
        table.cell(hud, 0, 4, "Footprint Flow", text_color=color.gray, text_size=size.tiny)
        table.cell(hud, 1, 4, fpTxt, text_color=fpCol, text_size=size.tiny)
 
// =============================================================================
// 5. NATIVE TRADINGVIEW ALERTS
// =============================================================================
alertcondition(bullAbsorb,     "Bullish VSA/FP Absorption", "Saturnian Vol Pane: High-RVOL Bullish Absorption (◆) Detected!")
alertcondition(bearAbsorb,     "Bearish VSA/FP Absorption", "Saturnian Vol Pane: High-RVOL Bearish Absorption (◆) Detected!")
alertcondition(isBullIgnition, "Bullish Volume Ignition",   "Saturnian Vol Pane: High-RVOL Bullish Breakout Ignition Detected!")
alertcondition(isBearIgnition, "Bearish Volume Ignition",   "Saturnian Vol Pane: High-RVOL Bearish Breakout Ignition Detected!")
alertcondition(isUh,           "Ultra High Volume (3.5x+)", "Saturnian Vol Pane: Ultra High Volume Anomaly (≥3.5x MA)!")
alertcondition(isLow,          "Low Volume (<0.5x)",        "Saturnian Vol Pane: Low Volume Anomaly (<0.5x MA)!")

← 返回列表