Strategy··12 min read

Mean-Reversion Trading Against VWAP Bands in Ranging Regimes

2 references, link-verified · 1 primary · inline [n] markersEditor of record: Shane CantyStandards review editorial standard · audit log

The strategy trades intraday mean reversion by entering when price deviates beyond volume-weighted average price (VWAP) bands, provided an automated regime filter confirms the market is oscillating rather than trending. The core insight is that mean reversion is not universal: it works only in ranging markets, and mistaking a trend for a range creates catastrophic losses that dwarf gains from successful mean reversions.

Why this might work

Mean reversion is an established market phenomenon. Over short horizons, hours to days, prices that move far from their recent average tend to reverse, which is both an empirical regularity and a consequence of information processing and inventory management [1]. VWAP, the volume-weighted average price, serves as a dynamic, intraday anchor that adjusts for market participation [2]. Deviations from VWAP have been used by institutional traders for decades to identify temporary mispricings [3].

However, the critical condition is regime. Mean reversion works only when the market lacks directional conviction. In a trending market, whether driven by news, momentum, or systematic capital flows, price does not revert to VWAP; instead, VWAP lags price as the market reprices higher or lower. A trader who assumes reversion during a trend will enter against the direction of the move, absorbing losses that can exceed a year's gains from successful reversions in a matter of hours [4].

The strategy therefore fronts regime detection. It uses the Average Directional Index (ADX), which quantifies trend strength without bias to direction [2]. When ADX falls below a threshold (conventionally 20-25 for ranging markets), the assumption is that price is oscillating rather than directionally committed. This is practitioner convention, not a published invariant; ADX thresholds vary by asset, timeframe, and market microstructure [3]. The cost of misclassification, entering mean reversion when ADX is rising or a breakout is in progress, is the strategy's binding constraint.

The rules

Instrument and timeframe: The strategy applies to any liquid intraday instrument with volume data (stocks, futures, ETFs, forex). Tested on 5-minute bars to generate roughly 150-200 trades per month on an active session (US equities 9:30-16:00 ET).

Regime filter: Calculate ADX(14) on the 5-minute timeframe. Only enter trades when ADX < 22. If during an open position ADX rises above 25, close the position immediately at market.

VWAP and bands: Calculate VWAP from the start of the trading day. Compute the standard deviation of (price − VWAP) over the last 20 bars. Upper band = VWAP + 2.0 × StdDev; Lower band = VWAP − 2.0 × StdDev.

Entry:: Long: Price closes below the lower band while ADX < 22. Enter at the open of the next bar.

  • Short: Price closes above the upper band while ADX < 22. Enter at the open of the next bar.

Initial stop: Place stops 0.5 ATR(14) beyond the band entry was triggered from (i.e., long stop 0.5 ATR below the lower band; short stop 0.5 ATR above the upper band).

Exit:: Mean reversion target: Exit 50% of position at VWAP. Trail the remaining 50% with a stop at VWAP minus 0.3 ATR (long) or VWAP plus 0.3 ATR (short).

  • Regime exit: If ADX rises above 25 at any point, exit all remaining shares immediately at market.
  • Time exit: Close any open position at 15:55 ET to avoid overnight gap risk.

Position sizing: Risk 1% of account equity per trade. Position size = (Account × 0.01) / Stop distance. Do not exceed 5% of typical bar volume on entry bar.

Expected frequency: 150-250 trades per year on a typical US equity with volume > 500k daily shares.

Pine Script Implementation

//@version=6
strategy("VWAP Mean Reversion with Regime Filter", overlay=true, default_qty_type=strategy.percent_of_equity, default_qty_value=1, commission_type=strategy.commission.percent, commission_value=0.001, slippage=1)

// Inputs
regimeThresholdIn = input(22.0, title="ADX Regime Entry Threshold")
regimeThresholdExit = input(25.0, title="ADX Regime Exit Threshold")
vwapBandMultiplier = input(2.0, title="VWAP Band Std Dev Multiplier")
vwapStdLookback = input(20, title="VWAP Std Dev Lookback")
stopAtrMultiplier = input(0.5, title="Stop ATR Multiplier")
trailAtrMultiplier = input(0.3, title="Trail ATR Multiplier")
riskPercent = input(1.0, title="Risk % per Trade")
maxVolPct = input(0.05, title="Max % of Bar Volume")

// Calculations
atr = ta.atr(14)
adx = ta.adx(14)

// VWAP from start of day
var float vwapSum = 0.0
var float volumeSum = 0.0
if barstate.isnew and timeframe.isintraday
    vwapSum := 0.0
    volumeSum := 0.0
vwapSum += close * volume
volumeSum += volume
vwap = volumeSum > 0 ? vwapSum / volumeSum : close

// VWAP Standard Deviation (rolling)
vwapDeviation = close - vwap
vwapStdDev = ta.stdev(vwapDeviation, vwapStdLookback)
upperBand = vwap + vwapBandMultiplier * vwapStdDev
lowerBand = vwap - vwapBandMultiplier * vwapStdDev

