Mean Reversion Signals (v6.4) – VWAP ±SD + RSI Cross + ATR/Vol Filters

optisense_pro · study · 51 行 · 点赞 329 · TradingView 原页

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

Pine Script

//@version=6
indicator(" Mean Reversion Signals (v6.4) – VWAP ±SD + RSI Cross + ATR/Vol Filters", overlay=true)
 
// === INPUTS ===
emaLength200   = input.int(200, "EMA Long-Term")
rsiLength      = input.int(14, "RSI Length")
rsiBuyCross    = input.int(40, "RSI Cross Above (Buy)")
rsiSellCross   = input.int(60, "RSI Cross Below (Sell)")
sdLength       = input.int(20, "VWAP StdDev Lookback")
sdMultiplier   = input.float(1.5, "VWAP StdDev Multiplier (1.0–2.0)", step=0.1)
volAvgLen      = input.int(21, "Volume MA Length")
volMultiplier  = input.float(1.1, "Volume Multiplier")
atrLength      = input.int(14, "ATR Length")
useATRFilter   = input.bool(true, "Use ATR Rising Filter?")
cooldownBars   = input.int(4, "Cooldown Bars")
 
// === CORE CALCULATIONS ===
ema200 = ta.ema(close, emaLength200)
vwap = ta.vwap(close)
vwapDev = ta.stdev(close, sdLength)
vwapUpper = vwap + (vwapDev * sdMultiplier)
vwapLower = vwap - (vwapDev * sdMultiplier)
rsi = ta.rsi(close, rsiLength)
volAvg = ta.sma(volume, volAvgLen)
volCond = volume > (volAvg * volMultiplier)
atrVal = ta.atr(atrLength)
atrCond = not useATRFilter or atrVal > atrVal[1]
emaBuffer = ema200 * 0.01
trendCondBuy = close > ema200 - emaBuffer
trendCondSell = close < ema200 + emaBuffer
rsiCrossUp = ta.crossover(rsi, rsiBuyCross)
rsiCrossDn = ta.crossunder(rsi, rsiSellCross)
 
// === COOLDOWN LOGIC ===
var int lastSignalBar = na
canSignal = na(lastSignalBar) or (bar_index - lastSignalBar > cooldownBars)
 
// === SIGNAL CONDITIONS ===
finalBuy  = barstate.isconfirmed and trendCondBuy and close < vwapLower and rsiCrossUp and volCond and atrCond and canSignal
finalSell = barstate.isconfirmed and trendCondSell and close > vwapUpper and rsiCrossDn and volCond and atrCond and canSignal
 
if (finalBuy or finalSell)
    lastSignalBar := bar_index
 
// === BUY/SELL SIGNALS ONLY ===
plotshape(finalBuy,  title="Buy Signal",  color=color.new(color.lime, 0), style=shape.triangleup,   size=size.large, location=location.belowbar, text="BUY")
plotshape(finalSell, title="Sell Signal", color=color.new(color.red, 0),  style=shape.triangledown, size=size.large, location=location.abovebar, text="SELL")
 
// === ALERTS ===
alertcondition(finalBuy,  "Buy Signal",  "BUY Signal Triggered (RSI/VWAP/ATR Confirmed)")
alertcondition(finalSell, "Sell Signal", "SELL Signal Triggered (RSI/VWAP/ATR Confirmed)")

← 返回列表