OPEN-SOURCE SCRIPT

Auto AVWAP - Core and Adaptive Levels

671
Auto AVWAP Core and Adaptive Levels

This indicator plots automatically anchored Volume Weighted Average Price levels designed to represent dynamic support and resistance.

It expands the traditional Auto AVWAP concept into a multi-level structure composed of:

- Core AVWAPs: the primary active support and resistance references.
- Adaptive AVWAPs: additional levels anchored at subsequently confirmed market swings.
- Developing candidates: optional previews of potential Adaptive anchors.

The objective is to preserve relevant volume-weighted references while allowing new AVWAPs to emerge during persistent directional moves. This can be particularly useful when an older AVWAP remains structurally relevant but becomes too distant from current price to represent nearby support or resistance.

Core calculation

Each AVWAP is calculated as:

AVWAP = Sum(Price × Volume) / Sum(Volume)

The indicator can use:

- High for resistance AVWAP calculations.
- Low for support AVWAP calculations.

When “Use High/Low instead of HLC3” is disabled, both directions use:

HLC3 = (High + Low + Close) / 3

Using High and Low generally creates greater separation between support and resistance AVWAPs. HLC3 produces a more conventional volume-weighted average.

Core AVWAPs

The indicator maintains one active Core AVWAP in each direction:

- Core Resistance AVWAP.
- Core Support AVWAP.

The Core Resistance AVWAP is violated when the selected violation source remains above it for the configured number of consecutive bars.

The Core Support AVWAP is violated when the selected violation source remains below it for the configured number of consecutive bars.

When a Core AVWAP reaches its violation threshold:

1) The active Core AVWAP stops immediately.
2) Its completed historical segment remains visible.
3) Its accumulators stop receiving new price and volume data.
4) The indicator waits for a confirmed replacement anchor.
5) The confirmed candidate becomes the new Core AVWAP.

This separates invalidation from replacement. A violated Core AVWAP is not kept active merely because its replacement has not yet been confirmed.

Adaptive AVWAPs

Adaptive AVWAPs provide additional support and resistance references during extended trends.

A new Adaptive AVWAP can be considered when:

- price has moved a configurable ATR distance from the newest valid AVWAP;
- the minimum number of bars between anchors has elapsed;
- a qualifying Stochastic RSI episode occurs;
- price reacts sufficiently from the candidate extreme;
- the selected top or bottom confirmation is completed;
- the anchor satisfies the configured spacing and progression rules;
- and an Adaptive AVWAP slot is available.

Each Adaptive AVWAP:

- begins at its own confirmed top or bottom;
- maintains independent price-volume accumulators;
- remains independent from the Core and other Adaptive AVWAPs;
- has its own consecutive-violation counter;
- remains active while respected;
- and stops only when its individual violation rule is satisfied.

The indicator supports up to 10 Adaptive AVWAPs per direction.

Adaptive creation distance

“Distance required from newest AVWAP (ATR)” determines how far price must move from the newest valid AVWAP before the indicator begins searching for an additional Adaptive anchor.

A lower value:

- creates Adaptive AVWAPs more frequently;
- keeps references closer to price;
- and may produce more overlapping levels.

A higher value:

- produces fewer Adaptive AVWAPs;
- requires greater separation from existing levels;
- and emphasizes larger market movements.

Anchor spacing and timing

“Minimum spacing between anchors (ATR)” prevents new Adaptive anchors from being created too close to the newest valid anchor.

“Minimum bars between anchors” imposes an additional time-based separation.

These controls work together with the creation-distance requirement to reduce redundant AVWAPs.

Progressive anchors

When “Require progressively higher lows / lower highs” is enabled:

- Adaptive support anchors must form at progressively higher lows.
- Adaptive resistance anchors must form at progressively lower highs.

This setting emphasizes directional progression.

When disabled, the indicator can accept sufficiently separated anchors that are not strictly progressive. This may be useful when a trend experiences a deeper correction before resuming.

