//@version=6
indicator("GM VWAP Reversal - Candle Confirmation v1.2", shorttitle="GM VWAP Reversal", overlay=true, max_lines_count=20)
// v1.2: Fixed calculation timeframe, independent of the display chart.
// Auto: Session=1 minute; Week/Month/Quarter=1 hour; Year/Decade/Century=1 day.
// Confirmed mode uses the previous calculation candle; Live uses the open one.
// C1/C2, entry confirmations and ADX still run on the display chart.
// VWAP mean reversion using the user's leading / C1 / C2 / entry sequence.
// Defaults are starting parameters for testing, not optimized settings.
//
// SELL:
// 1. A confirmed CLOSE above the outer VWAP band arms the leading move.
// It can continue for many candles.
// 2. A later bearish candle is C1.
// 3. A later bearish candle closing below C1's CLOSE is C2.
// C2's CLOSE becomes the fixed entry reference.
// 4. A LATER candle closing strictly below C2's close can signal SELL.
// It must still close at/above the upper inner band (default +1 sigma).
// BUY is the exact opposite below VWAP (default entry at/below -1 sigma).
// Intervening candles are allowed. C3 does not need a specific body color.
//
// Only confirmed closes arm, advance, cancel or trigger setups. Wick sweeps
// and closes exactly on the entry reference do not trigger an entry.
// One signal per excursion; a close at/beyond VWAP rearms that side.
// A new VWAP anchor clears pending setups, rearming locks and latest lines.
// No entry is allowed after the same candle has closed at/beyond VWAP.
//
// The first qualifying entry close consumes the setup, even if the zone
// check or optional ADX filter rejects it. There are no delayed filter entries.
// ADX rejects entries only when above its threshold AND rising.
// Candle direction is determined from open/close, never chart colors.
//
// VWAP uses volume from the selected calculation timeframe on this symbol.
// Default source is Close. HLC3 can be selected for a typical-price VWAP.
// The built-in ta.vwap() supplies the standard-deviation bands; they are
// adaptive distances, not calibrated probabilities of a reversal.
// Session anchor follows the symbol's daily session boundary, not the
// chart's display timezone. Week/Month/Quarter/Year anchors follow the feed.
// Decade = calendar blocks such as 2020-2029; Century = 2000-2099.
// These are reset periods, not rolling lookbacks of 10 or 100 years.
// Source history is requested explicitly, independently of chart bar count.
// Provider/plan history limits still apply. The dashboard shows the actual start.
// Confirmed mode publishes the previous source candle at the next source open.
// Live mode can repaint historical bands/signals after reload when the source
// timeframe is higher than the chart, even though entries require chart closes.
// On coarser charts, each bar can display only one source snapshot.
// Compare current values on the same symbol, source settings and timestamp.
// Dashed target = VWAP frozen at signal time; live VWAP keeps changing.
// Setup close extreme is an invalidation reference, not a protective order.
// This indicator does not execute orders or measure trading performance.
//
// Pine v6 docs:
// https://www.tradingview.com/pine-script-reference/v6/#fun_ta.vwap
// https://www.tradingview.com/pine-script-docs/concepts/bar-states/
// https://www.tradingview.com/support/solutions/43000502018-volume-weighted-average-price-vwap/
// INPUTS
anchorChoice = input.string("Session", "VWAP Anchor", options=["Session", "Week", "Month", "Quarter", "Year", "Decade", "Century"], group="VWAP and Zones", tooltip="Session resets at the symbol's daily session boundary. Quarter = Jan/Apr/Jul/Oct. Decade = 2020-2029, 2030-2039, etc. Century = 2000-2099, etc. VWAP, bands and setups share this anchor. Calculation uses a fixed timeframe independent of the chart. Source history may be partial; see VWAP from in the dashboard.")
calcChoice = input.string("Auto", "Calculation Timeframe", options=["Auto", "1 minute", "5 minutes", "15 minutes", "1 hour", "4 hours", "1 day"], group="VWAP and Zones", tooltip="Auto depends only on the anchor, never on the chart: Session=1 minute; Week/Month/Quarter=1 hour; Year/Decade/Century=1 day. Use the same setting on all charts. Source candles must be shorter than the anchor. Daily-sampled VWAP is an approximation based on daily price and volume, not tick-by-tick VWAP.")
updateMode = input.string("Confirmed", "VWAP Updates", options=["Confirmed", "Live"], group="VWAP and Zones", tooltip="Confirmed uses the previous closed calculation candle and updates at the next calculation candle's open. With daily calculations it updates once per trading day. Live includes the open calculation candle; historical bands and signals may change after reload. C1/C2 confirmations still use chart candles.")
sourceChoice = input.string("Close", "VWAP Source", options=["Close", "HLC3"], group="VWAP and Zones", tooltip="Close is the default. HLC3 uses (high + low + close) / 3. Setup and entry conditions always use candle closes.")
bandMultiplier = input.float(2.0, "Outer Band (Standard Deviations)", minval=0.2, step=0.1, group="VWAP and Zones", tooltip="A confirmed close outside this band starts the leading move.")
entryZoneMultiplier = input.float(1.0, "Minimum Entry Distance from VWAP", minval=0.1, step=0.1, group="VWAP and Zones", tooltip="Standard deviations. SELL must close at/above the upper inner band; BUY at/below the lower inner band. Must be less than the outer band. This prevents signals near the middle.")
minAnchorBars = input.int(10, "Minimum Bars after VWAP Reset", minval=2, maxval=500, group="VWAP and Zones", tooltip="Wait for this many chart candles in the anchor before starting setups.")
maxWaitBars = input.int(30, "Max Bars After C1", minval=2, maxval=300, group="Setup", tooltip="Number of later candles allowed after the first reversal candle, including the wait for C2 and the entry close. The leading move itself may last longer.")
useAdxFilter = input.bool(false, "Use ADX Filter", group="ADX Filter", tooltip="At the entry candle's close, block signals if ADX is above the threshold and rising. A blocked setup is consumed. Turn off to compare against the original candle-entry rules.")
diLength = input.int(14, "DI Length", minval=1, maxval=100, group="ADX Filter")
adxSmoothing = input.int(14, "ADX Smoothing", minval=1, maxval=100, group="ADX Filter")
adxThreshold = input.float(25.0, "Strong ADX Threshold", minval=0.0, maxval=100.0, step=0.5, group="ADX Filter")
showMean = input.bool(true, "Show VWAP", group="Display")
showBands = input.bool(true, "Show VWAP Bands and Entry Zones", group="Display")
showEntryLevel = input.bool(true, "Show Entry Level", group="Display")
showTarget = input.bool(true, "Show VWAP Target at Signal", group="Display")
showInvalidation = input.bool(false, "Show Setup Invalidation Level", group="Display")
showSignals = input.bool(true, "Show BUY / SELL", group="Display")
showSetupMarks = input.bool(false, "Show Leading / C1 / C2 Marks", group="Display", tooltip="L = first close outside the band. C1 = first reversal candle. C2 = candle whose CLOSE supplies the fixed entry level. X = an entry blocked by the zone or ADX filter.")
showDashboard = input.bool(false, "Show Dashboard", group="Display")
signalLineBars = input.int(20, "Keep Signal Lines for Bars", minval=1, maxval=200, group="Display", tooltip="Latest setup only. After a signal, its lines remain for this many bars, or until a new setup starts. Historical BUY/SELL markers remain visible.")
buyColor = input.color(color.rgb(0, 200, 160), "BUY Color", group="Colors")
sellColor = input.color(color.rgb(240, 75, 110), "SELL Color", group="Colors")
meanColor = input.color(color.rgb(255, 183, 77), "VWAP Color", group="Colors")
// FIXED-SOURCE VWAP AND STANDARD-DEVIATION ZONES
string anchorTf = switch anchorChoice
"Session" => "1D"
"Week" => "1W"
"Month" => "1M"
"Quarter" => "3M"
=> "12M"
int anchorYears = anchorChoice == "Decade" ? 10 : anchorChoice == "Century" ? 100 : 1
float anchorSeconds = timeframe.in_seconds(anchorTf) * anchorYears
string autoCalcTf = switch anchorChoice
"Session" => "1"
"Week" => "60"
"Month" => "60"
"Quarter" => "60"
=> "1D"
string calcTf = switch calcChoice
"1 minute" => "1"
"5 minutes" => "5"
"15 minutes" => "15"
"1 hour" => "60"
"4 hours" => "240"
"1 day" => "1D"
=> autoCalcTf
bool confirmedSource = updateMode == "Confirmed"
bool sourceBelowChart = timeframe.in_seconds(calcTf) < timeframe.in_seconds()
if barstate.isfirst
if timeframe.in_seconds(calcTf) >= anchorSeconds
runtime.error("Calculation Timeframe must be shorter than VWAP Anchor. Use Auto, or choose a smaller calculation timeframe.")
if entryZoneMultiplier >= bandMultiplier
runtime.error("Minimum Entry Distance must be smaller than Outer Band.")
// This function runs IN THE REQUESTED SOURCE CONTEXT. Do not calculate a
// chart VWAP first and request only its price/volume afterwards.
f_anchorKey() =>
int annualYear = year(time_close("12M") - 1)
int calendarBlock = int(math.floor(annualYear / anchorYears)) * anchorYears
anchorYears > 1 ? timestamp(syminfo.timezone, calendarBlock, 1, 1, 0, 0) : time(anchorTf)
f_sourceVWAP(bool usePrevious) =>
int key = f_anchorKey()
bool reset = barstate.isfirst or key != key[1]
var int startedAt = na
if reset
startedAt := time
float src = sourceChoice == "Close" ? close : hlc3
[v, hi, lo] = ta.vwap(src, reset, 1.0)
float sd = math.max(hi - v, 0.0)
float allVolume = ta.cum(nz(volume))
// Offset every returned field together, so dates and values always match.
[usePrevious ? v[1] : v, usePrevious ? sd[1] : sd, usePrevious ? key[1] : key, usePrevious ? startedAt[1] : startedAt, usePrevious ? time_close[1] : time_close, usePrevious ? allVolume[1] : allVolume]
// Confirmed HTF/equal-TF requests: offset + lookahead_on, no future prices.
// LTF requests: lookahead_off selects the LAST source snapshot in each chart
// bar. The VWAP itself is accumulated over ALL requested source bars.
// A fixed history request prevents short chart history from defining VWAP.
[mean, sigma, sourceKey, sourceStart, sourceAsOf, sourceTotalVolume] = request.security(syminfo.tickerid, calcTf, f_sourceVWAP(confirmedSource), gaps=barmerge.gaps_off, lookahead=confirmedSource and not sourceBelowChart ? barmerge.lookahead_on : barmerge.lookahead_off, calc_bars_count=100000)
int currentKey = f_anchorKey()
bool chartAnchorChanged = not na(currentKey[1]) and currentKey != currentKey[1]
bool sourceAnchorChanged = not na(sourceKey) and (na(sourceKey[1]) or sourceKey != sourceKey[1])
bool newAnchor = barstate.isfirst or chartAnchorChanged or sourceAnchorChanged
// In Confirmed mode the previous period can remain visible until the first
// source candle of the new period closes. Block entries against that old key.
bool sourceIsCurrent = not na(sourceKey) and sourceKey == currentKey
float upperBand = mean + sigma * bandMultiplier
float lowerBand = mean - sigma * bandMultiplier
float upperEntry = mean + sigma * entryZoneMultiplier
float lowerEntry = mean - sigma * entryZoneMultiplier
float distanceSigma = sigma > 0 ? (close - mean) / sigma : na
int anchorBars = ta.barssince(newAnchor) + 1
bool hasVolume = not na(volume) and volume > 0
bool dataReady = hasVolume and sourceIsCurrent and not na(mean) and not na(sigma) and sigma >= syminfo.mintick and anchorBars >= minAnchorBars
bool bullish = close > open
bool bearish = close < open
if barstate.islast and not na(sourceTotalVolume) and sourceTotalVolume == 0
runtime.error("This symbol has no usable volume on the calculation timeframe.")
// ADX value can update live, but its gate is read only inside the confirmed
// entry block. No +DI/-DI directional condition is used.
[diPlus, diMinus, adx] = ta.dmi(diLength, adxSmoothing)
bool adxReady = not na(adx) and not na(adx[1])
bool adxStrongRising = adxReady and adx > adxThreshold and adx > adx[1]
bool adxAllowsEntry = not useAdxFilter or (adxReady and not adxStrongRising)
meanPlot = plot(showMean ? mean : na, "VWAP", color=meanColor, linewidth=2)
upperPlot = plot(showBands ? upperBand : na, "Upper Outer Band", color=color.new(sellColor, 20), linewidth=1)
lowerPlot = plot(showBands ? lowerBand : na, "Lower Outer Band", color=color.new(buyColor, 20), linewidth=1)
upperEntryPlot = plot(showBands ? upperEntry : na, "Upper Entry Limit", color=color.new(sellColor, 75), linewidth=1)
lowerEntryPlot = plot(showBands ? lowerEntry : na, "Lower Entry Limit", color=color.new(buyColor, 75), linewidth=1)
fill(upperEntryPlot, upperPlot, color=showBands ? color.new(sellColor, 88) : na, title="Upper Reversal Zone")
fill(lowerEntryPlot, lowerPlot, color=showBands ? color.new(buyColor, 88) : na, title="Lower Reversal Zone")
f_price(float price) =>
na(price) ? "-" : str.tostring(price, format.mintick)
// ENGINE STATE
// phase: 0 = idle, 1 = leading, 2 = C1 found, 3 = fixed level ready.
// direction: -1 = waiting for SELL, +1 = waiting for BUY.
var int phase = 0
var int direction = 0
var int leadingBar = na
// Highest / lowest CLOSE during the leading and confirmation phase.
var float leadingExtreme = na
var int c1Bar = na
var float c1Close = na
var int referenceBar = na
var float entryLevel = na
var bool shortRearmed = true
var bool longRearmed = true
var float lastMeanTarget = na
var float lastSignalClose = na
// Events start false on EVERY update, including updates of the live candle.
bool newLeading = false
bool newC1 = false
bool newC2 = false
bool setupCancelled = false
bool buySignal = false
bool sellSignal = false
bool buyBlocked = false
bool sellBlocked = false
// ENGINE BEGIN
// Resets are evaluated even when the new anchor has not warmed up.
// Missing/zero-volume candles cancel a pending sequence.
if barstate.isconfirmed and (newAnchor or not dataReady)
phase := 0
direction := 0
leadingBar := na
leadingExtreme := na
c1Bar := na
c1Close := na
referenceBar := na
entryLevel := na
setupCancelled := true
if newAnchor
shortRearmed := true
longRearmed := true
lastMeanTarget := na
lastSignalClose := na
if barstate.isconfirmed and dataReady
// A close at/beyond the VWAP resets that side. A wick touch is ignored.
// Check this before entries to avoid signalling after a close past mean.
if close <= mean
shortRearmed := true
if close >= mean
longRearmed := true
if phase > 0
bool meanReached = false
if direction == -1
meanReached := close <= mean
else
meanReached := close >= mean
bool expired = not na(c1Bar) and bar_index - c1Bar > maxWaitBars
bool invalidated = false
if phase == 3
if direction == -1
invalidated := close > leadingExtreme
else
invalidated := close < leadingExtreme
if meanReached or expired or invalidated
phase := 0
direction := 0
setupCancelled := true
// An excursion starts at the first eligible close outside an outer band.
// After a mean reset, a later close outside a band starts a fresh setup.
// The arming candle cannot also supply C1.
if phase == 0
if close > upperBand and shortRearmed
phase := 1
direction := -1
leadingBar := bar_index
leadingExtreme := close
c1Bar := na
c1Close := na
referenceBar := na
entryLevel := na
shortRearmed := false
newLeading := true
else if close < lowerBand and longRearmed
phase := 1
direction := 1
leadingBar := bar_index
leadingExtreme := close
c1Bar := na
c1Close := na
referenceBar := na
entryLevel := na
longRearmed := false
newLeading := true
// Only ONE of these phases can advance per candle.
if phase == 1
if direction == -1
leadingExtreme := math.max(leadingExtreme, close)
if bar_index > leadingBar and bearish
phase := 2
c1Bar := bar_index
c1Close := close
newC1 := true
else
leadingExtreme := math.min(leadingExtreme, close)
if bar_index > leadingBar and bullish
phase := 2
c1Bar := bar_index
c1Close := close
newC1 := true
else if phase == 2
bool leadingResumed = false
bool c2Ready = false
if direction == -1
leadingResumed := close > leadingExtreme
leadingExtreme := math.max(leadingExtreme, close)
c2Ready := bearish and close < c1Close
else
leadingResumed := close < leadingExtreme
leadingExtreme := math.min(leadingExtreme, close)
c2Ready := bullish and close > c1Close
if leadingResumed
// A close beyond the old extreme restarts the reversal sequence.
// Wick sweeps alone do not restart it.
phase := 1
c1Bar := na
c1Close := na
else if bar_index > c1Bar and c2Ready
phase := 3
referenceBar := bar_index
entryLevel := close
newC2 := true
// Both entryLevel and leadingExtreme are now fixed.
else if phase == 3
bool entryClose = false
if direction == -1
entryClose := close < entryLevel
else
entryClose := close > entryLevel
if bar_index > referenceBar and entryClose
bool entryInZone = false
if direction == -1
entryInZone := close >= upperEntry
else
entryInZone := close <= lowerEntry
if entryInZone and adxAllowsEntry
buySignal := direction == 1
sellSignal := direction == -1
lastSignalClose := close
lastMeanTarget := mean
else
buyBlocked := direction == 1
sellBlocked := direction == -1
phase := 0
direction := 0
// Consume the first qualifying close even if zone/ADX rejects it.
// Neither a moving zone nor ADX can create a delayed entry.
// Prices are retained for drawings/alerts until the next arm.
// ENGINE END
// LATEST SETUP LINES
var line entryLine = na
var line targetLine = na
var line invalidationLine = na
var int linesExpireBar = na
if barstate.isconfirmed
if newLeading or setupCancelled or buyBlocked or sellBlocked
if not na(entryLine)
line.delete(entryLine)
if not na(targetLine)
line.delete(targetLine)
if not na(invalidationLine)
line.delete(invalidationLine)
entryLine := na
targetLine := na
invalidationLine := na
linesExpireBar := na
if newC2
color setupColor = direction == 1 ? buyColor : sellColor
if showEntryLevel
entryLine := line.new(bar_index, entryLevel, bar_index + 1, entryLevel, xloc=xloc.bar_index, color=setupColor, width=2)
if showInvalidation
invalidationLine := line.new(bar_index, leadingExtreme, bar_index + 1, leadingExtreme, xloc=xloc.bar_index, color=color.new(setupColor, 50), style=line.style_dotted)
if phase == 3
if not na(entryLine)
line.set_x2(entryLine, bar_index + 1)
if not na(invalidationLine)
line.set_x2(invalidationLine, bar_index + 1)
if buySignal or sellSignal
linesExpireBar := bar_index + signalLineBars
if not na(entryLine)
line.set_x2(entryLine, linesExpireBar)
if not na(invalidationLine)
line.set_x2(invalidationLine, linesExpireBar)
if showTarget
targetLine := line.new(bar_index, lastMeanTarget, linesExpireBar, lastMeanTarget, xloc=xloc.bar_index, color=meanColor, style=line.style_dashed, width=2)
if not na(linesExpireBar) and bar_index > linesExpireBar
if not na(entryLine)
line.delete(entryLine)
if not na(targetLine)
line.delete(targetLine)
if not na(invalidationLine)
line.delete(invalidationLine)
entryLine := na
targetLine := na
invalidationLine := na
linesExpireBar := na
// SIGNALS AND OPTIONAL SEQUENCE MARKS
plotshape(showSignals and buySignal, title="BUY Mean Reversion", style=shape.triangleup, location=location.belowbar, color=buyColor, textcolor=buyColor, size=size.small, text="BUY")
plotshape(showSignals and sellSignal, title="SELL Mean Reversion", style=shape.triangledown, location=location.abovebar, color=sellColor, textcolor=sellColor, size=size.small, text="SELL")
plotshape(showSetupMarks and newLeading and direction == -1, title="Leading Up", style=shape.circle, location=location.abovebar, color=sellColor, textcolor=sellColor, size=size.tiny, text="L")
plotshape(showSetupMarks and newLeading and direction == 1, title="Leading Down", style=shape.circle, location=location.belowbar, color=buyColor, textcolor=buyColor, size=size.tiny, text="L")
plotshape(showSetupMarks and newC1 and direction == -1, title="Bearish C1", style=shape.circle, location=location.abovebar, color=sellColor, textcolor=sellColor, size=size.tiny, text="C1")
plotshape(showSetupMarks and newC1 and direction == 1, title="Bullish C1", style=shape.circle, location=location.belowbar, color=buyColor, textcolor=buyColor, size=size.tiny, text="C1")
plotshape(showSetupMarks and newC2 and direction == -1, title="SELL Reference C2", style=shape.diamond, location=location.abovebar, color=sellColor, textcolor=sellColor, size=size.tiny, text="C2")
plotshape(showSetupMarks and newC2 and direction == 1, title="BUY Reference C2", style=shape.diamond, location=location.belowbar, color=buyColor, textcolor=buyColor, size=size.tiny, text="C2")
plotshape(showSetupMarks and buyBlocked, title="BUY Blocked by Zone or ADX", style=shape.xcross, location=location.belowbar, color=color.gray, textcolor=color.gray, size=size.tiny, text="X")
plotshape(showSetupMarks and sellBlocked, title="SELL Blocked by Zone or ADX", style=shape.xcross, location=location.abovebar, color=color.gray, textcolor=color.gray, size=size.tiny, text="X")
// OPTIONAL DASHBOARD
var table dash = table.new(position.top_right, 2, 10, bgcolor=color.new(color.black, 10), border_width=1)
if barstate.islast
if showDashboard
string stateText = shortRearmed and longRearmed ? "Waiting for extension" : "Waiting for close at mean"
color stateColor = meanColor
if phase == 1
stateText := direction == -1 ? "Leading up / wait C1" : "Leading down / wait C1"
else if phase == 2
stateText := direction == -1 ? "Bearish C1 / wait C2" : "Bullish C1 / wait C2"
else if phase == 3
stateText := direction == -1 ? "Wait close below level" : "Wait close above level"
if direction != 0
stateColor := direction == 1 ? buyColor : sellColor
if not dataReady
stateText := not sourceIsCurrent ? "Waiting for current anchor data" : hasVolume ? "Waiting for VWAP / band width" : "No volume on this candle"
table.cell(dash, 0, 0, "GM VWAP Reversal", text_color=color.white)
table.cell(dash, 1, 0, "v1.2 | " + timeframe.period, text_color=meanColor)
table.cell(dash, 0, 1, "VWAP (" + anchorChoice + ")", text_color=color.white)
table.cell(dash, 1, 1, f_price(mean), text_color=meanColor)
table.cell(dash, 0, 2, "Distance", text_color=color.white)
table.cell(dash, 1, 2, str.tostring(distanceSigma, "#.00") + " SD", text_color=color.white)
table.cell(dash, 0, 3, "Setup", text_color=color.white)
table.cell(dash, 1, 3, stateText, text_color=stateColor)
table.cell(dash, 0, 4, "Entry level", text_color=color.white)
table.cell(dash, 1, 4, phase == 3 ? f_price(entryLevel) : "-", text_color=stateColor)
table.cell(dash, 0, 5, "Last VWAP target", text_color=color.white)
table.cell(dash, 1, 5, f_price(lastMeanTarget), text_color=meanColor)
string adxText = "OFF"
if useAdxFilter
adxText := not adxReady ? "Warming up" : str.tostring(adx, "#.0") + (adxStrongRising ? " | Block" : " | Allow")
table.cell(dash, 0, 6, "ADX filter (live)", text_color=color.white)
table.cell(dash, 1, 6, adxText, text_color=adxAllowsEntry ? meanColor : color.gray)
table.cell(dash, 0, 7, "Calculation", text_color=color.white)
table.cell(dash, 1, 7, calcTf + " | " + updateMode, text_color=meanColor)
table.cell(dash, 0, 8, "VWAP from (feed)", text_color=color.white)
table.cell(dash, 1, 8, na(sourceStart) ? "No source history" : str.format_time(sourceStart, "yyyy-MM-dd HH:mm", syminfo.timezone), text_color=color.white)
table.cell(dash, 0, 9, confirmedSource ? "Source close (feed)" : "Live source closes", text_color=color.white)
table.cell(dash, 1, 9, na(sourceAsOf) ? "-" : str.format_time(sourceAsOf, "yyyy-MM-dd HH:mm", syminfo.timezone), text_color=color.white)
else
table.clear(dash, 0, 0, 1, 9)
// ALERTS
// Display switches do not disable alerts.
// Create an alert and choose "Any alert() function call" for direction and
// actual prices, or choose one of the individual conditions below.
alertcondition(buySignal, "GM VWAP Reversal BUY", "{{ticker}} {{interval}} | GM VWAP Reversal BUY | Close: {{close}}")
alertcondition(sellSignal, "GM VWAP Reversal SELL", "{{ticker}} {{interval}} | GM VWAP Reversal SELL | Close: {{close}}")
alertcondition(buySignal or sellSignal, "GM VWAP Reversal BUY / SELL", "{{ticker}} {{interval}} | GM VWAP Reversal signal | Close: {{close}}")
if buySignal or sellSignal
string sideText = buySignal ? "BUY" : "SELL"
alert(syminfo.tickerid + " | TF " + timeframe.period + " | " + sideText + " GM VWAP REVERSAL\nSignal close: " + f_price(lastSignalClose) + "\nC2 reference close: " + f_price(entryLevel) + "\nVWAP target at signal: " + f_price(lastMeanTarget) + "\nSetup close extreme: " + f_price(leadingExtreme), alert.freq_once_per_bar_close)
Overview
A setup requires price to close beyond an outer standard deviation band, followed by two consecutive confirmation candles (C1 and C2). A trade signal triggers when a later candle closes past C2 while remaining beyond the minimum entry distance from VWAP. Includes an optional ADX filter to avoid trading into strong trends. Visuals overlay directly on the price chart, plotting bands, entry zones, signal markers, and frozen target levels.
Anchored VWAP with standard deviation bands
Multi-step candle confirmation sequence
Configurable calculation timeframe and anchor periods
The inputs you can change from the gear icon on the chart. Defaults are the author's.
Setting
Type
Default
Variable
VWAP Anchor
string
Session
anchorChoice
Calculation Timeframe
string
Auto
calcChoice
VWAP Updates
string
Confirmed
updateMode
VWAP Source
string
Close
sourceChoice
Outer Band (Standard Deviations)
float
2.0
bandMultiplier
Minimum Entry Distance from VWAP
float
1.0
entryZoneMultiplier
Minimum Bars after VWAP Reset
int
10
minAnchorBars
Max Bars After C1
int
30
maxWaitBars
Use ADX Filter
bool
false
useAdxFilter
DI Length
int
14
diLength
ADX Smoothing
int
14
adxSmoothing
Strong ADX Threshold
float
25.0
adxThreshold
Show all 24 settings
Setting
Type
Default
Variable
Show VWAP
bool
true
showMean
Show VWAP Bands and Entry Zones
bool
true
showBands
Show Entry Level
bool
true
showEntryLevel
Show VWAP Target at Signal
bool
true
showTarget
Show Setup Invalidation Level
bool
false
showInvalidation
Show BUY / SELL
bool
true
showSignals
Show Leading / C1 / C2 Marks
bool
false
showSetupMarks
Show Dashboard
bool
false
showDashboard
Keep Signal Lines for Bars
int
20
signalLineBars
BUY Color
color
color.rgb(0, 200, 160)
buyColor
SELL Color
color
color.rgb(240, 75, 110)
sellColor
VWAP Color
color
color.rgb(255, 183, 77)
meanColor
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.
Mean Reversion Study is an indicator that identifies trade setups combining exponential moving averages, RSI extremes, and engulfing candlestick patterns. It highlights bullish setups when a bullish engulfing candle forms below the EMA while RSI is oversold, a
Exhaustion Reversal identifies potential market exhaustion and reversal points on the price chart by detecting strong force bars followed by price give-back patterns. A force bar is defined by an above-average body reaching recent extreme highs or lows. The sc
Vector Candles is an overlay indicator that recolors price candles using PVSRA volume rules taken from the Traders Reality concept. It compares each bar's volume with the average of the previous ten bars and also checks the product of spread and volume against
Point-Clip Unified Indicator plots breakout and directional labels on the price chart. It scores volume spikes against a volume average, range or opening-range breaks, optional VWAP or session-anchored VWAP, fast and slow EMA trend, and a higher-timeframe EMA
This indicator plots an anchored MIDAS support and resistance curve from launch-anchored volume-weighted price on the price chart. It adds two configurable volume-weighted standard-deviation, ATR, or hybrid bands and a topfinder or bottomfinder accelerated exh
This indicator identifies unusually large candles and high trading volume directly on the price chart. It checks whether the current bar range exceeds the maximum high-low range over a specified lookback period. If the range breaks the record with volume below