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.
开源脚本
秉承TradingView的精神,该脚本的作者将其开源,以便交易者可以查看和验证其功能。向作者致敬!您可以免费使用该脚本,但请记住,重新发布代码须遵守我们的网站规则。
免责声明
这些信息和出版物并非旨在提供,也不构成TradingView提供或认可的任何形式的财务、投资、交易或其他类型的建议或推荐。请阅读使用条款了解更多信息。
开源脚本
秉承TradingView的精神,该脚本的作者将其开源,以便交易者可以查看和验证其功能。向作者致敬!您可以免费使用该脚本,但请记住,重新发布代码须遵守我们的网站规则。
免责声明
这些信息和出版物并非旨在提供,也不构成TradingView提供或认可的任何形式的财务、投资、交易或其他类型的建议或推荐。请阅读使用条款了解更多信息。