Strategy · Pine Script v6 · On the chart

NQ VWAP Reversion [trugurpala]

by trugurpala

This strategy draws on the price chart and identifies mean-reversion opportunities around daily volume-weighted average price (VWAP) bands.

View on GitHub

GitHub stars4on the repository
Pine versionv6current
Lines of code92
Settings5inputs
LicenceMIT
Last update2 months ago3 Aug 2026

Add It to Your TradingView Chart

  1. 1Copy the scriptPress Copy script above, or the copy button on the code below.
  2. 2Open the Pine EditorOpen a TradingView chart and choose Pine Editor at the bottom of the screen.
  3. 3Paste over the templateCreate a new strategy, select all of the template text and paste. Press Save and give it a name.
  4. 4Add it to the chartPress Add to chart. The trades and results appear in the Strategy Tester tab; adjust the settings with the gear icon.

Source Code

92 lines of Pine Script v6 from global-markets/16_nq_vwap_reversion.pine, published under MIT. Keep the author's credit and licence lines when you reuse it.

16_nq_vwap_reversion.pine
//@version=6
// NQ Nasdaq-100 — VWAP Mean Reversion Strategy
// Author: Ugur Pala · github.com/trugurpala/pinescriptv6
// TradingView: https://tr.tradingview.com/u/trugurpala/
//
// TR: Fiyat VWAP'tan uzaklaştığında VWAP'a geri dönüş üzerine işlem yapar.
//     Trendsiz / range piyasalarda daha etkilidir.
// EN: Trades mean reversion to VWAP when price extends too far.
//     More effective in range / low-trend market conditions.
//
// Sembol / Symbol: CME_MINI:NQ1! veya CME_MICRO:MNQ1!
// Önerilen TF / Recommended TF: 5M, 15M
strategy("NQ VWAP Reversion [trugurpala]",
    overlay           = true,
    initial_capital   = 25000,
    default_qty_type  = strategy.fixed,
    default_qty_value = 1,
    commission_type   = strategy.commission.cash_per_contract,
    commission_value  = 4.0,
    slippage          = 1)

// ── Inputs ───────────────────────────────────────────────────────────────────
float devMult   = input.float(1.5, "VWAP Band Mult", step=0.1,
                    tooltip="Kaç standart sapma uzakta / How many std devs away")
int   rsiLen    = input.int(14,  "RSI Filter",    minval=1)
float rsiOb     = input.float(65, "RSI OB",       minval=55, maxval=80)
float rsiOs     = input.float(35, "RSI OS",       minval=20, maxval=45)
float atrMult   = input.float(1.5, "SL Mult",     step=0.1)

// ── RTH Filtresi ──────────────────────────────────────────────────────────────
bool inRTH = not na(time(timeframe.period, "0930-1600", "America/New_York"))
bool rthEnd = inRTH[1] and not inRTH
if rthEnd
    strategy.close_all(comment="RTH End")

// ── VWAP Hesapla ─────────────────────────────────────────────────────────────
bool newDay = ta.change(time("D")) != 0
var float cumVol    = 0.0
var float cumVolPx  = 0.0
var float cumVolPx2 = 0.0

if newDay
    cumVol    := 0.0
    cumVolPx  := 0.0
    cumVolPx2 := 0.0

cumVol    += volume
cumVolPx  += volume * hlc3
cumVolPx2 += volume * hlc3 * hlc3

float vwapVal  = cumVolPx  / cumVol
float variance = cumVolPx2 / cumVol - vwapVal * vwapVal
float stdev    = math.sqrt(math.max(variance, 0))
float upperBand = vwapVal + devMult * stdev
float lowerBand = vwapVal - devMult * stdev

// ── Sinyaller ────────────────────────────────────────────────────────────────
float rsi       = ta.rsi(close, rsiLen)
float atrVal    = ta.atr(14)

// Bandın altından VWAP'a dönüş (long)
bool longEntry  = ta.crossover(close, lowerBand) and rsi < rsiOs and inRTH and strategy.position_size == 0
// Bandın üstünden VWAP'a dönüş (short)
bool shortEntry = ta.crossunder(close, upperBand) and rsi > rsiOb and inRTH and strategy.position_size == 0

// ── Entries ──────────────────────────────────────────────────────────────────
if longEntry
    strategy.entry("Long", strategy.long)
    strategy.exit("Long Exit", "Long",
        stop  = close - atrMult * atrVal,
        limit = vwapVal)  // Hedef VWAP / Target is VWAP

if shortEntry
    strategy.entry("Short", strategy.short)
    strategy.exit("Short Exit", "Short",
        stop  = close + atrMult * atrVal,
        limit = vwapVal)

