Logo
OFFLINEPIXEL
/ pinescript-strategies / pine-script-anchored-vwap

$ Pinescript Anchored VWAP (AVWAP)

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.

500+ Clients Helped
100% Satisfaction
Live Trading Ready
⚠️
Trading financial markets carries risk. All content (PineScript code, indicators, strategies) on this website is for educational purposes only. Past performance is not indicative of future results. By using any code or information from this site, you agree that you are solely responsible for your trading decisions. The author disclaims all liability for any losses incurred. To gain from experts experiences, You can always try our Invite Only Scripts
01

What is Anchored VWAP (AVWAP)?

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:

  • Identify true support and resistance: AVWAP lines often act as dynamic support when price is above them and dynamic resistance when price is below them.
  • Gauge market conviction: Price trading significantly above AVWAP indicates strong buying conviction from the anchor point; below indicates selling conviction.
  • Assess 'smart money' positions: Traders can anchor VWAP to major institutional entry points to see if those players are currently profitable or under pressure.
  • Confirm trends and reversals: A break and hold above/below an AVWAP can signal a new trend direction or continuation, while bounces can confirm existing trends.
02

Components and Calculation

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:

  1. Typical Price (TP): TP = (High + Low + Close) / 3
  2. Cumulative TP * Volume: sum(TP * volume) from anchor bar to current bar
  3. Cumulative Volume: sum(volume) from anchor bar to current bar
  4. AVWAP: AVWAP = Cumulative TP * Volume / Cumulative Volume
03

Basic Anchored VWAP Implementation in Pinescript

pine-script@terminal
//@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
$ ✓ Compiled successfully
04

Optimizing Anchored VWAP (AVWAP) Performance

To get the most from Anchored VWAP in Pinescript:

  • Anchor Point Selection: This is the most critical aspect. The effectiveness of AVWAP heavily depends on anchoring it to a genuinely significant event. Common anchor points include:
  • Confluence is Key: AVWAP is a powerful tool, but it's rarely used in isolation. Its signals gain significant strength when they align with other technical analysis tools:
  • Trend Confirmation: Use AVWAP to confirm the trend from the anchor point. If price consistently stays above AVWAP, the uptrend from that anchor is strong. If below, the downtrend is strong.
  • Fair Value Assessment: Consider price relative to AVWAP. If price is far above AVWAP, it might be overextended from the average price paid by recent participants; conversely if far below.
  • Multiple AVWAPs: Some traders plot multiple AVWAPs anchored to different significant events (e.g., one from a recent swing low, another from a major earnings report). This creates a web of dynamic support/resistance.
05

Smart Money Compass

Smart Money Compass

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.

06

Common Anchored VWAP (AVWAP) Pitfalls

  • Anchor Point Subjectivity: Choosing the 'correct' anchor point can be subjective and is crucial for the indicator's effectiveness. An ill-chosen anchor will result in irrelevant levels.
  • Lagging Indicator: Like all moving averages, AVWAP is a lagging indicator. It reflects past price and volume action. It's best used for confirmation and context, not as a predictive signal on its own.
  • False Signals/Whipsaws: In very choppy or range-bound markets, price can repeatedly cross AVWAP, leading to whipsaws and false signals if not combined with other filters or higher timeframe analysis.
  • Over-Reliance: Using AVWAP as the sole decision-making tool without considering the broader market context, fundamental news, or other technical analysis can lead to poor trading decisions.
  • Volume Data Quality: AVWAP relies heavily on accurate volume data. For assets with unreliable or low-quality volume data, AVWAP may be less effective.
  • Misinterpretation in Strong Trends: In very strong, parabolic trends, price might stay far from AVWAP, making it less useful for immediate entry/exit signals but still valuable for assessing overall conviction.
07

Conclusion

Conclusion

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.

Enhance Your Trading

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