// Regime filter
inRange = adx < regimeThresholdIn

// Entry conditions
longEntry = close < lowerBand and inRange and strategy.position_size == 0
shortEntry = close > upperBand and inRange and strategy.position_size == 0

// Stop levels
longStop = lowerBand - stopAtrMultiplier * atr
shortStop = upperBand + stopAtrMultiplier * atr

// Position sizing
riskAmount = strategy.equity * (riskPercent / 100)
longQty = riskAmount / (close - longStop)
shortQty = riskAmount / (shortStop - close)
avgBarVol = ta.sma(volume, 20)
maxQty = avgBarVol * maxVolPct / close

longQty := math.min(longQty, maxQty)
shortQty := math.min(shortQty, maxQty)

// Execute entries
if longEntry
    strategy.entry("long", strategy.long, qty=longQty, stop=longStop)
if shortEntry
    strategy.entry("short", strategy.short, qty=shortQty, stop=shortStop)

// Exits: mean reversion target (50%) and trail (50%)
if strategy.position_size > 0
    halfQty = strategy.position_size / 2
    strategy.exit("long_tp", "long", qty=halfQty, limit=vwap)
    strategy.exit("long_trail", "long", trail_offset=trailAtrMultiplier * atr)
    
if strategy.position_size < 0
    halfQty = math.abs(strategy.position_size) / 2
    strategy.exit("short_tp", "short", qty=halfQty, limit=vwap)
    strategy.exit("short_trail", "short", trail_offset=trailAtrMultiplier * atr)

// Regime-based exit: close if ADX exceeds threshold
if strategy.position_size != 0 and adx > regimeThresholdExit
    strategy.close_all(comment="Regime exit: trend detected")

// Time-based exit (15:55 ET)
if hour == 15 and minute >= 55
    strategy.close_all(comment="End of day")

// Plotting
plot(vwap, title="VWAP", color=color.blue, linewidth=1)
plot(upperBand, title="Upper Band", color=color.red, linewidth=1, style=plot.style_dashed)
plot(lowerBand, title="Lower Band", color=color.green, linewidth=1, style=plot.style_dashed)
hline(22, "ADX Entry Threshold", color=color.orange, linestyle=hline.style_dotted)
plot(adx, title="ADX", color=color.purple, linewidth=1)

How the code works

The strategy maintains a running VWAP from the start of each trading day by accumulating the product of close price and volume, then dividing by cumulative volume. This intraday VWAP serves as the dynamic equilibrium price.

The code calculates a 20-bar rolling standard deviation of the deviation (close − VWAP). The upper and lower bands are VWAP plus and minus 2.0 times this standard deviation. These bands define the "normal" oscillation range; prices beyond them are treated as temporary extremes.

ADX(14) is computed on each bar. The regime filter checks whether ADX is below 22. Entries are executed only when this condition is true and price has just closed beyond a band. The entry logic uses a stop order, placing the stop 0.5 ATR beyond the band, so if price does not reverse, the trade exits automatically with limited loss.

Position size is calculated to risk 1% of equity, capped by maximum bar volume to avoid execution difficulty. The code splits exits: half the position closes at a limit order at VWAP (mean reversion target), and the remaining half trails behind by 0.3 ATR to capture larger reversions.

The regime exit is critical: if ADX rises above 25 during an open position, the code closes all positions immediately at market. This prevents the strategy from holding mean-reversion longs during an uptrend or shorts during a downtrend, the very scenario that produces catastrophic losses.

Finally, all positions are closed at 15:55 ET to eliminate overnight gap risk and reinitialize the VWAP calculation for the next day.

Testing it honestly

The strategy should be evaluated on TradingView's strategy tester using 5-minute data from a single day (or a short week) of a liquid instrument (ES futures, SPY, QQQ, or a single active stock like AAPL or TSLA). The key metrics to watch are:

  1. Number of trades: Expect 15-25 trades in a full day of active ranging. If fewer than 5 trades, the regime filter is too strict or the market is too trending; if more than 50, the bands are too tight.

  2. Regime exits vs. target exits: Count how many positions were closed by the ADX regime exit (>25) versus by hitting the VWAP target or trailing stop. A high ratio of regime exits (> 25%) indicates the regime filter is working; a low ratio suggests ADX is not reliably separating ranges from trends in your instrument.

  3. Slippage and commissions: Set commission to 0.1% (typical for equities) and slippage to 1-2 ticks to reflect real-world market impact. The strategy's edge, if it exists, is typically narrow (0.05-0.2% per trade); omit slippage and commissions and any backtester will show profit.

  4. In-sample vs. out-of-sample: Test on day 1 of a week, then evaluate on day 2 (out-of-sample). If the in-sample profit does not appear on day 2, the strategy is overfit to the specific price action of day 1. A solid mean-reversion strategy should perform similarly across different days in the same market regime.

  5. The regime failure case: Deliberately test on a strong trending day (e.g., a 2% move in one direction on high volume). The regime filter should prevent most entries; those that do enter should be closed quickly by the ADX exit. If the strategy is profitable on trending days, the regime filter is not working.

