本页源码来自 TradingView 公开发布的开源脚本,版权归原作者所有, 请遵循其原始许可(Pine 脚本常见 CC BY-NC-SA / MPL-2.0 / MIT)。 本项目仅用于研究检索与许可范围内的移植。
// ╔══════════════════════════════════════════════════════════════════════════════╗
// ║ ENHANCED VOLUME — CHART SYMBOL (EnVol) ║
// ╠══════════════════════════════════════════════════════════════════════════════╣
// ║ PURPOSE ║
// ║ Volume histogram for the chart symbol's own volume. Classifies each bar ║
// ║ into one of eight tiers based on institutional-grade signal logic. ║
// ║ ║
// ║ SIGNAL PRIORITY (highest wins when multiple fire on same bar) ║
// ║ 1 PPV Up Up close + vol > max recent down-day vol (strongest) ║
// ║ 2 PPV Down Down close + vol > max recent up-day vol (strongest) ║
// ║ 3 Spike Up Vol % of MA > threshold + up close ║
// ║ 4 Spike Down Vol % of MA > threshold + down close ║
// ║ 5 Dry Volume Vol < dry threshold × MA (low participation) ║
// ║ 6 Hi-Vol Up Vol > MA + up close (above average, below spike) ║
// ║ 7 Hi-Vol Down Vol > MA + down close (above average, below spike) ║
// ║ 8 Neutral Quiet gray — below average, no other signal ║
// ╚══════════════════════════════════════════════════════════════════════════════╝
//@version=6
indicator(
"Enhanced Volume",
shorttitle = "EnVol",
format = format.volume,
overlay = false)
// ══════════════════════════════════════════════════════════════════════════════
// SECTION A — INPUT GROUP LABELS
// Rendered as collapsible headers in the TradingView Settings panel.
// ══════════════════════════════════════════════════════════════════════════════
var string GRP_BASELINE = "⚙️ 1 · Volume Baseline"
var string GRP_PPV = "🔵 2 · Pocket Pivot Volume (PPV)"
var string GRP_SPIKE = "⚡ 3 · Volume Spike"
var string GRP_DRY = "🌵 4 · Dry / Low Volume"
var string GRP_COLS = "🎨 5 · Bar Colors"
// ══════════════════════════════════════════════════════════════════════════════
// SECTION B — INPUTS
// ══════════════════════════════════════════════════════════════════════════════
// ── 1 · Volume Baseline ───────────────────────────────────────────────────────
maLength = input.int(
20, "MA Length",
minval = 1,
maxval = 500,
group = GRP_BASELINE,
tooltip = "Period for the Simple Moving Average of volume.\n"
+ "All spike, PPV, and dry thresholds are relative to this average.\n\n"
+ " 22 — default (≈ 1 trading month on daily)\n"
+ " 10 — faster response, better for intraday\n"
+ " 50 — smoother, slower to adapt")
showVolMA = input.bool(
true, "Show Volume MA Line",
group = GRP_BASELINE,
tooltip = "Display the rolling MA as a reference line on the histogram.")
// ── 2 · Pocket Pivot Volume ───────────────────────────────────────────────────
ppvLookback = input.int(
10, "PPV Lookback (bars)",
minval = 2,
maxval = 50,
group = GRP_PPV,
tooltip = "Prior bars scanned for the highest opposing-day volume.\n\n"
+ " 10 — default (≈ 2 trading weeks on daily)\n"
+ " 20 — wider context, fewer but higher-conviction signals")
// ── 3 · Volume Spike ──────────────────────────────────────────────────────────
spikeThreshPct = input.int(
100, "Spike Threshold (% of MA)",
minval = 100,
maxval = 1000,
group = GRP_SPIKE,
tooltip = "Volume must exceed this % of the MA to qualify as a spike.\n\n"
+ " 200 = 2.0× average (default)\n"
+ " 150 = 1.5× average (more signals)\n"
+ " 300 = 3.0× average (rare events only)")
// ── 4 · Dry / Low Volume ──────────────────────────────────────────────────────
dryVolThreshMult = input.float(
0.3, "Dry Volume Threshold (× MA)",
minval = 0.01,
maxval = 0.99,
step = 0.05,
group = GRP_DRY,
tooltip = "Bars with volume below (MA × this value) are highlighted as dry.\n\n"
+ " 0.3 = vol < 30% of average (default)\n"
+ " 0.5 = vol < 50% of average (catches more bars)")
// ── 5 · Bar Colors — all tiers user-configurable ──────────────────────────────
colPPVUp = input.color(color.new(color.teal, 0), "PPV Up", group = GRP_COLS,
tooltip = "Up close + vol beats max recent down-day vol.")
colPPVDown = input.color(color.new(color.maroon, 0), "PPV Down", group = GRP_COLS,
tooltip = "Down close + vol beats max recent up-day vol.")
colSpikeUp = input.color(color.new(color.green, 25), "Spike Up", group = GRP_COLS,
tooltip = "Vol % of MA > spike threshold on an up close.")
colSpikeDown = input.color(color.new(color.red, 25), "Spike Down", group = GRP_COLS,
tooltip = "Vol % of MA > spike threshold on a down close.")
colDryVol = input.color(color.new(color.orange, 0), "Dry Volume", group = GRP_COLS,
tooltip = "Volume below the dry threshold — low participation bar.")
colHiVolUp = input.color(color.new(color.green, 60), "Hi-Vol Up", group = GRP_COLS,
tooltip = "Vol > MA on an up close — above average, below spike level.")
colHiVolDown = input.color(color.new(color.red, 60), "Hi-Vol Down", group = GRP_COLS,
tooltip = "Vol > MA on a down close — above average, below spike level.")
colNeutral = input.color(color.new(color.gray, 70), "Neutral", group = GRP_COLS,
tooltip = "Below-average volume with no other active signal.")
colMALine = input.color(color.new(color.orange, 40), "MA Line", group = GRP_COLS,
tooltip = "Color of the volume MA reference line.")
// ══════════════════════════════════════════════════════════════════════════════
// SECTION C — VOLUME BASELINE
//
// baselineReady: prevents division errors and false signals during the first
// maLength bars before the SMA has warmed up with enough data.
// volPctOfMA: volume expressed as % of average (200 = 2× average).
// ══════════════════════════════════════════════════════════════════════════════
volMA = ta.ema(volume, maLength)
baselineReady = not na(volMA) and volMA > 0
volPctOfMA = baselineReady ? (volume / volMA) * 100 : na
// ══════════════════════════════════════════════════════════════════════════════
// SECTION D — PRICE DIRECTION
//
// Session-to-session close comparison — correct for PPV day classification.
// Computed once and reused across all five signal sections below.
// ══════════════════════════════════════════════════════════════════════════════
barClosedUp = not na(close[1]) and close > close[1]
barClosedDown = not na(close[1]) and close < close[1]
// ══════════════════════════════════════════════════════════════════════════════
// SECTION E — SIGNAL: VOLUME SPIKE
//
// Shared volIsSpike flag evaluated once — avoids repeating the threshold
// expression for both up and down variants.
// ══════════════════════════════════════════════════════════════════════════════
volIsSpike = baselineReady and volPctOfMA > spikeThreshPct
isSpikeUp = volIsSpike and barClosedUp
isSpikeDown = volIsSpike and barClosedDown
// ══════════════════════════════════════════════════════════════════════════════
// SECTION F — SIGNAL: POCKET PIVOT VOLUME (PPV)
//
// PPV Up : today closed up AND today vol > highest down-day vol in window
// PPV Down: today closed down AND today vol > highest up-day vol in window
//
// Arrays rebuild fresh each bar (no var, no barstate.isconfirmed gate) —
// real-time updates on every tick during live bar formation.
//
// DOWN-DAY RULE: close[i] < close[i-1] (bar[i] lower than the next bar)
// ══════════════════════════════════════════════════════════════════════════════
// ── PPV Up: collect down-day volumes ─────────────────────────────────────────
downDayVols = array.new_float(0)
for i = 1 to ppvLookback
if not na(close[i]) and not na(close[i - 1])
and close[i] < close[i - 1]
array.push(downDayVols, volume[i])
maxDownDayVol = array.size(downDayVols) > 0 ? array.max(downDayVols) : na
isPPVUp = barClosedUp and not na(maxDownDayVol) and volume > maxDownDayVol
// ── PPV Down: collect up-day volumes ──────────────────────────────────────────
upDayVols = array.new_float(0)
for i = 1 to ppvLookback
if not na(close[i]) and not na(close[i - 1])
and close[i] > close[i - 1]
array.push(upDayVols, volume[i])
maxUpDayVol = array.size(upDayVols) > 0 ? array.max(upDayVols) : na
isPPVDown = barClosedDown and not na(maxUpDayVol) and volume > maxUpDayVol
// ══════════════════════════════════════════════════════════════════════════════
// SECTION G — SIGNAL: DRY VOLUME
//
// Bars where volume is unusually low — a sign of disinterest or pause.
// Uses baselineReady guard so it doesn't fire on warm-up bars.
// ══════════════════════════════════════════════════════════════════════════════
isDryVol = baselineReady and volume < volMA * dryVolThreshMult
// ══════════════════════════════════════════════════════════════════════════════
// SECTION H — BAR COLOR RESOLUTION
//
// First matching tier wins — lower tiers silently suppressed on that bar.
//
// ┌──────┬────────────┬───────────────────────────────────────────────────┐
// │ Tier │ Signal │ Condition │
// ├──────┼────────────┼───────────────────────────────────────────────────┤
// │ 1 │ PPV Up │ up close + vol > max down-day vol in window │
// │ 2 │ PPV Down │ down close + vol > max up-day vol in window │
// │ 3 │ Spike Up │ volPctOfMA > threshold + up close │
// │ 4 │ Spike Down │ volPctOfMA > threshold + down close │
// │ 5 │ Dry Volume │ vol < dryVolThreshMult × MA │
// │ 6 │ Hi-Vol Up │ vol > MA + up close (below spike level) │
// │ 7 │ Hi-Vol Down│ vol > MA + down close (below spike level) │
// │ 8 │ Neutral │ everything else — below average, no signal │
// └──────┴────────────┴───────────────────────────────────────────────────┘
// ══════════════════════════════════════════════════════════════════════════════
resolvedBarColor =
isPPVUp ? colPPVUp :
isPPVDown ? colPPVDown :
isSpikeUp ? colSpikeUp :
isSpikeDown ? colSpikeDown :
isDryVol ? colDryVol :
barClosedUp and volume > volMA ? colHiVolUp :
barClosedDown and volume > volMA ? colHiVolDown :
colNeutral
// ══════════════════════════════════════════════════════════════════════════════
// SECTION I — OUTPUT
// ══════════════════════════════════════════════════════════════════════════════
plot(
volume,
title = "Vol",
style = plot.style_columns,
color = resolvedBarColor)
plot(
showVolMA ? volMA : na,
title = "Vol MA",
color = colMALine,
linewidth = 2)