Mean ReversionIntermediateVWAPATREMA

VWAP Reversion Strategy

VWAP (Volume Weighted Average Price) acts as a magnet for price during the trading session. This strategy buys pullbacks to VWAP when the trend is bullish (price above 200 EMA) and shorts bounces to VWAP when bearish. VWAP resets at each new session.

Best for: Intraday stocks and futures — first 2 hours of sessionTimeframes: 5m, 15m

Pine Script v6 — Complete Strategy Code

//@version=6
vwap-strategy-pine-script.pine
//@version=6
strategy("VWAP Reversion", overlay=true,
     default_qty_type=strategy.percent_of_equity, default_qty_value=10)

// ── Inputs ──
int   trendLen = input.int(defval=200,  title="Trend EMA Length", minval=1,   group="Filter")
int   atrLen   = input.int(defval=14,   title="ATR Length",       minval=1,   group="Risk")
float slMult   = input.float(defval=1.0, title="SL ATR Mult",    minval=0.1, step=0.1, group="Risk")
float tpMult   = input.float(defval=2.0, title="TP ATR Mult",    minval=0.1, step=0.1, group="Risk")

// ── Calculations ──
float vwap      = ta.vwap(close)
float trendEma  = ta.ema(close, trendLen)
float atr       = ta.atr(atrLen)

bool aboveVwap  = close > vwap
bool belowVwap  = close < vwap
bool bullTrend  = close > trendEma
bool bearTrend  = close < trendEma

bool longCond   = ta.crossover(close, vwap)  and bullTrend
bool shortCond  = ta.crossunder(close, vwap) and bearTrend

// ── Visuals ──
plot(vwap,     "VWAP",      color.new(color.yellow, 0), linewidth=2)
plot(trendEma, "Trend EMA", color.new(color.gray,   50), linewidth=1)
plotshape(longCond,  style=shape.triangleup,   location=location.belowbar, color=color.green, size=size.small)
plotshape(shortCond, style=shape.triangledown, location=location.abovebar, color=color.red,   size=size.small)

// ── Orders ──
if longCond
    strategy.entry("Long", strategy.long)
    strategy.exit("XL", from_entry="Long", stop=close - atr * slMult, limit=close + atr * tpMult)
if shortCond
    strategy.entry("Short", strategy.short)
    strategy.exit("XS", from_entry="Short", stop=close + atr * slMult, limit=close - atr * tpMult)

// ── Alerts ──
alertcondition(longCond,  title="VWAP Long",  message="VWAP long entry — {{ticker}}")
alertcondition(shortCond, title="VWAP Short", message="VWAP short entry — {{ticker}}")

Copy and paste into TradingView Pine Editor, or generate a custom variation with AI.

How it works

Strategy logic, step by step

  1. 1

    VWAP is calculated using ta.vwap — automatically resets each session.

  2. 2

    Trend filter: 200 EMA on the same chart determines bias.

  3. 3

    Long entry: price crosses above VWAP AND close is above 200 EMA.

  4. 4

    Short entry: price crosses below VWAP AND close is below 200 EMA.

  5. 5

    Stop loss: ATR(14) × 1.0 below/above entry.

  6. 6

    Take profit: ATR(14) × 2.0 (2:1 R:R).

Parameters

Configurable inputs

ParameterDefault
Trend EMA Length200
ATR Length14
SL ATR Mult1.0
TP ATR Mult2.0

Ask the TradePilot copilot to backtest this and sweep the inputs to find the best combination for your asset and timeframe.

FAQ

VWAP Reversion Strategy questions

What markets work best for VWAP strategies?

VWAP is most reliable on liquid intraday markets: stocks, futures (ES, NQ, CL), and major forex pairs. It is less useful on crypto where there is no clear session open.

Does VWAP reset daily?

Yes — ta.vwap() in Pine Script resets at the start of each new trading session by default, which is the correct behavior for intraday VWAP.

More strategies

Other Pine Script strategies

Want a custom version of this strategy?

Describe your modifications in plain English — different indicators, different risk parameters, long-only, multi-timeframe filter — and TradePilot generates the full Pine Script v6 code in seconds.