// ── Visuals ──────────────────────────────────────────────────────────────────
plot(vwapVal,   "VWAP",    color.new(color.orange, 0),  linewidth=2)
p1 = plot(upperBand, "Upper", color.new(color.red,   40))
p2 = plot(lowerBand, "Lower", color.new(color.green, 40))
fill(p1, p2, color.new(color.blue, 93))
bgcolor(not inRTH ? color.new(color.gray, 96) : na)
plotshape(longEntry,  "Long",  shape.triangleup,   location.belowbar, color.green, size=size.small)
plotshape(shortEntry, "Short", shape.triangledown, location.abovebar, color.red,   size=size.small)

// ── Alerts (alert() — strategy içinde çalışır) ───────────────────────────────
if longEntry
    alert("NQ VWAP Reversion Long — " + str.tostring(close, "#.##"), alert.freq_once_per_bar)
if shortEntry
    alert("NQ VWAP Reversion Short — " + str.tostring(close, "#.##"), alert.freq_once_per_bar)

Overview

NQ VWAP Reversion [trugurpala] enters long positions when the price crosses above the lower band while the Relative Strength Index indicates oversold conditions, and takes short positions when price crosses below the upper band with overbought momentum. Entries execute only during regular trading hours with a fixed single-contract position size. Exits occur via an Average True Range multiplier stop loss and an automatic market close at session end. User settings adjust standard deviation multipliers, RSI thresholds, and stop-loss sensitivity.

Details

Published by

trugurpala on GitHub

Type

Strategy, Pine Script v6

Draws

On the price chart

Category

Mean reversion, Sessions & time, Oscillators & momentum, Volume

Markets

Indices

Timeframes

M1-M5, M15-H1

Risk Notes

No repainting, lookahead or stacked entries were found in its code or README. That says nothing about how well it works: test it first.

Topics

aialgorithmic-tradingclaude-codecodexcoding-agentsgithub-copilotopen-sourcepine-scriptpine-script-v6technical-analysis

Settings

The inputs you can change from the gear icon on the chart. Defaults are the author's.

SettingTypeDefaultVariable
VWAP Band Multfloat1.5devMult
RSI Filterint14rsiLen
RSI OBfloat65rsiOb
RSI OSfloat35rsiOs
SL Multfloat1.5atrMult
Third-party code. ForexR did not write, test or endorse this script, and the summary above was generated automatically from its code and README. Indicators describe the past, and a strategy's backtest can look better than live trading, especially when a script repaints. Check it in the Strategy Tester and on a demo account before you rely on it.

Similar Pine Scripts

ARR VWAP Intraday

by hasnocool
106 stars

This strategy plots VWAP on the price chart and trades only between a start hour and an end hour. It enters long when VWAP is rising and RSI is above a threshold, and short when VWAP is falling and RSI is below a threshold. If the reversal option is on, it clo

Strategy v4 Oscillators & momentumVolume Repaints
Updated 2 years ago · GPL-3.0 GitHub repository of ARR VWAP Intraday
13 stars

This strategy overlays the price chart to trade DAX futures during European market hours. It calculates exponential and simple moving averages, RSI, MACD, Bollinger Bands, ATR, and realized volatility to simulate VIX levels. Trades execute when session time fi

Strategy v5 Sessions & timeOscillators & momentum
Updated 8 months ago · Custom licence GitHub repository of ClaudeHedge - DAX Session Strategy

RSI Mean Reversion

by GifariKemal
3 stars

This strategy plots entry signals, stop loss, take profit levels, and an information panel directly on the price chart. It combines a relative strength index mean reversion model with ATR percentile thresholds to filter trades based on volatility conditions. T

Strategy v5 Oscillators & momentumVolatility & bands
Updated 3 days ago · MIT GitHub repository of RSI Mean Reversion
2 stars

This mean-reversion trading strategy targets XAUUSD during the Asian trading session. It generates buy signals when price touches the lower Bollinger Band and RSI is oversold, and sell signals when price reaches the upper band and RSI is overbought. Trades are

Strategy v6 Mean reversionSessions & time
Updated 4 months ago · None stated GitHub repository of XAUUSD Mean Reversion Strategy
1 stars

This strategy identifies Initial Balance periods on NQ and ES futures charts using user-defined start and end hours in Eastern Time. It classifies days as narrow or wide based on average range lookback and skips narrow or trending days per settings. Entries tr

Strategy v6 Mean reversionSupport & resistance
Updated 7 months ago · MIT GitHub repository of IB Mean Reversion Fade

More strategys

Trade Your Charts With a Regulated Broker

Compare brokers that connect to TradingView, with spreads, minimum deposits and leverage side by side.

Compare brokers