OPEN-SOURCE SCRIPT

Anchored VWAP Origin Chronicle - Manual Swing High and Low

2 897
Overview

Anchored VWAP Origin Chronicle is an open-source chart overlay for studying chart-reported volume-weighted price from three independently managed origins:

* one manually selected chart point;
* the latest accepted, confirmed swing-high origin;
* the latest accepted, confirmed swing-low origin.

The manual time selects the first chart bar included in the manual anchored VWAP. The manual price is used only to position the M marker; moving that marker vertically does not change the calculation.

This is not a session-reset VWAP, a deviation-band study, a prediction model, a strategy, or a buy/sell signal system. Its purpose is to make origin selection, confirmation timing, volume availability, visible-window context, and the relationship between two independently anchored structural means explicit and researchable.

What the script calculates

For each active origin, the calculation is:

AVWAP = sum(source x positive chart-reported volume) / sum(positive chart-reported volume)

The manual, swing-high, and swing-low AVWAPs maintain independent numerators and denominators. The implementation uses compensated floating-point accumulation to reduce numerical cancellation that can occur when recent anchored values are obtained by subtracting large chart-wide cumulative totals.

Missing, zero, negative, or otherwise unusable volume receives zero weight. The script does not replace unavailable volume with equal bar weighting or TWAP. The calculation can therefore remain unavailable on symbols or ranges that do not provide positive chart volume.

Manual origin

When the indicator is added, select the chart point that should act as the manual origin.

* The selected time determines the first included bar.
* The selected price positions the M marker only.
* The cyan manual AVWAP is independent of the two automatic AVWAPs.
* If the selected time is earlier than the loaded dataset, the manual calculation is blocked instead of silently substituting the first loaded bar.
* By default, the manual AVWAP is hidden when its origin is outside the current visible horizontal range. This prevents an off-screen manual anchor from appearing as an unexplained line. Disable "Hide manual AVWAP when origin is outside view" when a long-horizon manual projection should remain visible.

Hiding the manual curve is a presentation rule only. It does not redefine the selected origin or convert the calculation into a visible-range VWAP.

Confirmed swing origins

The magenta high-origin AVWAP and green low-origin AVWAP are managed independently. Replacing one origin does not force the other side to reset.

An automatic origin is not accepted solely because it is a local high or low. Users can control:

* bars required on the left and right of a pivot;
* minimum local prominence normalized by ATR;
* minimum spacing between same-type origins;
* an optional relative-volume requirement at the pivot bar;
* the replacement policy.

The available replacement policies are:

* Latest qualified: accepts each new candidate that passes the active filters.
* More prominent only: requires a candidate to improve on the active same-type origin by the configured ATR-normalized margin.
* New price extreme only: requires a higher high for the high-origin curve or a lower low for the low-origin curve.

Confirmation chronology

Automatic pivots require the configured number of right-side bars. A pivot therefore becomes knowable only after its confirmation delay has elapsed.

H and L labels identify the historical origin bars after confirmation. The optional confirmation marker identifies the later bar where the pivot became available, and the dotted bridge shows the origin-to-confirmation delay.

The automatic AVWAP includes chart-reported volume beginning at the actual pivot bar. However, the curve is not backfilled through the origin-to-confirmation interval. It first appears after confirmation and is broken on an anchor-replacement bar so the previous and replacement origins are not visually connected.

This distinction is important: the calculation starts at the pivot, but the automatic origin is not treated as known before confirmation.

Visible-window historical research

The indicator is designed to support both live observation and historical chart research.

Plots, endpoint symbols, retained origin drawings, visible-range volume statistics, and the status panel follow the chart's current visible horizontal range. Scrolling or zooming the chart re-evaluates that research view.

The status panel is evaluated at the rightmost visible bar:

* LIVE means the visible right edge is the developing realtime bar.
* CLOSED means the visible right edge is the latest confirmed bar.
* HISTORY means the latest chart bar is outside the visible range and the panel is reporting a historical research state.

When HISTORY is shown, later bars do not redefine the panel state displayed for the visible right edge. A pivot that would only be confirmed after that visible right edge is not drawn as an available historical origin in that research view.

The underlying AVWAP accumulation still begins at the true accepted origin. The script does not restart an automatic AVWAP at the left edge of the screen.

Swing-pair relationship model

When both automatic AVWAPs are available, the script reports:

* whether the selected context source is above both curves, below both curves, or between them;
* the separation between the two curves in ATR units;
* whether the pair is within the user-defined convergence threshold;
* whether the high-origin curve is above or below the low-origin curve;
* optional confirmed order-flip events when the curves cross.

