Skip to main content

VWAP Bounce — Pine Script v5 strategy

REVERSALVWAPPine Script v5

The script computes VWAP from the hlc3 price and compares the current close with that value. It opens one long position when the close crosses above VWAP and closes it when the close crosses below.

Full code (free to copy)

//@version=5
strategy("VWAP Bounce", overlay=true)
vwapVal = ta.vwap(hlc3)
if (close > vwapVal and close[1] < vwapVal[1])
    strategy.entry("Long", strategy.long)
if (close < vwapVal and close[1] > vwapVal[1])
    strategy.close("Long")

How the script works

The script starts with a version directive set to 5, then declares a strategy named VWAP Bounce with overlay set to true so it is drawn on the price chart. The next line stores ta.vwap of the hlc3 series in the variable vwapVal, which gives one VWAP value per bar, recalculated from the session start.

The entry block tests two comparisons joined by and: the current close must be above vwapVal, and the previous close must be below the previous VWAP value. When both are true on the same bar, the close has crossed back above VWAP and strategy.entry is called with the identifier Long and the direction strategy.long, which sends a market buy order.

The exit block mirrors the entry: it checks that the close is below vwapVal while the previous close was above the previous VWAP value. If that is true, strategy.close is called with the same identifier Long and the open long position is closed. The code holds no stop loss, take profit, short entry or filter on trend or volume.

Parameters in the code

ParameterValueRole
Strategy nameVWAP BounceFirst argument of the strategy declaration.
OverlaytrueSet in the strategy declaration, so the script is drawn on the price chart.
VWAP sourcehlc3Series passed to ta.vwap, the average of high, low and close.
Entry identifierLongLabel given to the position opened by strategy.entry.
Entry directionstrategy.longDirection argument of strategy.entry.
Exit identifierLongPosition closed by strategy.close.
Pine version5Value of the version directive on the first line.

Known limits of this rule

Before you trust it: test it on data it never saw

A backtest in TradingView's Strategy Tester shows one past path with the settings you picked. Strategy Arena Lab (free, Windows and Linux) replays this Pine on your PC, compares its trades one by one with TradingView's for supported Pine, counts the variants you try, then judges the rule on a period kept sealed during the search: holds, mirage or inconclusive.

Get the free Lab →

FAQ

Does it work on crypto?

The script only reads hlc3 and calls ta.vwap, so it can run on any symbol the platform offers, crypto pairs included. VWAP is anchored per session, which fits markets that trade around the clock less naturally. You can replay it on a period you have never seen in Strategy Arena Lab, which is free.

How do I add a stop loss?

Add a strategy.exit call with a stop price and the same Long identifier, or pass a stop argument to strategy.entry. The current code contains neither.

Other free Pine Script v5 strategies

RSI Mean ReversionEMA Crossover 9/21EMA Ribbon 8/21/55Bollinger Band BounceMACD MomentumSuperTrendStochastic RSIATR BreakoutRSI + EMA Combo
TradingView Starter
Choose the account path. Prove the strategy separately.
Your first chart and price alert do not require the Lab. Strategy Arena proof remains required before trusting or exporting a strategy.
Partner attribution is for first-time users and web purchases only. Strategy Arena may earn a commission on eligible purchases; starting with a free account needs no payment.
I have never had an account · Start free I already have an account Check a strategy
More TradingView paths
Evidence-gated Pine review

Educational code on past data. No investment advice; no result is promised.