VWAP Deviation Band and Volatility Filter Trading Strategy
FMZQuant

FMZQuant @fmzquant

Joined:
Apr 25, 2024

VWAP Deviation Band and Volatility Filter Trading Strategy

Publish Date: Apr 17
1 1

Image description

Image description

Overview
The VWAP Deviation Band and Volatility Filter Trading Strategy is an intraday trading system based on Volume Weighted Average Price (VWAP) and standard deviation channels. This strategy utilizes VWAP as a central reference point for price, combines Al Brooks' H1/H2 and L1/L2 reversal patterns, and employs an ATR-based volatility filter to screen out low volatility environments, forming a structured trading decision framework. The strategy enters positions when price breaks through standard deviation channels and then reverts, while implementing signal-bar-based stop losses and various flexible profit-taking methods, including regression to VWAP and deviation band targets. Additionally, a safety exit mechanism provides extra protection when consecutive adverse price movements occur, ensuring the strategy maintains robustness across various market conditions.

Strategy Principles
The core principles of this strategy are built on several key components:

VWAP Calculation Anchored to Each Trading Session: The VWAP calculation resets at the beginning of each trading day, ensuring that the price reference point is closely related to the current day's trading activity. The strategy uses standard deviations to create bands above and below VWAP, defaulting to 2x standard deviation.

Entry Trigger Signals:

  • Long Entry (H1/H2): When price opens below the lower 2x standard deviation band but closes above this band, with sufficient bullish strength (calculated via the closing position within the bar range).

  • Short Entry (L1/L2): When price opens above the upper 2x standard deviation band but closes below this band, with sufficient bearish strength.

Volatility Filter:

  • Uses ATR(14) to measure market volatility
  • Skips trading signals when the standard deviation range is too small (less than 3x ATR), avoiding false entries in low volatility environments

Stop Loss Configuration:

  • Longs: Signal bar low minus a stop buffer
  • Shorts: Signal bar high plus a stop buffer

Profit-Taking Exit Strategies:

  • Different exit logic can be configured independently for long and short directions
  • Options include: regression to VWAP, reaching specific deviation band targets, or disabling automatic profit-taking

Safety Exit Mechanism:

  • Triggers a safety exit when a predetermined number of consecutive opposing bars appear
  • Longs: X consecutive bearish bars
  • Shorts: X consecutive bullish bars

The strategy implements a complete signal strength calculation mechanism by measuring the relative position of the closing price within the high-low range to evaluate the quality of each signal. Entry signals are only considered valid when signal strength reaches a minimum threshold (default 0.7).

Strategy Advantages
After in-depth code analysis, this strategy demonstrates the following significant advantages:

  1. Market Structure-Based Entries: Rather than simply tracking price movements, the strategy looks for specific reversal patterns near deviation bands, meaning trades are conducted with the statistical advantage of mean reversion.

  2. Multi-Layered Filtering Mechanism: Through volatility filters, signal strength requirements, and specific price patterns, trade signals are screened on multiple levels, significantly reducing misleading signals.

  3. Flexible Risk Management: The strategy provides various risk control tools, including tight signal-bar-based stop losses, adjustable profit targets, and a safety exit mechanism, allowing traders to adjust risk parameters for different market environments.

  4. Independent Long/Short Configuration: The strategy allows traders to independently configure entry and exit conditions for long and short trades, which is particularly valuable for optimizing performance in markets with directional bias.

  5. Visual Aids: The strategy includes rich visualization options, such as VWAP, deviation band display, and highlighting of low volatility zones, helping traders intuitively understand market conditions and potential signals.

  6. Session-Anchored VWAP: Recalculating VWAP for each trading day ensures that price reference points always remain relevant to current market activity, avoiding issues with outdated reference points.

  7. Emphasis on Signal Quality: Through signal strength calculations, the strategy focuses on high-quality reversal signals rather than merely mechanical crossovers of price and deviation bands.

Strategy Risks
Despite its well-designed structure, the strategy still presents the following potential risks:

  1. Reversal Risk in Trending Markets: As a mean-reversion-based strategy, it may frequently trigger counter-trend signals in strong trending markets, leading to consecutive stop losses. Solution: Disable counter-trend direction trading in strong trend environments or add additional filtering conditions.

  2. Parameter Sensitivity: Strategy performance heavily depends on multiple key parameters, such as standard deviation multiplier, stop loss size, and signal strength threshold. Solution: Conduct comprehensive parameter optimization and sensitivity analysis to find robust parameter sets for different market conditions.

  3. Lack of Time Filtering: The strategy does not consider the characteristics of trading sessions and may generate misleading signals during especially volatile periods such as market opening or closing. Solution: Add time filters to avoid trading during specific market sessions.

  4. Fixed Stop Loss Risk: Using a fixed point-based stop loss may perform inconsistently across different volatility environments. Solution: Consider using ATR-based dynamic stop losses that adapt to current market volatility.

  5. Lack of Volume Filtering: While the strategy uses VWAP, it doesn't directly filter low volume environments, which may lead to unreliable signals in conditions of insufficient liquidity. Solution: Add volume threshold conditions to ensure trading only in environments with adequate liquidity.

  6. Timing Issues with Safety Exit: A fixed number of opposing bars may trigger safety exits prematurely or react too slowly when an exit is truly needed. Solution: Consider a dynamic safety exit mechanism that combines price movement magnitude with bar count.

