本页源码来自 TradingView 公开发布的开源脚本,版权归原作者所有, 请遵循其原始许可(Pine 脚本常见 CC BY-NC-SA / MPL-2.0 / MIT)。 本项目仅用于研究检索与许可范围内的移植。
// This Pine Script® code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © brian_woods79
//@version=6
//@version=5
indicator("VWAP Cross + Hammer/Shooting Star Alert", overlay=true)
// --- Inputs ---
wickMultiplier = input.float(2.0, title="Min Wick to Body Ratio", minval=1.0, step=0.1)
maxMinorWickPct = input.float(0.15, title="Max Opposite Wick (% of Total Range)", minval=0.0, maxval=0.5, step=0.05)
vwapSource = input.source(hlc3, title="VWAP Source")
// --- VWAP Calculation ---
vwapValue = ta.vwap(vwapSource)
plot(vwapValue, title="VWAP", color=color.blue, linewidth=2)
// --- Candle Anatomy ---
totalRange = high - low
bodySize = math.abs(close - open)
lowerWick = math.min(open, close) - low
upperWick = high - math.max(open, close)
// --- Candlestick Patterns ---
// Bullish Hammer Conditions
isHammer = totalRange > 0 and
lowerWick >= (bodySize * wickMultiplier) and
upperWick <= (totalRange * maxMinorWickPct) and
close > (low + totalRange * 0.5)
// Bearish Shooting Star (Inverted Hammer) Conditions
isShootingStar = totalRange > 0 and
upperWick >= (bodySize * wickMultiplier) and
lowerWick <= (totalRange * maxMinorWickPct) and
close < (high - totalRange * 0.5)
// --- VWAP Cross Logic ---
// Long Cross: Close crosses above VWAP, or candle dips below VWAP but closes above it
longCross = ta.crossover(close, vwapValue) or (low < vwapValue and close > vwapValue)
// Short Cross: Close crosses below VWAP, or candle spikes above VWAP but closes below it
shortCross = ta.crossunder(close, vwapValue) or (high > vwapValue and close < vwapValue)
// --- Final Signals ---
longSignal = isHammer and longCross
shortSignal = isShootingStar and shortCross
// --- Visual Shapes ---
plotshape(longSignal, title="Bullish VWAP Hammer", location=location.belowbar, color=color.green, style=shape.labelup, text="BUY", textcolor=color.white)
plotshape(shortSignal, title="Bearish VWAP Star", location=location.abovebar, color=color.red, style=shape.labeldown, text="SELL", textcolor=color.white)
// --- Dynamic Alert Configurations ---
// Triggers when either condition is met
anySignal = longSignal or shortSignal
alertcondition(anySignal, title="VWAP Cross Pattern (Any)", message="VWAP Signal on {{ticker}} ({{interval}}): Close={{close}}")
// Specific direction alerts (useful if you map them to different webhook strategies)
alertcondition(longSignal, title="VWAP Cross + Bullish Hammer", message="BULLISH: Price crossed above VWAP with a Hammer on {{ticker}} ({{interval}})")
alertcondition(shortSignal, title="VWAP Cross + Shooting Star", message="BEARISH: Price crossed below VWAP with a Shooting Star on {{ticker}} ({{interval}})")