strategy · on price · open source
VWAP mean reversion strategy (1% band)
VWAP mean reversion: buy when price closes 1% below the session VWAP, exit when it closes back above VWAP. Plain-English rules, code and a costed backtest. Deepwick Script runs a subset of Pine Script.
What the VWAP Mean Reversion strategy does
VWAP mean reversion long-only: enter when price drops below the session VWAP by the band percentage, exit when it recovers above VWAP.
- Lower
Band %for tighter, more frequent entries. - Best on intraday timeframes (1m–1h) where VWAP has clear meaning.
- Combine with a higher-timeframe trend filter for swing setups.
Entry and exit rules
Language reference: Deepwick Script.
Default inputs
| Input | Default | Min | Max |
|---|---|---|---|
Band % | 1 | 0.1 | 5 |
Stop Loss % | 2 | 0.5 | 10 |
Take Profit % | 6 | 0 | 20 |
How Deepwick fills this strategy
- Market orders fill at the next bar's open.
- Stops and limits follow the bar's path: open → nearer extreme → farther extreme → close.
- Gaps fill at the open.
- Commission is charged on every fill, and slippage applies to market and stop fills, as set in
strategy().
Source code
Deepwick Script, a subset of Pine Script · read-only
//@version=6
strategy("VWAP Mean Reversion", overlay=true, initial_capital=10000, default_qty_type=strategy.percent_of_equity, default_qty_value=10, commission_type=strategy.commission.percent, commission_value=0.05)
bandPct = input.float(1, "Band %", minval=0.1, maxval=5, step=0.1)
stopPct = input.float(2, "Stop Loss %", minval=0.5, maxval=10, step=0.1)
tpPct = input.float(6, "Take Profit %", minval=0, maxval=20, step=0.1)
colorMid = input.color("color.orange", "Color Mid")
colorMid2 = input.color("color.teal", "Color Mid2")
colorUp = input.color("color.green", "Color Up")
colorDown = input.color("color.red", "Color Down")
v = ta.vwap(hlc3)
lowerBand = v * (1 - bandPct / 100)
upperBand = v * (1 + bandPct / 100)
longSignal = strategy.position_size == 0 and close < lowerBand
exitSignal = strategy.position_size > 0 and close > v
if longSignal
strategy.entry("Long", strategy.long)
if strategy.position_size > 0
strategy.exit("Risk", stop=stopPct > 0 ? strategy.position_avg_price * (1 - stopPct / 100) : na, limit=tpPct > 0 ? strategy.position_avg_price * (1 + tpPct / 100) : na)
if exitSignal
strategy.close("Long", comment="Back to VWAP")
p_VWAP = plot(v, "VWAP", color=colorMid, linewidth=2)
p_Lower_Band = plot(lowerBand, "Lower Band", color=color.new(colorMid2, 50), linewidth=1)
p_Upper_Band = plot(upperBand, "Upper Band", color=color.new(colorMid2, 50), linewidth=1)
plotshape(longSignal, "Long", style=shape.triangleup, location=location.belowbar, color=colorUp, text="L")
plotshape(exitSignal, "Exit", style=shape.triangledown, location=location.abovebar, color=colorDown, text="X")
alertcondition(longSignal, "VWAP long entry", "Price dropped below VWAP band")
alertcondition(exitSignal, "VWAP exit", "Price recovered above VWAP")
Run it in Deepwick
- Open a chart of any crypto pair or CFD.
- Click “Scripts” and add this strategy.
- Press Run and read the trades in the Strategy Tester.
FAQ
Is VWAP mean reversion an intraday strategy?
Yes, it is meant for intraday bars, where the session VWAP is meaningful. On daily bars the VWAP resets every bar and the logic stops making sense.
How wide should the band be?
1% is a starting point. Volatile pairs may need more, FX majors much less. Compare a few values with the optimizer, then validate with walk-forward.
No comments yet.
Sign in to comment.