Strategy Optimization Directions
Based on code analysis, here are potential optimization directions:

  1. Dynamic Deviation Band Multiplier: The current strategy uses a fixed 2x standard deviation for entry trigger conditions. Consider dynamically adjusting this multiplier based on market volatility, using larger multipliers in high-volatility markets and smaller ones in low-volatility markets to adapt to different market environments.

  2. Add Time Filters: Implement trade filtering for specific time periods, avoiding unstable volatility periods such as market opening, closing, and lunch hours, or focusing on specific high-efficiency trading sessions.

  3. Integrate Market Structure Analysis: Incorporate trend analysis from higher timeframes, trading only in directions consistent with larger trends, or using stricter filtering conditions for counter-trend signals.

  4. Optimize Safety Exit Mechanism: The current safety exit is based on a fixed number of opposing bars. Consider combining price movement magnitude, such as triggering an exit when price retraces beyond a specific percentage of the maximum favorable movement after entry.

  5. Add Volume Confirmation: When entry signals form, add volume confirmation conditions to ensure signals are accompanied by sufficient market participation, improving signal reliability.

  6. Implement Dynamic Stop Loss Management: Replace fixed point-based stops with ATR-based dynamic stop losses, or implement trailing stop functionality to protect accumulated profits.

  7. Add Risk-Reward Ratio Filtering: Calculate the potential target-to-stop ratio before entry, executing only trades with sufficiently favorable risk-reward ratios.

  8. Incorporate Seasonality and Calendar Effects: Analyze and leverage seasonal patterns and calendar effects specific to the market, increasing trading during statistically favorable periods and reducing it during unfavorable periods.

These optimizations can improve the strategy's robustness and profitability, particularly its adaptability across different market environments.

Conclusion
The VWAP Deviation Band and Volatility Filter Trading Strategy is a well-designed intraday trading system that combines several key concepts from technical analysis. It utilizes VWAP as the central price reference point, calculates deviation bands through standard deviations, and captures trading opportunities when price rebounds from these bands. The core strengths of this strategy lie in its multi-layered filtering mechanism and flexible risk management system, enabling it to adapt to different market environments.

Despite some potential risks, such as reversal risk in strong trending markets and parameter sensitivity, these can be mitigated through further optimization. Optimization directions include dynamically adjusting deviation band multipliers, adding time filters, integrating higher timeframe analysis, and improving stop loss management.

Overall, this is a solidly constructed strategy framework suitable for experienced traders to further customize and improve. Through optimization targeted at specific markets and trading styles, it has the potential to become a reliable intraday trading tool, especially in moderately volatile markets with mean-reversion tendencies.

Strategy source code

/*backtest
start: 2025-03-30 00:00:00
end: 2025-03-31 20:00:00
period: 1m
basePeriod: 1m
exchanges: [{"eid":"Futures_Binance","currency":"ETH_USDT"}]
*/

//@version=5
strategy("VWAP Strategy", overlay=true, default_qty_type=strategy.fixed, default_qty_value=1, initial_capital=2000)

// === Inputs ===
src = input.source(hlc3, "Source")
stopPoints = input.float(20.0, "Stop Buffer (Points from Signal Bar High/Low)", step=0.25)

exitModeLong = input.string("VWAP", "Long Exit Rule", options=["VWAP", "Deviation Band", "None"])
exitModeShort = input.string("VWAP", "Short Exit Rule", options=["VWAP", "Deviation Band", "None"])
targetLongDeviation = input.float(2.0, "Long Target Deviation", step=0.1)
targetShortDeviation = input.float(2.0, "Short Target Deviation", step=0.1)

enableSafetyExit = input.bool(true, "Enable Safety Exit")
numOpposingBars = input.int(3, "Opposing Bars for Safety Exit", minval=1)

allowLongs = input.bool(true, "Allow Long Trades")
allowShorts = input.bool(true, "Allow Short Trades")

minStrength = input.float(0.7, "Minimum Signal Strength (0-1)", step=0.05)

showVWAP = input.bool(true, "Show VWAP")
showBands = input.bool(true, "Show Entry Bands")
showLowVolZones = input.bool(true, "Highlight Low Vol Zones")

// === VWAP Session Logic ===
var float sumSrc = na
var float sumVol = na
var float sumSrcSqVol = na

newSession = ta.change(time("D"))
if newSession or na(sumSrc)
    sumSrc := 0.0
    sumVol := 0.0
    sumSrcSqVol := 0.0

