Quantum Fox | Volume Bubbles v2.0

reticent67 · study · 98 行 · 点赞 31 · TradingView 原页

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

Pine Script

//@version=6
indicator("Quantum Fox | Volume Bubbles v2.0", shorttitle="QF Vol Bubbles", overlay=true, max_labels_count=500)
 
// Quantum Fox — Volume Bubbles v2.0
// Clean, confirmed-bar volume anomalies. One bubble per bar, no clusters or outcome markers.
// Footprint buy/sell volume is TradingView-classified, NOT native exchange aggressor flags.
// Intended for NQ/MNQ on a 1-second line chart; usable on other intraday timeframes.
 
// ── Detection ────────────────────────────────────────────────────────────────
gDetection = "1. Volume anomaly"
avgLen    = input.int(50, "Average volume lookback (bars)", minval=5, maxval=2000, group=gDetection)
mult      = input.float(2.0, "Volume multiplier", minval=0.1, step=0.1, group=gDetection)
minVolume = input.float(50, "Minimum total bar volume (contracts)", minval=0, step=1, group=gDetection)
minDomPct = input.float(0, "Minimum dominant-side share (%) — 0 disables", minval=0, maxval=100, step=5, group=gDetection, tooltip="Optional display/detection filter. 0 shows whichever footprint side has more volume; e.g. 60 requires at least 60% buy or sell volume. Bars without footprint data are skipped.")
ticksRow  = input.int(1, "Footprint row height (ticks)", minval=1, maxval=100, group=gDetection)
 
// ── Appearance ───────────────────────────────────────────────────────────────
gDisplay = "2. Bubble appearance"
showBuy   = input.bool(true, "Show buy bubbles", group=gDisplay, inline="sides")
showSell  = input.bool(true, "Show sell bubbles", group=gDisplay, inline="sides")
buyColor  = input.color(color.lime, "Buy color", group=gDisplay, inline="colors")
sellColor = input.color(color.red, "Sell color", group=gDisplay, inline="colors")
opacity   = input.int(50, "Bubble opacity (%)", minval=5, maxval=100, group=gDisplay)
buyText   = input.color(color.white, "Buy volume text", group=gDisplay, inline="texts")
sellText  = input.color(color.white, "Sell volume text", group=gDisplay, inline="texts")
showText  = input.bool(true, "Show volume inside bubbles", group=gDisplay)
sizeLook  = input.int(100, "Relative bubble-size lookback (bars)", minval=20, maxval=2000, group=gDisplay)
sizePreset = input.string("Balanced", "Bubble size preset", options=["Compact", "Balanced", "Large"], group=gDisplay)
locationMode = input.string("Dominant footprint row", "Bubble price placement", options=["Dominant footprint row", "Outside bar"], group=gDisplay)
offsetTicks = input.int(3, "Outside-bar offset (ticks)", minval=0, maxval=100, group=gDisplay)
 
// ── Data ─────────────────────────────────────────────────────────────────────
footprint fp = request.footprint(ticksRow)
bool hasFp = not na(fp)
float buyVol = hasFp ? fp.buy_volume() : na
float sellVol = hasFp ? fp.sell_volume() : na
float fpTotal = hasFp ? fp.total_volume() : na
float classified = nz(buyVol) + nz(sellVol)
float buyShare = classified > 0 ? 100.0 * buyVol / classified : na
float sellShare = classified > 0 ? 100.0 * sellVol / classified : na
bool isBuy = hasFp and classified > 0 and buyVol > sellVol
bool isSell = hasFp and classified > 0 and sellVol > buyVol
float dominantShare = isBuy ? buyShare : isSell ? sellShare : na
 
// Total-volume anomaly: compare against PRECEDING bars. No current-bar baseline contamination.
float baseline = ta.sma(volume, avgLen)[1]
bool exceptional = barstate.isconfirmed and hasFp and classified > 0 and not na(baseline) and baseline > 0 and volume >= minVolume and volume > baseline * mult
bool dominantEnough = minDomPct == 0 or (not na(dominantShare) and dominantShare >= minDomPct)
bool buySignal = exceptional and dominantEnough and isBuy and showBuy
bool sellSignal = exceptional and dominantEnough and isSell and showSell
 