Top and bottom confirmation

The indicator provides three confirmation modes.

Reaction only

The candidate requires:

- the relevant Stochastic RSI reversal;
- and a minimum price reaction measured in ATR.

This is the fastest and most sensitive mode.

Pivot confirmed

In addition to the required reaction, the candidate extreme must remain unbroken for the configured number of bars.

This reduces anchors generated from brief or unstable extremes.

Pivot + Structure break

This is the default and most selective mode.

A resistance anchor requires:

- an overbought Stochastic RSI episode;
- a candidate high;
- a bearish K/D reversal;
- the configured downward reaction in ATR;
- the high to remain unbroken for the required number of bars;
- and a close below the microstructure low captured around the extreme.

A support anchor requires the inverse sequence:

- an oversold Stochastic RSI episode;
- a candidate low;
- a bullish K/D reversal;
- the configured upward reaction in ATR;
- the low to remain unbroken for the required number of bars;
- and a close above the corresponding microstructure high.

All confirmation events must belong to the same candidate episode.

Candidate expiration

Unconfirmed candidates expire after the configured timeout.

When a candidate expires:

- its accumulated state is cleared;
- it cannot be confirmed much later;
- and it does not produce a historical AVWAP.

This prevents stale oscillator events from generating delayed or unrelated anchors.

Core and Adaptive invalidation

Every active Core and Adaptive AVWAP maintains an independent consecutive-violation counter.

The violation source can be selected from:

- Close: uses the candle close.
- Open: uses the candle open.
- High/Low: uses High for resistance violations and Low for support violations.

A resistance AVWAP is violated when the selected source remains above it.

A support AVWAP is violated when the selected source remains below it.

For example, with six consecutive bars selected:

- a resistance AVWAP stops after six consecutive violations above it;
- a support AVWAP stops after six consecutive violations below it.

If a bar does not violate a level, that AVWAP’s counter returns to zero.

The “Count only closed bars” option prevents an unfinished real-time candle from temporarily advancing the violation counter.

Historical origin display

Candidates remain hidden while unconfirmed.

When a Core or Adaptive candidate is confirmed, the indicator reconstructs and displays the AVWAP from its true anchor rather than displaying it only from the confirmation candle.

This preserves the complete origin and development of confirmed AVWAPs without displaying candidates that were rejected or expired.

The reconstructed origin uses the same direction, generation color, transparency, width, and approximate dotted style as the active AVWAP.

AVWAP interaction alerts

The indicator monitors every active Core and Adaptive AVWAP independently for three types of price interaction:

- Touch.
- Directional rejection.
- Failed violation.

These events are separated by direction into support and resistance alerts.

Touch

A touch occurs when the candle enters a configurable ATR-based zone around an active AVWAP.

The interaction zone is defined as:

AVWAP ± Touch Tolerance × ATR

A touch does not require the candle to close on a particular side of the AVWAP.

To reduce repeated notifications, a touch alert is triggered only when price enters the interaction zone. Additional candles remaining inside the same zone do not generate new touch alerts. The touch state resets after price leaves the zone.

Directional rejection

A rejection requires more than a simple touch.

The candle must:

- interact with the AVWAP;
- return to the valid side;
- close at least the configured ATR distance away from the AVWAP;
- and form in the expected directional candle color.

A resistance AVWAP rejection requires:

- the candle to touch or penetrate the resistance interaction zone;
- the candle to close back below the resistance AVWAP;
- the close to finish at least the configured rejection distance below the AVWAP;
- and a bearish candle, where Close is below Open.

A support AVWAP rejection requires:

- the candle to touch or penetrate the support interaction zone;
- the candle to close back above the support AVWAP;
- the close to finish at least the configured rejection distance above the AVWAP;
- and a bullish candle, where Close is above Open.

Doji candles, where Close equals Open, are not classified as rejection candles.

This directional-candle requirement is intended to distinguish an actual reaction from a candle that merely crosses or finishes near an AVWAP.