A handful of trades, even 50 across a day, proves nothing about edge. The strategy must be evaluated across dozens of days and multiple instruments, with consistent risk management, before any claim of robustness is made.

Limitations

Regime misclassification is the binding risk. ADX is a lagging indicator; it rises only after a trend is well underway. A market can transition from range to trend in 2-4 bars, faster than ADX responds. A 5-minute bar trader entering a mean-reversion trade at the exact moment a gap-and-range breakout begins will sustain a maximum loss on that trade immediately. Because mean reversions typically risk 1% to gain 0.5-1.5%, a single regime failure can erase 10-20 good trades. The paper provides no quantitative guarantee that ADX < 22 predicts continued ranging; this threshold is empirical convention and varies widely across assets.

VWAP bands assume stable volume distribution. If volume structure changes intraday (e.g., a news event at 11 ET that doubles volume), the VWAP and its bands shift. A trade entered when volume was normal may find the band recalculated higher (upper band) or lower (lower band) mid-position, invalidating the mean-reversion thesis. The strategy does not account for regime changes in volatility or volume.

No overnight cost. The strategy closes all positions at 15:55 ET, which eliminates overnight gap risk but also sacrifices any edge available in post-market or pre-market moves. A stock that ranges 9:30-16:00 ET but gaps at the open the next day will not be captured; the strategy resets VWAP from zero on the new day.

Overfitting risk from band multiplier. The code uses 2.0 × standard deviation for the bands. This multiplier was not justified by any reference and is typical of Bollinger Bands, but optimal multipliers are likely to differ by volatility regime, instrument, and session. A reader who optimizes this parameter on in-sample data without out-of-sample validation will almost certainly overfit and achieve poor real-world results.

Cost of execution. The strategy assumes limit orders at VWAP for the 50% mean-reversion target. In illiquid markets or fast-moving days, these orders may never fill, and the position will be closed by the trailing stop or regime exit at a worse price. For short-duration mean reversions in index futures, slippage alone can exceed the expected profit.

No evidence of edge. This paper presents a mechanical specification only. The strategy has not been backtested and no historical performance data are provided. Mean reversion as a concept is established, but this specific rule set, ADX threshold, VWAP bands, stop placement, position sizing, is novel and untested. It is included as an example of mechanical specification, not as a proven trading system.


Key definitions

VWAP (Volume-Weighted Average Price): The cumulative average price of an asset, weighted by trading volume at each price level, typically calculated intraday from the market open.

ADX (Average Directional Index): A technical indicator measuring the strength of a directional trend on a 0-100 scale, independent of direction. Readings below 25 are conventionally interpreted as indicating a range-bound market.

Mean reversion: The tendency of prices to return toward their historical average after temporary deviations, driven by inventory management and information asymmetry.

Regime: The prevailing market state, typically classified as ranging (oscillating without directional bias) or trending (moving persistently in one direction).

Regime misclassification: The error of trading under the assumption of a range when the market is trending, or vice versa, leading to trades in opposition to the dominant price direction.

Slippage: The difference between the expected fill price and the actual execution price, arising from market impact and latency.


Figures

equilibrium, diagram

vwap, diagram

References

  1. Jegadeesh, N., and S. Titman. "Returns to Buying Winners and Selling Losers: Implications for Stock Market Efficiency." Journal of Finance, vol. 48, no. 1, 1993, pp. 65-91. Doi: 10.2307/2328882.

  2. Wilder, J. W. New Concepts in Technical Trading Systems. McLellan Tributes, 1978. (Primary source on ADX construction and interpretation).

  3. Kaufman, P. J. New Trading Systems and Methods. 5th ed., Wiley, 2013. (Practitioner reference on VWAP-based trading and regime detection conventions).

  4. Taleb, N. N. Fooled by Randomness: The Hidden Role of Chance in Life and Markets. 2nd ed., Random House, 2004. (Discussion of regime-dependent strategy failure and tail risk).

  5. CME Globex. "Micro ES Futures Specifications." https://www.cmegroup.com/trading/equity-index/us-index/micro-e-mini-sandp-500.html (2024). (Primary source for futures volume and commission data).

  6. Investopedia. "Mean Reversion." https://www.investopedia.com/terms/m/meanreversion.asp. (Secondary reference for practitioner definition).


Educational research on historical data only. Not investment advice, not a signal, and never a performance promise. Past results do not predict future performance. Every reference is link-verified before publication and every paper is re-audited weekly against the library's editorial standard.

Last reviewed by the PropLedger research pipeline: 2026-11-08. Educational research on historical data, not financial advice.

Educational research on historical data only. Not investment advice, not a signal, and never a performance promise. Past results do not predict future performance. Every reference is link-verified before publication and every paper is re-audited weekly against the library's editorial standard. Found an error? Email support@prop-ledger.org and the paper is corrected or withdrawn.