// ── Bubble price ─────────────────────────────────────────────────────────────
// One row's midpoint is a PLACEMENT aid. The displayed volume is the entire bar's
// volume, not the volume at that row or a single print.
float dominantPrice = close
if hasFp and exceptional and locationMode == "Dominant footprint row"
    float bestSideVol = -1.0
    for row in fp.rows()
        float sideVol = isBuy ? row.buy_volume() : row.sell_volume()
        if sideVol > bestSideVol
            bestSideVol := sideVol
            dominantPrice := math.avg(row.up_price(), row.down_price())
float bubblePrice = locationMode == "Outside bar" ? (isBuy ? low - offsetTicks * syminfo.mintick : high + offsetTicks * syminfo.mintick) : dominantPrice
 
// ── Relative size ─────────────────────────────────────────────────────────────
// Scale within the recent bar-volume range. Not a volume percentile, not a signal filter.
// Larger volume cannot shrink the bubble because of the display preset.
float volMin = ta.lowest(volume, sizeLook)
float volMax = ta.highest(volume, sizeLook)
float relative = volMax > volMin ? math.max(0.0, math.min(1.0, (volume - volMin) / (volMax - volMin))) : 0.5
int tier = relative >= 0.90 ? 3 : relative >= 0.60 ? 2 : relative >= 0.30 ? 1 : 0
string sz = sizePreset == "Compact" ? (tier == 3 ? size.normal : tier == 2 ? size.small : size.tiny) : sizePreset == "Large" ? (tier == 3 ? size.huge : tier == 2 ? size.large : tier == 1 ? size.normal : size.small) : (tier == 3 ? size.large : tier == 2 ? size.normal : tier == 1 ? size.small : size.tiny)
 
// ── Draw only confirmed bubbles ──────────────────────────────────────────────
var array<label> bubbleLabels = array.new<label>()
bool draw = buySignal or sellSignal
if draw
    bool green = buySignal
    color bg = color.new(green ? buyColor : sellColor, 100 - opacity)
    color fg = green ? buyText : sellText
    string side = green ? "BUY" : "SELL"
    string textLabel = showText ? str.tostring(volume, format.volume) : ""
    string tip = side + " (dominant footprint side)" + "\nTotal bar volume: " + str.tostring(volume, format.volume) + "\nFootprint buy: " + str.tostring(buyVol, format.volume) + "\nFootprint sell: " + str.tostring(sellVol, format.volume) + "\nDominant share: " + str.tostring(dominantShare, "#.0") + "%" + "\nPrior-bar average: " + str.tostring(baseline, format.volume) + "\nVolume ratio: " + str.tostring(volume / baseline, "#.00") + "x" + "\nRelative size: " + str.tostring(relative, "#.00") + "\nNote: displayed bubble volume is TOTAL bar volume."
    label lb = label.new(bar_index, bubblePrice, text=textLabel, color=bg, textcolor=fg, style=label.style_circle, size=sz, tooltip=tip)
    array.push(bubbleLabels, lb)
    // Respect label limits without letting TradingView's automatic GC obscure the policy.
    if array.size(bubbleLabels) > 450
        label.delete(array.shift(bubbleLabels))
 
// ── Alerts and Data Window diagnostics ───────────────────────────────────────
alertcondition(buySignal, "Quantum Fox Volume Bubble BUY", "High-volume bar with footprint-buy dominance on {{ticker}} ({{interval}}). Total volume: {{volume}}")
alertcondition(sellSignal, "Quantum Fox Volume Bubble SELL", "High-volume bar with footprint-sell dominance on {{ticker}} ({{interval}}). Total volume: {{volume}}")
plot(baseline, "Previous-bar volume average", display=display.data_window)
plot(fpTotal, "Footprint total", display=display.data_window)
plot(buyVol, "Footprint buy volume", display=display.data_window)
plot(sellVol, "Footprint sell volume", display=display.data_window)
plot(dominantShare, "Dominant side percent", display=display.data_window)
plot(relative, "Relative bubble size (0–1)", display=display.data_window)

← 返回列表