Failed violation

A failed violation occurs when price begins violating an AVWAP but returns to the valid side before reaching the number of consecutive bars required for full invalidation.

For a resistance AVWAP:

1) Price evaluates above the AVWAP according to the selected violation source.
2) A partial consecutive-violation count begins.
3) The count reaches the configured minimum partial-violation requirement.
4) Price returns to the valid side before reaching full invalidation.

For a support AVWAP, the inverse sequence applies below the level.

A failed violation does not require the reversal candle to be bullish or bearish. Its purpose is to identify an unsuccessful multi-bar violation sequence rather than a single-candle rejection pattern.

Interaction alert settings

Touch tolerance (ATR)

Defines the size of the interaction zone surrounding every active AVWAP.

A lower value requires price to approach the AVWAP more precisely.

A higher value detects interactions occurring within a wider volatility-adjusted area.

Minimum rejection close distance (ATR)

Defines how far the rejection candle must close back on the valid side of the AVWAP.

Increasing this setting requires a stronger reaction before a rejection alert is generated.

Minimum partial violation bars

Defines how many consecutive violation bars must occur before a return to the valid side can be classified as a failed violation.

For example:

- A value of 1 detects a failure after any single partial violation.
- A value of 2 requires at least two consecutive violation bars.
- The partial count must remain below the full invalidation threshold.

Confirm interactions only on closed bars

When enabled, touch, rejection, and failed-violation events are confirmed only after the candle closes.

This prevents temporary intrabar movements from producing interaction alerts that may disappear before the bar is complete.

Plots

The indicator can display:

- Core Resistance AVWAP.
- Core Support AVWAP.
- Up to 10 Adaptive Resistance AVWAPs.
- Up to 10 Adaptive Support AVWAPs.
- Optional developing Adaptive resistance candidate.
- Optional developing Adaptive support candidate.

Core AVWAPs use stronger red and green styling.

Adaptive resistance AVWAPs use orange, fuchsia, purple, and related shades.

Adaptive support AVWAPs use blue, aqua, teal, and related shades.

Developing candidates are hidden by default to reduce chart noise.

Alerts

The indicator includes alert conditions for:

- New Adaptive resistance AVWAP.
- New Adaptive support AVWAP.
- Resistance AVWAP invalidation.
- Support AVWAP invalidation.
- Resistance AVWAP touch.
- Support AVWAP touch.
- Resistance AVWAP rejection.
- Support AVWAP rejection.
- Failed resistance AVWAP violation.
- Failed support AVWAP violation.

Because TradingView alert conditions cannot dynamically create a separate selectable alert for every array slot, interaction alerts are aggregated by event type and direction.

For example, “Support AVWAP rejection” indicates that price rejected at least one active Core or Adaptive Support AVWAP. It does not identify the individual AVWAP slot in the static alert message.

How to use

- Treat support AVWAPs as potential dynamic support references.
- Treat resistance AVWAPs as potential dynamic resistance references.
- Use Core AVWAPs as the primary active market references.
- Use Adaptive AVWAPs to monitor newer levels formed during extended trends.
- Reduce the ATR creation distance to capture more intermediate anchors.
- Increase it to retain only more widely separated Adaptive levels.
- Use “Pivot + Structure break” when stronger confirmation is preferred.
- Use “Reaction only” when faster but less selective anchoring is desired.
- Increase the consecutive-violation requirement to make levels more persistent.
- Prefer confirmed closes when the objective is to reduce intrabar noise.
- Use touch alerts as early notifications that price is interacting with an active AVWAP.
- Use directional rejection alerts when a candle touches the level and confirms a reaction in the expected direction.
- Use failed-violation alerts to identify unsuccessful attempts to invalidate an AVWAP.
- A rejection and a failed violation represent different events: rejection is a directional candle pattern, while failed violation is the cancellation of a partial multi-bar violation sequence.
- Increase the rejection distance when stronger reactions are preferred.
- Increase the minimum partial-violation count to filter isolated failed breaks.
- Adjust settings according to the symbol, timeframe, session structure, liquidity, and volatility regime.