The transparent fill describes the current price context. When the two automatic curves are close enough to satisfy the convergence threshold, an amber midpoint spine helps preserve visual separation without moving either AVWAP.

These relationships are descriptive. They are not directional forecasts, entries, exits, or trade recommendations.

Visual design

The default presentation uses:

* cyan for the manual AVWAP;
* magenta for the confirmed swing-high-origin AVWAP;
* green for the confirmed swing-low-origin AVWAP;
* a dark contrast halo;
* an optional one-pixel precision core;
* compact endpoint symbols at the rightmost visible values;
* a transparent relationship fill;
* an amber convergence spine when the automatic curves overlap closely.

Cross, convergence-event, and order-flip markers are available but disabled by default to keep the chart readable. Colors, widths, transparency, retained marker history, panel position, panel size, and right-axis clearance are configurable.

Status panel

The panel summarizes:

◆ Manual anchor
▲ High origin
▼ Low origin
● Price context
↔ Pair relation
✓ or ! Data integrity

The panel can report states including WAITING, ORIGIN OUTSIDE VIEW, OUTSIDE LOADED DATA, BLOCKED, NO VOLUME, SYNTHETIC, PARTIAL, and READY.

READY has a narrow meaning: the percentage of visible bars with positive usable chart volume meets the configured threshold. It is not a certification of exchange data, broker data, data-vendor accuracy, or market quality.

Chart-type and volume handling

Standard chart prices are accepted by default.

Heikin Ashi, Renko, Kagi, Line Break, Point & Figure, Range, and other calculated-price chart types are blocked by default because their displayed prices are synthetic or transformed. Users can opt in intentionally. When enabled on such charts, the panel identifies the state as SYNTHETIC.

The panel also reports the chart's volume type when available. Depending on the symbol, volume can represent exchange volume, base volume, quote volume, tick volume, another reported measure, or no usable value.

Alerts

All optional events are routed through one dynamic alert call. To use alerts:

1. Enable "Dynamic alerts" in the indicator settings.
2. Create a TradingView alert.
3. Select this indicator.
4. Choose "Any alert() function call."

Dynamic messages can report:

* newly accepted confirmed swing origins;
* confirmed price crosses of the manual, high-origin, or low-origin AVWAP;
* transitions into above-both or below-both context;
* entry into swing-pair convergence;
* order flips between the two automatic AVWAPs.

Automatic anchor replacement, event conditions, and alerts are evaluated on confirmed bar close. Active AVWAP values can still change while the current realtime bar is forming because its price and cumulative volume are not final.

The visible-window presentation does not redefine the alert conditions. Alert events use the underlying live series and confirmed-bar logic.

Suggested workflow

1. Add the indicator and select a meaningful manual origin.
2. Confirm that the chart provides the type of volume you intend to study.
3. Read H and L as confirmed historical origins, not as signals available on the original pivot bar.
4. Compare the independent manual, high-origin, and low-origin AVWAP paths.
5. Use the panel to inspect price context, pair separation, curve order, visible-range volume coverage, and LIVE/CLOSED/HISTORY state.
6. Adjust pivot qualification and replacement policy to study how different origin definitions change the result.
7. Enable optional event markers or alerts only when they are useful to the research question.

Limitations

* Results depend entirely on the price and volume series supplied by the chart and data provider.
* No AVWAP is produced when total positive chart-reported volume from an origin is zero.
* Tick volume, base volume, quote volume, and exchange volume are not interchangeable economic measures.
* Pivot confirmation necessarily occurs after the pivot bar. Larger right-side settings increase the delay.
* H and L labels are placed on historical origin bars only after confirmation.
* The open realtime bar can change the current AVWAP values until that bar closes.
* Scrolling or zooming changes the visible-window research scope and therefore the panel's visible-range statistics and right-edge state.
* Default settings are general research starting points. They are not optimized for a symbol, timeframe, market, or outcome.
* ATR prominence, relative volume, convergence, curve order, fills, markers, and alerts describe observed chart relationships only.
* This indicator does not claim profitability, predictive accuracy, or future performance and does not provide financial advice.

Open-source note

This is an independent open-source implementation built from the conventional definition of volume-weighted average price and standard Pine Script features. It does not incorporate third-party indicator source code, a proprietary trading methodology, or a paper-specific implementation.

Thông báo miễn trừ trách nhiệm

Thông tin và các ấn phẩm này không nhằm mục đích, và không cấu thành, lời khuyên hoặc khuyến nghị về tài chính, đầu tư, giao dịch hay các loại khác do TradingView cung cấp hoặc xác nhận. Đọc thêm tại Điều khoản Sử dụng.