VWAP Separation w/ StDev (LEX)

## VWAP Separation with Standard Deviation Bands
**Overview**
This indicator measures and visualizes the raw distance (separation) between a chosen price source (like `hlc3` or `close`) and its corresponding Volume Weighted Average Price (VWAP) for a selected anchor period. It helps traders gauge how far the current price has deviated from its volume-weighted average.
To provide context on the magnitude of this separation, the indicator also calculates and plots dynamic bands representing +/- 1 standard deviation of the separation value itself, calculated over a user-defined lookback period.
**How it Works**
1. **VWAP Calculation:** The indicator first calculates the VWAP based on the user-selected `Anchor Period` (e.g., Session, Week, Month) and `Source` price. The VWAP calculation resets at the beginning of each new anchor period.
2. **Separation Calculation:** It then subtracts the calculated VWAP from the source price for each bar (`Separation = Source - VWAP`).
3. **Plotting Separation:** This raw separation value is plotted as a line in a separate indicator pane.
* Positive values indicate the source price is above the VWAP.
* Negative values indicate the source price is below the VWAP.
4. **Zero Line & Crossings:** A horizontal line at zero is plotted for easy reference. Small circles are plotted on the zero line whenever the separation value crosses it (using `ta.cross`), highlighting moments when the price crosses its VWAP.
5. **Standard Deviation Bands:**
* The indicator calculates the rolling Simple Moving Average (SMA) of the `Separation` value over a specified `StDev Length` using `ta.sma`.
* It then calculates the rolling standard deviation of the `Separation` value over the same length using `ta.stdev`.
* Finally, it plots two dynamic lines: `SMA + 1 StDev` and `SMA - 1 StDev`. These bands represent the typical range of the separation's volatility based on the lookback period.
**How to Use / Interpretation**
* **Magnitude of Separation:** The primary line directly shows how far, in price terms, the market is currently trading away from its VWAP for the chosen anchor period. Large absolute values suggest a significant deviation.
* **Zero Line:** Crossing the zero line indicates the price is moving from one side of the VWAP to the other. The indicator staying consistently above/below zero shows price trending relative to its VWAP.
* **Standard Deviation Bands:** These bands help contextualize the separation.
* When the separation line touches or exceeds the upper band, it suggests the price is unusually far *above* the VWAP compared to its recent behavior.
* When the separation line touches or exceeds the lower band, it suggests the price is unusually far *below* the VWAP compared to its recent behavior.
* These "unusual" deviations *might* indicate over-extended conditions potentially leading to mean reversion back towards the VWAP, *or* they could signal the start of a strong move away from the VWAP. Always use in conjunction with other analysis methods.
* The width of the bands indicates the recent volatility *of the separation value itself*. Wider bands mean the separation has been more volatile; narrower bands mean it's been more stable.
**Key Features**
* Flexible VWAP calculation based on various anchor periods (Session, Week, Month, Earnings, etc.).
* Plots the raw price separation from VWAP.
* Clear zero line reference.
* Visual markers for zero-line crossings.
* Dynamic +/- 1 Standard Deviation bands based on the separation's volatility.
* User-configurable inputs for anchor period, price source, and standard deviation length.
**Settings**
* **Anchor Period:** Determines the calculation period for VWAP (Session, Week, Month, Quarter, Year, Decade, Century, Earnings, Dividends, Splits). Default: `Session`.
* **Source:** The price data used for calculating VWAP and separation (e.g., hlc3, close, open). Default: `hlc3`.
* **StDev Length:** The lookback period (number of bars) used to calculate the moving average and standard deviation of the separation value. Default: `20`.
**Disclaimer**
This indicator is provided for educational and informational purposes only. It does not constitute financial advice or a recommendation to trade. Trading financial markets involves significant risk. Always perform your own due diligence and test any indicator thoroughly before using it in live trading. Past performance is not indicative of future results.
---
Skrip sumber terbuka
Dalam semangat sebenar TradingView, pencipta skrip ini telah menjadikannya sumber terbuka supaya pedagang dapat menilai dan mengesahkan kefungsiannya. Terima kasih kepada penulis! Walaupun anda boleh menggunakannya secara percuma, ingat bahawa menerbitkan semula kod ini adalah tertakluk kepada Peraturan Dalaman kami.
Untuk akses pantas pada carta, tambah skrip ini kepada kegemaran anda — ketahui lebih lanjut di sini.
Penafian
Skrip sumber terbuka
Dalam semangat sebenar TradingView, pencipta skrip ini telah menjadikannya sumber terbuka supaya pedagang dapat menilai dan mengesahkan kefungsiannya. Terima kasih kepada penulis! Walaupun anda boleh menggunakannya secara percuma, ingat bahawa menerbitkan semula kod ini adalah tertakluk kepada Peraturan Dalaman kami.
Untuk akses pantas pada carta, tambah skrip ini kepada kegemaran anda — ketahui lebih lanjut di sini.