本页源码来自 TradingView 公开发布的开源脚本,版权归原作者所有, 请遵循其原始许可(Pine 脚本常见 CC BY-NC-SA / MPL-2.0 / MIT)。 本项目仅用于研究检索与许可范围内的移植。
//@version=6
indicator("VWAP Hunter - Clean", shorttitle="VWAP Hunt", overlay = true)
// Daily VWAP with independently tracked reclaim and pullback-bounce events.
// RECLAIM: a confirmed cross from at/below VWAP to above it.
// BOUNCE: previous close above VWAP, current low at/below the previous low,
// a touch of the VWAP tolerance zone, and a confirmed close above VWAP.
// A reclaim does not consume or delay the next qualifying bounce.
// Bounce repeats are suppressed until price clears the zone above it for the
// selected number of candles, closes at/below VWAP, or a new daily anchor starts.
// Bounce quality filters are optional and OFF by default; reclaims bypass them.
// Labels, scanner codes and alerts use the same confirmed Bounce/Reclaim events.
// Compact green BOUNCE and blue RECLAIM labels identify each displayed event.
// Optional gray CONTINUATION labels are hidden by default.
// A smooth 28-period EMA with soft price-to-line shading provides trend context.
// Green = close at/above the EMA; red = close below it. Default: update at close.
// The trend line uses chart OHLC and does not filter the VWAP setup signals.
// Label spacing affects only optional CONTINUATION labels, not BOUNCE/RECLAIM.
// Raw Continuation alerts can still repeat. To match displayed labels,
// choose "Clean chart signal" and Once Per Bar Close.
// Bounce and Reclaim always wait for candle close. Continuation has its own
// candle-close setting. No setup is plotted retrospectively on an earlier bar.
// Chart type/source semantics are unchanged: on Heikin Ashi, chart OHLC is
// synthetic. This cleanup does not convert signals or VWAP to actual OHLC.
// Use standard time-based candles (including hollow candles) for public signal
// publications. This indicator is not a tested strategy or a performance claim.
// Install this ONE script in a new Pine indicator and remove the old Hunter.
// Source/logic checks completed locally; TradingView compilation/rendering
// must still be verified. No RSI/volume pane or dashboard is added.
//────────────────────────────────────────────────────────────
// INPUTS
//────────────────────────────────────────────────────────────
groupVWAP = "VWAP Settings"
vwapSource = input.source(
hlc3,
"VWAP Source",
group = groupVWAP
)
touchTolerancePct = input.float(
0.30,
"VWAP Touch Tolerance (%)",
minval = 0.0,
step = 0.05,
group = groupVWAP
) / 100
groupSignals = "Signal Settings"
enableBounce = input.bool(
true,
"Enable VWAP Bounce",
group = groupSignals,
tooltip = "One confirmed pullback bounce per VWAP interaction. A preceding RECLAIM does not block it."
)
applyBounceFilters = input.bool(false, "Apply optional quality filters to BOUNCE", group = groupSignals, tooltip = "OFF: show qualifying price-based bounces regardless of candle color, volume, gain or liquidity. ON: also require the optional filters below. RECLAIM is unaffected.")
enableReclaim = input.bool(
true,
"Enable VWAP Reclaim",
group = groupSignals,
tooltip = "One RECLAIM for every confirmed cross from at/below VWAP to above it. Bounce/continuation filters and label spacing do not block reclaims."
)
enableContinuation = input.bool(
true,
"Enable Above-VWAP Continuation",
group = groupSignals
)
requireBullishCandle = input.bool(
true,
"Require bullish candle for filtered setups",
group = groupSignals
)
continuationNeedsHigherHigh = input.bool(
true,
"Continuation Must Make Higher High",
group = groupSignals
)
confirmedOnly = input.bool(
true,
"Wait for CONTINUATION candle close",
group = groupSignals,
tooltip = "BOUNCE and RECLAIM always wait for candle close, regardless of this setting."
)
cooldownBars = input.int(
0,
"Continuation Cooldown Bars",
minval = 0,
group = groupSignals
)
groupFilters = "Optional Bounce / Continuation Filters"
useVolumeFilter = input.bool(
true,
"Use Relative Volume Filter",
group = groupFilters
)
volumeLength = input.int(
20,
"Average Volume Length",
minval = 1,
group = groupFilters
)
minimumRelativeVolume = input.float(
1.00,
"Minimum Relative Volume",
minval = 0.0,
step = 0.05,
group = groupFilters
)
useGainFilter = input.bool(
false,
"Use Minimum Daily Gain Filter",
group = groupFilters
)
minimumDailyGain = input.float(
5.0,
"Minimum Gain Today (%)",
step = 0.5,
group = groupFilters
)
minimumPrice = input.float(
0.10,
"Minimum Stock Price",
minval = 0.0,
group = groupFilters
)
minimumDollarVolume = input.float(
100000,
"Minimum Intraday Dollar Volume",
minval = 0,
step = 10000,
group = groupFilters
)
groupDisplay = "Display"
showVWAP = input.bool(
true,
"Show VWAP",
group = groupDisplay
)
showBounceLabels = input.bool(
true,
"Show BOUNCE labels",
group = groupDisplay
)
showReclaimLabels = input.bool(
true,
"Show RECLAIM labels",
group = groupDisplay
)
showContinuationLabels = input.bool(
false,
"Show CONTINUATION labels (optional)",
group = groupDisplay
)
// Separate confirmed events need no shared cooldown.
markerSpacing = input.int(8, "Minimum bars between CONTINUATION labels", minval = 0, maxval = 100, group = groupDisplay, tooltip = "Applies only to optional CONTINUATION labels. BOUNCE and RECLAIM use independent event rules.")
episodeResetBars = input.int(1, "Candles clear above VWAP zone to reset BOUNCE", minval = 1, maxval = 20, group = groupDisplay, tooltip = "After a bounce, each reset candle must have its low above the upper edge of the VWAP touch zone. A close at/below VWAP also resets the bounce detector.")
vwapLineColor = input.color(color.blue, "VWAP color", group = groupDisplay)
showVWAPBands = input.bool(true, "Show upper/lower VWAP bands", group = groupDisplay)
vwapBandColor = input.color(color.rgb(40, 180, 100), "VWAP band color", group = groupDisplay)
vwapBandMultiplier = input.float(1.0, "VWAP band standard deviations", minval = 0.1, step = 0.25, group = groupVWAP)
groupTrend = "Trend Line & Shading"
showTrendLine = input.bool(true, "Show smooth red/green trend line", group = groupTrend)
trendLength = input.int(28, "EMA length", minval = 1, group = groupTrend, tooltip = "A longer EMA is smoother and slower. Green means the candle closes at or above the EMA; red means it closes below.")
trendCloseOnly = input.bool(true, "Update trend at candle close", group = groupTrend, tooltip = "Keeps the last closed candle's trend line and color while the current candle forms. Turning this off allows intrabar changes.")
trendLineWidth = input.int(3, "Trend line thickness", minval = 1, maxval = 4, group = groupTrend)
trendUpColor = input.color(color.lime, "Uptrend color", group = groupTrend)
trendDownColor = input.color(color.red, "Downtrend color", group = groupTrend)
showTrendShade = input.bool(true, "Show soft trend shading", group = groupTrend)
trendShadeTransparency = input.int(90, "Shading transparency", minval = 0, maxval = 100, group = groupTrend, tooltip = "90 gives a subtle shade. Lower values make it stronger; 100 hides it.")
//────────────────────────────────────────────────────────────
// DAILY VWAP
//────────────────────────────────────────────────────────────
newDay = timeframe.change("1D")
vwapValue = ta.vwap(
vwapSource,
newDay
)
// Bands use the same source and daily anchor as the original VWAP.
[bandVWAP, upperVWAPBand, lowerVWAPBand] = ta.vwap(vwapSource, newDay, vwapBandMultiplier)
//────────────────────────────────────────────────────────────
// DAILY PERCENTAGE GAIN
//────────────────────────────────────────────────────────────
previousDailyClose = request.security(
syminfo.tickerid,
"D",
close[1],
lookahead = barmerge.lookahead_on
)
dailyGainPct =
not na(previousDailyClose) and previousDailyClose != 0
? ((close - previousDailyClose) / previousDailyClose) * 100
: na
//────────────────────────────────────────────────────────────
// RELATIVE VOLUME
//────────────────────────────────────────────────────────────
averageVolume = ta.sma(
volume,
volumeLength
)
relativeVolume =
not na(averageVolume) and averageVolume > 0
? volume / averageVolume
: 0.0
//────────────────────────────────────────────────────────────
// INTRADAY DOLLAR VOLUME
//────────────────────────────────────────────────────────────
var float cumulativeDollarVolume = 0.0
if newDay
cumulativeDollarVolume := volume * close
else
cumulativeDollarVolume += volume * close
//────────────────────────────────────────────────────────────
// BOUNCE / CONTINUATION FILTERS
//────────────────────────────────────────────────────────────
bullishCandle = close > open
candleFilter =
not requireBullishCandle or bullishCandle
volumeFilter =
not useVolumeFilter or
relativeVolume >= minimumRelativeVolume
gainFilter =
not useGainFilter or
dailyGainPct >= minimumDailyGain
liquidityFilter =
close >= minimumPrice and
cumulativeDollarVolume >= minimumDollarVolume
confirmationFilter =
not confirmedOnly or
barstate.isconfirmed
allFilters =
candleFilter and
volumeFilter and
gainFilter and
liquidityFilter and
confirmationFilter
//────────────────────────────────────────────────────────────
// SETUP 1: VWAP PULLBACK AND BOUNCE
//────────────────────────────────────────────────────────────
// The previous candle was above VWAP.
wasAboveVWAP =
close[1] > vwapValue[1]
// The current candle touches VWAP or comes within tolerance.
touchZoneUpper = vwapValue * (1 + touchTolerancePct)
touchedVWAP =
low <= touchZoneUpper and
high >= vwapValue * (1 - touchTolerancePct)
// The candle finishes above VWAP.
closedAboveVWAP =
close > vwapValue
// Distinguish a pullback from candles simply rising out of a reclaim.
pullbackTowardVWAP = low <= low[1]
rawVWAPBounce =
wasAboveVWAP and
touchedVWAP and
closedAboveVWAP and
pullbackTowardVWAP
// The bounce owns its state. Reclaim and continuation never consume this state.
var bool bounceEpisodeUsed = false
var int bounceAwayBars = 0
bool vwapBounce = false
if barstate.isconfirmed
if newDay or close <= vwapValue
bounceEpisodeUsed := false
bounceAwayBars := 0
if close > vwapValue
bounceAwayBars := low > touchZoneUpper ? bounceAwayBars + 1 : 0
if bounceAwayBars >= episodeResetBars
bounceEpisodeUsed := false
if enableBounce and rawVWAPBounce and not bounceEpisodeUsed and (not applyBounceFilters or allFilters)
vwapBounce := true
bounceEpisodeUsed := true
//────────────────────────────────────────────────────────────
// SETUP 2: VWAP RECLAIM
//────────────────────────────────────────────────────────────
// The prior candle closed at or below VWAP,
// and the current candle closes above VWAP. Evaluate crossover every bar.
// A wick above VWAP is insufficient; reclaims always wait for confirmation.
rawVWAPReclaim = ta.crossover(close, vwapValue)
vwapReclaim =
enableReclaim and
rawVWAPReclaim and
barstate.isconfirmed
//────────────────────────────────────────────────────────────
// SETUP 3: CONTINUED MOVEMENT ABOVE VWAP
//────────────────────────────────────────────────────────────
// Price must remain above VWAP.
aboveVWAP =
close > vwapValue
// Current candle closes higher than the previous candle.
higherClose =
close > close[1]
// Optional requirement for a higher high.
higherHighFilter =
not continuationNeedsHigherHigh or
high > high[1]
rawContinuation =
aboveVWAP and
higherClose and
higherHighFilter
var int lastContinuationBar = na
continuationCooldownComplete =
na(lastContinuationBar) or
bar_index - lastContinuationBar > cooldownBars
vwapContinuation =
enableContinuation and
rawContinuation and
allFilters and
continuationCooldownComplete
if vwapContinuation
lastContinuationBar := bar_index
//────────────────────────────────────────────────────────────
// CLEAN DISPLAY - INDEPENDENT BOUNCE/RECLAIM EVENTS
//────────────────────────────────────────────────────────────
var bool continuationEpisodeUsed = false
var int continuationQuietBars = 0
var int lastContinuationDisplayedBar = na
int displayCode = 0
if confirmationFilter
if newDay
continuationEpisodeUsed := false
continuationQuietBars := 0
lastContinuationDisplayedBar := na
continuationQuietBars := not rawContinuation ? continuationQuietBars + 1 : 0
if close <= vwapValue or continuationQuietBars >= 2
continuationEpisodeUsed := false
bool continuationCandidate = vwapContinuation and not continuationEpisodeUsed
if vwapBounce or vwapReclaim or vwapContinuation
continuationEpisodeUsed := true
bool spacingOK = na(lastContinuationDisplayedBar) or bar_index - lastContinuationDisplayedBar >= markerSpacing
// Reclaim and bounce have different prior-close conditions, so cannot
// describe the same candle. Neither is suppressed by display spacing.
if showReclaimLabels and vwapReclaim
displayCode := 2
else if showBounceLabels and vwapBounce
displayCode := 1
else if spacingOK
displayCode := showContinuationLabels and continuationCandidate ? 3 : 0
if displayCode == 3
lastContinuationDisplayedBar := bar_index
// Smooth trend overlay. Its color reflects the close relative to the EMA.
// Calculate every candle; hold the last confirmed line, color and shade intrabar.
float trendLineRaw = ta.ema(close, trendLength)
int trendDirectionRaw = close >= trendLineRaw ? 1 : -1
float trendBodyMidRaw = (open + close) / 2.0
bool holdTrend = trendCloseOnly and not barstate.isconfirmed
float trendLineValue = holdTrend ? trendLineRaw[1] : trendLineRaw
int trendDirection = holdTrend ? trendDirectionRaw[1] : trendDirectionRaw
float trendBodyMid = holdTrend ? trendBodyMidRaw[1] : trendBodyMidRaw
color trendColor = trendDirection > 0 ? trendUpColor : trendDownColor
// One continuous curve; a hidden candle midpoint anchors the soft fill.
trendLinePlot = plot(showTrendLine ? trendLineValue : na, title = "Smooth trend EMA", color = trendColor, linewidth = trendLineWidth)
trendBodyPlot = plot(showTrendLine and showTrendShade ? trendBodyMid : na, title = "Trend shade anchor", display = display.none, editable = false)
fill(trendLinePlot, trendBodyPlot, color = showTrendLine and showTrendShade ? color.new(trendColor, trendShadeTransparency) : na, title = "Soft trend shading", fillgaps = false)
plot(showVWAP ? vwapValue : na, title = "Daily VWAP", color = vwapLineColor, linewidth = 2)
plot(showVWAP and showVWAPBands ? upperVWAPBand : na, title = "Upper VWAP band", color = vwapBandColor, linewidth = 1)
plot(showVWAP and showVWAPBands ? lowerVWAPBand : na, title = "Lower VWAP band", color = vwapBandColor, linewidth = 1)
// The filtered event carries its own name, with one label per displayed setup.
plotshape(displayCode == 1, title = "BOUNCE label", style = shape.labelup, location = location.belowbar, color = color.new(color.green, 10), text = "BOUNCE", textcolor = color.white, size = size.tiny)
plotshape(displayCode == 2, title = "RECLAIM label", style = shape.labelup, location = location.belowbar, color = color.new(color.blue, 10), text = "RECLAIM", textcolor = color.white, size = size.tiny)
plotshape(displayCode == 3, title = "CONTINUATION label", style = shape.labelup, location = location.belowbar, color = color.new(color.gray, 10), text = "CONTINUATION", textcolor = color.white, size = size.tiny)
// Optional clean alert route. Bounce/Reclaim alerts use their confirmed events.
plot(displayCode, title = "Displayed Setup Code", display = display.none)
alertcondition(displayCode > 0, title = "Clean chart signal", message = "{{ticker}} VWAP Hunter: new displayed signal. Code {{plot(\"Displayed Setup Code\")}} (1=Bounce, 2=Reclaim, 3=Continuation). Signal candle close: {{close}}")
//────────────────────────────────────────────────────────────
// SCANNER OUTPUTS
//────────────────────────────────────────────────────────────
// 0 = No setup
// 1 = VWAP bounce
// 2 = VWAP reclaim
// 3 = Above-VWAP continuation
setupCode =
vwapBounce ? 1 :
vwapReclaim ? 2 :
vwapContinuation ? 3 :
0
plot(
setupCode,
title = "Setup Code",
display = display.none
)
plot(
dailyGainPct,
title = "Gain Today %",
display = display.none
)
plot(
relativeVolume,
title = "Relative Volume",
display = display.none
)
plot(
cumulativeDollarVolume,
title = "Intraday Dollar Volume",
display = display.none
)
//────────────────────────────────────────────────────────────
// ALERT CONDITIONS
//────────────────────────────────────────────────────────────
alertcondition(
vwapBounce,
title = "VWAP Bounce",
message = "{{ticker}} VWAP BOUNCE: Price pulled back toward VWAP and closed back above it. Price: {{close}}"
)
alertcondition(
vwapReclaim,
title = "VWAP Reclaim",
message = "{{ticker}} VWAP RECLAIM: Price moved from below VWAP and closed back above it. Price: {{close}}"
)
alertcondition(
vwapContinuation,
title = "Above-VWAP Continuation",
message = "{{ticker}} ABOVE-VWAP CONTINUATION: Price is above VWAP and moving higher. Price: {{close}}"
)
alertcondition(
vwapBounce or vwapReclaim,
title = "VWAP Bounce or Reclaim",
message = "{{ticker}} triggered a VWAP bounce or VWAP reclaim. Price: {{close}}"
)
alertcondition(
vwapBounce or vwapReclaim or vwapContinuation,
title = "Any VWAP Hunter Signal",
message = "{{ticker}} triggered a VWAP Hunter signal. Price: {{close}}"
)
//────────────────────────────────────────────────────────────
// DYNAMIC ALERT MESSAGES
//────────────────────────────────────────────────────────────
if vwapBounce
alert(
syminfo.ticker +
" | VWAP BOUNCE" +
" | Price: " +
str.tostring(close, format.mintick) +
" | Gain: " +
str.tostring(dailyGainPct, "#.##") +
"%" +
" | RVOL: " +
str.tostring(relativeVolume, "#.##") +
"x",
alert.freq_once_per_bar_close
)
if vwapReclaim
alert(
syminfo.ticker +
" | VWAP RECLAIM" +
" | Price: " +
str.tostring(close, format.mintick) +
" | Gain: " +
str.tostring(dailyGainPct, "#.##") +
"%" +
" | RVOL: " +
str.tostring(relativeVolume, "#.##") +
"x",
alert.freq_once_per_bar_close
)
if vwapContinuation
alert(
syminfo.ticker +
" | ABOVE-VWAP CONTINUATION" +
" | Price: " +
str.tostring(close, format.mintick) +
" | Gain: " +
str.tostring(dailyGainPct, "#.##") +
"%" +
" | RVOL: " +
str.tostring(relativeVolume, "#.##") +
"x",
alert.freq_once_per_bar_close
)