Example starting configuration

For an intraday chart, a possible starting configuration is:

- Maximum Adaptive AVWAPs per direction: 3 to 5
- ATR length: 14
- Distance required from newest AVWAP: 1.0 to 2.0 ATR
- Minimum bars between anchors: 12 to 24
- Minimum spacing between anchors: 0.5 to 1.0 ATR
- Required price reaction: 0.5 ATR
- Confirmation mode: Pivot + Structure break
- Bars without a new extreme: 3
- Microstructure lookback: 5
- Consecutive bars to invalidate: 3 to 6
- Violation source: Close
- Count only closed bars: Enabled
- Touch tolerance: 0.10 ATR
- Minimum rejection close distance: 0.15 ATR
- Minimum partial violation bars: 1
- Confirm interactions only on closed bars: Enabled

These values are starting points rather than universal settings.

Open-source reuse and credits

This script is based on the open-source indicator:

“Auto AVWAP (Anchored-VWAP)” by Electrified.

Original source:
Auto AVWAP (Anchored-VWAP)


This version substantially extends and changes the original lifecycle model by adding:

1) Pine Script v6 implementation.
2) Separate Core and Adaptive AVWAP architecture.
3) Up to 10 independent Adaptive AVWAPs per direction.
4) Independent price-volume accumulators for every active level.
5) Independent consecutive-violation counters.
6) Immediate invalidation separated from replacement confirmation.
7) ATR-based Adaptive AVWAP search.
8) Configurable distance and spacing between anchors.
9) Configurable minimum time between Adaptive anchors.
10) Optional progressively higher-low and lower-high requirements.
11) Isolated Stochastic RSI candidate episodes.
12) Reaction, pivot, and microstructure confirmation modes.
13) Candidate expiration to prevent stale confirmations.
14) Historical reconstruction from each confirmed anchor.
15) Consistent styling before and after confirmation.
16) Separate creation and invalidation alerts.
17) Independent lifecycle management for Core and Adaptive levels.
18) ATR-normalized interaction zones for all active Core and Adaptive AVWAPs.
19) Touch alerts with zone-entry latching to reduce repeated notifications.
20) Directional rejection alerts requiring bearish resistance-rejection candles and bullish support-rejection candles.
21) Failed-violation alerts based on incomplete consecutive-violation sequences.
22) Configurable closed-bar confirmation for AVWAP interaction events.

Limitations

- AVWAPs are analytical references, not guaranteed support or resistance.
- Stronger confirmation reduces false anchors but introduces additional delay.
- Lower ATR-distance settings may produce many overlapping Adaptive AVWAPs.
- Higher distance and spacing settings may omit useful intermediate swings.
- Stochastic RSI behavior depends on the selected symbol and timeframe.
- Volume quality varies across markets and data providers.
- HLC3 can make support and resistance AVWAPs appear closer together.
- Touch and rejection zones are ATR-based and may require adjustment across volatility regimes.
- Directional rejection alerts describe candle behavior around an AVWAP; they do not guarantee continued movement away from the level.
- Failed-violation alerts identify an incomplete invalidation sequence, but price may attempt another violation shortly afterward.
- Aggregated interaction alerts identify the event type and direction but do not specify the individual Core or Adaptive AVWAP slot.
- Historical reconstruction uses TradingView drawing objects and may not render identically to native plot points.
- TradingView imposes limits on historical drawing objects.
- Historical behavior does not guarantee future results.
- This is a decision-support tool, not a guaranteed-profit system.
- Risk management is required.

免責事項

これらの情報および投稿は、TradingViewが提供または承認する金融、投資、取引、またはその他の種類の助言もしくは推奨であることを意図したものではなく、またこれらに該当するものでもありません。詳細は利用規約をご覧ください。