sumSrc += src * volume
sumVol += volume
sumSrcSqVol += math.pow(src, 2) * volume

vwap = sumSrc / sumVol
variance = (sumSrcSqVol / sumVol) - math.pow(vwap, 2)
stdev = math.sqrt(variance)

// === Deviation Bands ===
bandEntryMult = 2.0
entryUpper = vwap + stdev * bandEntryMult
entryLower = vwap - stdev * bandEntryMult

targetUpperLong = vwap + stdev * targetLongDeviation
targetLowerShort = vwap - stdev * targetShortDeviation

// === ATR-Based Volatility Filter ===
atrVal = ta.atr(14)
isVolTooLow = stdev * 2 < atrVal * 3
bgcolor(showLowVolZones and isVolTooLow ? color.new(color.orange, 85) : na, title="Low Volatility Zone")

// === Signal Strength Calculations ===
barRange = high - low
bullStrength = barRange > 0 ? (close - low) / barRange : 0
bearStrength = barRange > 0 ? (high - close) / barRange : 0

// === Entry Triggers with Strength Filter ===
isH1H2 = open < entryLower and close > entryLower and bullStrength >= minStrength
isL1L2 = open > entryUpper and close < entryUpper and bearStrength >= minStrength

plotshape(isH1H2, title="H1/H2", location=location.belowbar, color=color.lime, style=shape.triangleup, size=size.tiny)
plotshape(isL1L2, title="L1/L2", location=location.abovebar, color=color.red, style=shape.triangledown, size=size.tiny)

// === Signal Bar Stop Tracking ===
var float signalLow = na
var float signalHigh = na

// === Entry Logic ===
longCondition = allowLongs and isH1H2 and strategy.position_size == 0 and not isVolTooLow
shortCondition = allowShorts and isL1L2 and strategy.position_size == 0 and not isVolTooLow

if longCondition
    strategy.entry("Long", strategy.long)
    signalLow := low

if shortCondition
    strategy.entry("Short", strategy.short)
    signalHigh := high

// === Reset Signal Bar Info
if strategy.position_size == 0
    signalLow := na
    signalHigh := na

// === Apply Signal-Bar-Based Stop
if strategy.opentrades > 0
    if strategy.position_size > 0 and not na(signalLow)
        strategy.exit("Long SL", from_entry="Long", stop=signalLow - stopPoints)
    if strategy.position_size < 0 and not na(signalHigh)
        strategy.exit("Short SL", from_entry="Short", stop=signalHigh + stopPoints)

// === Target Exits (Independent per side)
exitLongVWAP = strategy.position_size > 0 and exitModeLong == "VWAP" and high >= vwap
exitLongDev  = strategy.position_size > 0 and exitModeLong == "Deviation Band" and high >= targetUpperLong
exitShortVWAP = strategy.position_size < 0 and exitModeShort == "VWAP" and low <= vwap
exitShortDev  = strategy.position_size < 0 and exitModeShort == "Deviation Band" and low <= targetLowerShort

if exitModeLong != "None" and (exitLongVWAP or exitLongDev)
    strategy.close("Long", comment="Target Exit")

if exitModeShort != "None" and (exitShortVWAP or exitShortDev)
    strategy.close("Short", comment="Target Exit")

// === Safety Exit
bullishBar(i) => close[i] > open[i]
bearishBar(i) => close[i] < open[i]

bullCount = 0
bearCount = 0
for i = 0 to numOpposingBars - 1
    bullCount += bullishBar(i) ? 1 : 0
    bearCount += bearishBar(i) ? 1 : 0

exitSafetyLong = enableSafetyExit and strategy.position_size > 0 and bearCount == numOpposingBars
exitSafetyShort = enableSafetyExit and strategy.position_size < 0 and bullCount == numOpposingBars

if exitSafetyLong
    strategy.close("Long", comment="Safety Exit")

if exitSafetyShort
    strategy.close("Short", comment="Safety Exit")

// === Plotting ===
plot(showVWAP ? vwap : na, color=color.blue, title="VWAP")
pUpper = plot(showBands ? entryUpper : na, color=color.green, title="Upper Entry Band")
pLower = plot(showBands ? entryLower : na, color=color.red, title="Lower Entry Band")
fill(pUpper, pLower, color=color.new(color.gray, 85))
Enter fullscreen mode Exit fullscreen mode

Strategy parameters

Image description

The original address: VWAP Deviation Band and Volatility Filter Trading Strategy

Comments 1 total

  • Rebecca Chow
    Rebecca ChowJun 26, 2025

    Smart use of VWP bands with volatility filters! The mean-reversion logic is clear, but how does it handle extended trends when price stays deviated? Have you tested different band widths for various volatility regimes? Also curious about position sizing—does it scale with the deviation strength? Really like the adaptive nature of this. Would love to see how it performs during FOMC events!

Add comment