Master this powerful technical analysis tool in TradingView's Pinescript that calculates the Volume-Weighted Average Price from a specific, user-defined anchor point, revealing significant support, resistance, and market conviction.
Anchored Volume-Weighted Average Price (AVWAP) is a powerful technical indicator that calculates the Volume-Weighted Average Price (VWAP) starting from a specific, user-defined 'anchor' point on the chart. Unlike the standard VWAP (which typically resets at the start of each trading session), the AVWAP accumulates volume and price data from its anchor point indefinitely, providing a continuous average of the price at which the majority of volume has been traded since that specific event or price level.
The core philosophy behind AVWAP is that major market movements, significant news events, earnings releases, or important swing highs/lows can serve as 'anchors' for new phases of market activity. By tracking the average price paid (weighted by volume) since such an event, traders can infer whether market participants who entered around that anchor point are currently in profit or loss, and identify areas of strong support or resistance.
AVWAP is primarily used by professional and institutional traders to:
The calculation of Anchored VWAP is based on the cumulative sum of (Typical Price * Volume) divided by the cumulative sum of Volume, starting from the designated anchor point. The formula is as follows:
TP = (High + Low + Close) / 3sum(TP * volume) from anchor bar to current barsum(volume) from anchor bar to current barAVWAP = Cumulative TP * Volume / Cumulative Volume//@version=5
indicator("My Anchored VWAP (AVWAP)", overlay=true, max_bars_back=5000)
// --- User Inputs for Anchor Point ---
anchorType = input.string("Time", title="Anchor Type", options=["Time", "Bar Index"])
anchorTime = input.time(timestamp("01 Jan 2024 09:15 +0530"), title="Anchor Date/Time (HH:MM IST)", tooltip="Set a specific date and time for the AVWAP to start from. Format: 'DD Mon YYYY HH:MM +HHMM'")
anchorBarOffset = input.int(200, title="Anchor Bars Back (from current bar)", minval=1, tooltip="Number of bars back from the current bar to set the anchor. Used if 'Anchor Type' is 'Bar Index'.")
resetOnSession = input.bool(false, title="Reset AVWAP on New Session?", tooltip="If true, AVWAP will reset calculation at the start of each new daily session, behaving like a traditional daily VWAP. If false, it continues from its anchor point.")
// --- Plotting Options ---
avwapColor = input.color(color.new(color.blue, 0), title="AVWAP Line Color")
avwapWidth = input.int(2, title="AVWAP Line Width", minval=1, maxval=4)
// --- Calculate Anchor Bar Index ---
var int anchorIdx = na
// Find the anchor bar index based on the chosen anchor type
if anchorType == "Time"
varip bool anchorFound = false
if not anchorFound
for i = 0 to bar_index
if time[i] >= anchorTime
anchorIdx := bar_index[i]
anchorFound := true
break
else
anchorIdx := bar_index - anchorBarOffset
if na(anchorIdx) or anchorIdx < 0
anchorIdx := 0
// --- Calculate AVWAP ---
var float cumulative_tp_volume = 0.0
var float cumulative_volume = 0.0
var float avwap_value = na
var bool isNewSession = false
if resetOnSession
isNewSession := ta.change(time("D"))
if isNewSession
cumulative_tp_volume := 0.0
cumulative_volume := 0.0
float tp = (high + low + close) / 3.0
if bar_index >= anchorIdx
cumulative_tp_volume := cumulative_tp_volume + (tp * volume)
cumulative_volume := cumulative_volume + volume
if cumulative_volume > 0
avwap_value := cumulative_tp_volume / cumulative_volume
else
avwap_value := tp
else
avwap_value := na
cumulative_tp_volume := 0.0
cumulative_volume := 0.0
// --- Plotting AVWAP ---
plot(avwap_value, title="AVWAP", color=avwapColor, linewidth=avwapWidth)
// Optional: Highlight the anchor point visually
anchorPlotColor = color.new(color.white, 20)
plotshape(bar_index == anchorIdx ? high : na, title="Anchor Point", location=location.belowbar, color=anchorPlotColor, style=shape.triangleup, size=size.small, text="Anchor")
// --- Simple Strategy Example (Conceptual) ---
strategy("AVWAP Strategy", overlay=true, initial_capital=10000, default_qty_type=strategy.percent_of_equity, default_qty_value=10)
if not na(avwap_value) and bar_index > anchorIdx
longCondition = ta.crossover(close, avwap_value)
shortCondition = ta.crossunder(close, avwap_value)
if (longCondition)
strategy.entry("Long AVWAP Cross", strategy.long)
if (shortCondition)
strategy.entry("Short AVWAP Cross", strategy.short)
strategy.close("Long AVWAP Cross", when=shortCondition)
strategy.close("Short AVWAP Cross", when=longCondition)
closeAboveAVWAP = close > avwap_value and close[1] <= avwap_value[1]
isNearAVWAP = math.abs(close - avwap_value) / close * 100 < 0.1
longBounceCondition = low < avwap_value and close > avwap_value and closeAboveAVWAP
shortBounceCondition = high > avwap_value and close < avwap_value and not closeAboveAVWAP
To get the most from Anchored VWAP in Pinescript:
AVWAP acts as a compass for institutional and 'smart money' participation. If price is above their average entry (AVWAP), they're profitable; if below, they're under pressure. This provides a unique lens into market conviction.
Anchored VWAP (AVWAP) is an exceptionally powerful and insightful technical analysis tool available in Pinescript for TradingView. By calculating the Volume-Weighted Average Price from a precise, user-defined anchor point, it provides a unique and continuous perspective on market conviction, revealing dynamic support and resistance levels that reflect the collective average entry price of market participants since a significant event. While demanding careful selection of the anchor point and diligent confirmation from price action, volume, and other technical tools, mastering AVWAP can significantly enhance your Pinescript strategies. By integrating this indicator into your trading plan, you can gain a deeper understanding of market dynamics, identify high-probability trading zones, and make more informed decisions based on where the true 'smart money' has transacted.
Get a high-performance Pinescript analysis tool for actionable market insights, designed for traders on the move.
This strategy runs in live mode on TradingView, helping you identify potential opportunities.
Get Pinescript Strategy