OPEN-SOURCE SCRIPT
VWAP slope (normalized)

**Normalized VWAP Slope (Session-Based Regime Filter)**
This indicator measures the slope of the session VWAP using a linear regression model and normalizes it by ATR. The goal is to identify whether the market is in a **balanced (range) state** or in a **directional (trend / discovery) state**.
The script calculates the slope of the VWAP regression line over a configurable lookback period and divides it by the current ATR value. This normalization makes the slope comparable across different instruments and volatility environments.
To avoid unstable readings at the start of a session, the indicator includes a **warm-up filter** that ignores the first N bars after the daily session reset.
**How it works**
1. Session VWAP is calculated using TradingView's built-in VWAP function.
2. A linear regression is applied to the VWAP over the selected lookback length.
3. The difference between consecutive regression values produces the VWAP slope.
4. The slope is normalized by ATR to account for changing volatility.
5. During the warm-up period after the session reset, values are suppressed to prevent distortions caused by the VWAP initialization.
**Interpretation**
The normalized slope represents how steep the VWAP is relative to normal market volatility.
Typical interpretation:
* Values near **0** → VWAP is flat → market is likely in **balance / range**
* Moderate positive or negative values → **developing directional bias**
* Large absolute values → **strong directional move / information driven market**
**Typical threshold usage**
Many mean-reversion strategies use thresholds to determine when range trading is allowed.
Example guideline:
For Intraday Session
* `|slope| < 0.01`and |slope| > -0.01 → Balanced market
* `|slope| > 0.01`or |slope| < -0.01 → Directional market (range trading discouraged)
These thresholds should be adjusted depending on the instrument and timeframe.
**Inputs**
* **LinReg Length** – Lookback period used for the VWAP regression slope.
* **Warm-up Bars** – Number of bars ignored after a new session begins.
* **ATR Length** – Period used for volatility normalization.
* **Upper / Lower Threshold** – Reference levels used to identify balanced vs directional conditions.
**Purpose**
This tool is designed primarily as a **market regime filter**, especially useful for strategies that rely on mean reversion around VWAP. By detecting when the VWAP becomes steep relative to normal volatility, traders can avoid applying range strategies during strong directional moves.
This indicator measures the slope of the session VWAP using a linear regression model and normalizes it by ATR. The goal is to identify whether the market is in a **balanced (range) state** or in a **directional (trend / discovery) state**.
The script calculates the slope of the VWAP regression line over a configurable lookback period and divides it by the current ATR value. This normalization makes the slope comparable across different instruments and volatility environments.
To avoid unstable readings at the start of a session, the indicator includes a **warm-up filter** that ignores the first N bars after the daily session reset.
**How it works**
1. Session VWAP is calculated using TradingView's built-in VWAP function.
2. A linear regression is applied to the VWAP over the selected lookback length.
3. The difference between consecutive regression values produces the VWAP slope.
4. The slope is normalized by ATR to account for changing volatility.
5. During the warm-up period after the session reset, values are suppressed to prevent distortions caused by the VWAP initialization.
**Interpretation**
The normalized slope represents how steep the VWAP is relative to normal market volatility.
Typical interpretation:
* Values near **0** → VWAP is flat → market is likely in **balance / range**
* Moderate positive or negative values → **developing directional bias**
* Large absolute values → **strong directional move / information driven market**
**Typical threshold usage**
Many mean-reversion strategies use thresholds to determine when range trading is allowed.
Example guideline:
For Intraday Session
* `|slope| < 0.01`and |slope| > -0.01 → Balanced market
* `|slope| > 0.01`or |slope| < -0.01 → Directional market (range trading discouraged)
These thresholds should be adjusted depending on the instrument and timeframe.
**Inputs**
* **LinReg Length** – Lookback period used for the VWAP regression slope.
* **Warm-up Bars** – Number of bars ignored after a new session begins.
* **ATR Length** – Period used for volatility normalization.
* **Upper / Lower Threshold** – Reference levels used to identify balanced vs directional conditions.
**Purpose**
This tool is designed primarily as a **market regime filter**, especially useful for strategies that rely on mean reversion around VWAP. By detecting when the VWAP becomes steep relative to normal volatility, traders can avoid applying range strategies during strong directional moves.
Mã nguồn mở
Theo đúng tinh thần TradingView, tác giả của tập lệnh này đã công bố nó dưới dạng mã nguồn mở, để các nhà giao dịch có thể xem xét và xác minh chức năng. Chúc mừng tác giả! Mặc dù bạn có thể sử dụng miễn phí, hãy nhớ rằng việc công bố lại mã phải tuân theo Nội quy.
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.
Mã nguồn mở
Theo đúng tinh thần TradingView, tác giả của tập lệnh này đã công bố nó dưới dạng mã nguồn mở, để các nhà giao dịch có thể xem xét và xác minh chức năng. Chúc mừng tác giả! Mặc dù bạn có thể sử dụng miễn phí, hãy nhớ rằng việc công bố lại mã phải tuân theo Nội quy.
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.