OPEN-SOURCE SCRIPT
KAS VWAP Engine v4.2

KAS VWAP Engine v4.2 is an open-source auto-anchored VWAP indicator designed for mean-reversion setups around volume-weighted average price. The anchor automatically resets when price establishes a new structural high or low over a configurable lookback period. A 2-stage state machine ensures signals only fire after a confirmed band-touch followed by an opposite-band close-reclaim.
WHAT IT DOES
- Plots an auto-anchored VWAP that resets on structure breaks (configurable lookback)
- Adds inner and outer ATR-based deviation bands around the VWAP baseline
- Detects mean-reversion entries when price touches the outer band and reclaims the inner band
- Visualizes completed trades as directional vectors with inline P&L labels
- Filters signals through an HTF EMA 200 trend gate (optional) and an ATR Z-Score volatility regime gate (optional)
- Displays a real-time dashboard with current reversion state, VWAP value, price deviation, HTF trend, and ATR filter status
HOW IT WORKS
1. Auto-Anchor Detection
The anchor resets when the current bar high exceeds the highest high of the previous N bars (configurable, default 50), or when the current low breaks below the lowest low. Implementation uses ta.highest(high[1], swingLen) and ta.lowest(low[1], swingLen) for the structure-break comparison.
2. Manual VWAP Accumulators
The VWAP uses hlc3 as price source and resets accumulator buffers on each new anchor. This produces a session-style VWAP from each detected structure point. Formula: VWAP = sumSrcVol / sumVol, where sumSrcVol accumulates hlc3 multiplied by volume.
3. ATR Deviation Bands with Bridge
Bands are placed at the VWAP plus/minus inner-multiplier and outer-multiplier times the ATR-14 baseline (SMA-smoothed over 100 bars). On anchor-reset bars, a dedicated bridge variable substitutes hlc3 for the freshly-reset VWAP value, preventing ghost-line artifacts in the visualization.
4. 2-Stage State Machine (Arm to Fire)
Stage 1 (Arm): a touch of the outer band sets the armed state to +1 (long-arm) or -1 (short-arm).
Stage 2 (Fire): a close back inside the inner band fires the entry signal in the same direction.
A signal cooldown (configurable bars) and a VWAP-touch-reset clear the armed state.
5. ATR Z-Score Regime Gate
The ATR-14 z-score is computed against its 100-bar SMA and 100-bar standard deviation. When the z-score falls below -1.0, the regime is classified as Low Vol and signals are blocked (optional filter, on by default).
6. HTF EMA 200 Filter
A request.security call retrieves the EMA-200 from a higher timeframe (default 4h). When enabled, long-reversion signals only fire when close is above the HTF EMA, and short-reversion signals only fire when close is below the HTF EMA.
WHY IT'S UNIQUE
- Unlike standard auto-anchored VWAP scripts that produce ghost-line artifacts when the anchor resets, this indicator substitutes hlc3 on the reset bar via a dedicated bridge variable, providing a continuous, artifact-free anchored VWAP visualization.
- Unlike instant-fire band-touch signals common in VWAP deviation scripts, this indicator uses a 2-stage Arm to Fire state machine: an outer-band touch only arms the setup, and the signal fires only after an inner-band close-reclaim, significantly reducing false signals during volatile band-pierces.
- Unlike static signal markers, this indicator visualizes each completed trade as a directional vector from entry to exit (Take Profit at VWAP, or Stop at opposite outer band) with inline P&L percentage labels, enabling rapid visual back-test review on historical bars.
HOW TO USE
- Add the indicator to a standard candlestick chart on any timeframe (intraday 5m-15m and swing 1h-4h work well)
- Default settings work for most liquid instruments; adjust Structure Lookback (50 bars) based on your timeframe density
- Watch for Revert Long (triangle below bar) or Revert Short (triangle above bar) signals after a touch of the outer band
- The dashboard shows current reversion state, VWAP deviation, HTF trend direction, and whether the ATR regime gate is blocking signals
- Trade trajectory beams visualize each completed setup with TP (return to VWAP) or STOP (extension to opposite band) outcomes
- Combine with your own risk management; the indicator is analytical, not a recommendation
LIMITATIONS
- Mean-reversion logic is designed for ranging or oscillating markets; performance is reduced in strong directional trends
- ATR Z-Score regime detection requires at least 100 bars of history to stabilize
- The HTF EMA 200 filter requires sufficient history on the higher timeframe; on newly-listed instruments or very short timeframes the HTF signal may be unstable
- Signals fire on bar close (barstate.isconfirmed); intra-bar movements are not signaled
- This indicator is for analytical purposes only and does not constitute financial advice or a recommendation to trade
ABOUT
Knecht Alpha Signals delivers Pine Script v6 indicators focused on precision over noise. This open-source release is part of our public toolkit for the TradingView community.
WHAT IT DOES
- Plots an auto-anchored VWAP that resets on structure breaks (configurable lookback)
- Adds inner and outer ATR-based deviation bands around the VWAP baseline
- Detects mean-reversion entries when price touches the outer band and reclaims the inner band
- Visualizes completed trades as directional vectors with inline P&L labels
- Filters signals through an HTF EMA 200 trend gate (optional) and an ATR Z-Score volatility regime gate (optional)
- Displays a real-time dashboard with current reversion state, VWAP value, price deviation, HTF trend, and ATR filter status
HOW IT WORKS
1. Auto-Anchor Detection
The anchor resets when the current bar high exceeds the highest high of the previous N bars (configurable, default 50), or when the current low breaks below the lowest low. Implementation uses ta.highest(high[1], swingLen) and ta.lowest(low[1], swingLen) for the structure-break comparison.
2. Manual VWAP Accumulators
The VWAP uses hlc3 as price source and resets accumulator buffers on each new anchor. This produces a session-style VWAP from each detected structure point. Formula: VWAP = sumSrcVol / sumVol, where sumSrcVol accumulates hlc3 multiplied by volume.
3. ATR Deviation Bands with Bridge
Bands are placed at the VWAP plus/minus inner-multiplier and outer-multiplier times the ATR-14 baseline (SMA-smoothed over 100 bars). On anchor-reset bars, a dedicated bridge variable substitutes hlc3 for the freshly-reset VWAP value, preventing ghost-line artifacts in the visualization.
4. 2-Stage State Machine (Arm to Fire)
Stage 1 (Arm): a touch of the outer band sets the armed state to +1 (long-arm) or -1 (short-arm).
Stage 2 (Fire): a close back inside the inner band fires the entry signal in the same direction.
A signal cooldown (configurable bars) and a VWAP-touch-reset clear the armed state.
5. ATR Z-Score Regime Gate
The ATR-14 z-score is computed against its 100-bar SMA and 100-bar standard deviation. When the z-score falls below -1.0, the regime is classified as Low Vol and signals are blocked (optional filter, on by default).
6. HTF EMA 200 Filter
A request.security call retrieves the EMA-200 from a higher timeframe (default 4h). When enabled, long-reversion signals only fire when close is above the HTF EMA, and short-reversion signals only fire when close is below the HTF EMA.
WHY IT'S UNIQUE
- Unlike standard auto-anchored VWAP scripts that produce ghost-line artifacts when the anchor resets, this indicator substitutes hlc3 on the reset bar via a dedicated bridge variable, providing a continuous, artifact-free anchored VWAP visualization.
- Unlike instant-fire band-touch signals common in VWAP deviation scripts, this indicator uses a 2-stage Arm to Fire state machine: an outer-band touch only arms the setup, and the signal fires only after an inner-band close-reclaim, significantly reducing false signals during volatile band-pierces.
- Unlike static signal markers, this indicator visualizes each completed trade as a directional vector from entry to exit (Take Profit at VWAP, or Stop at opposite outer band) with inline P&L percentage labels, enabling rapid visual back-test review on historical bars.
HOW TO USE
- Add the indicator to a standard candlestick chart on any timeframe (intraday 5m-15m and swing 1h-4h work well)
- Default settings work for most liquid instruments; adjust Structure Lookback (50 bars) based on your timeframe density
- Watch for Revert Long (triangle below bar) or Revert Short (triangle above bar) signals after a touch of the outer band
- The dashboard shows current reversion state, VWAP deviation, HTF trend direction, and whether the ATR regime gate is blocking signals
- Trade trajectory beams visualize each completed setup with TP (return to VWAP) or STOP (extension to opposite band) outcomes
- Combine with your own risk management; the indicator is analytical, not a recommendation
LIMITATIONS
- Mean-reversion logic is designed for ranging or oscillating markets; performance is reduced in strong directional trends
- ATR Z-Score regime detection requires at least 100 bars of history to stabilize
- The HTF EMA 200 filter requires sufficient history on the higher timeframe; on newly-listed instruments or very short timeframes the HTF signal may be unstable
- Signals fire on bar close (barstate.isconfirmed); intra-bar movements are not signaled
- This indicator is for analytical purposes only and does not constitute financial advice or a recommendation to trade
ABOUT
Knecht Alpha Signals delivers Pine Script v6 indicators focused on precision over noise. This open-source release is part of our public toolkit for the TradingView community.
開源腳本
秉持TradingView一貫精神,這個腳本的創作者將其設為開源,以便交易者檢視並驗證其功能。向作者致敬!您可以免費使用此腳本,但請注意,重新發佈代碼需遵守我們的社群規範。
Knecht Alpha Signals (KAS)
Institutional-grade Volume Delta · Momentum · MTF Analysis for TradingView.
Built for traders who demand precision over noise.
Full indicator suite: whop.com/knecht-alpha-signals
Institutional-grade Volume Delta · Momentum · MTF Analysis for TradingView.
Built for traders who demand precision over noise.
Full indicator suite: whop.com/knecht-alpha-signals
免責聲明
這些資訊和出版物並非旨在提供,也不構成TradingView提供或認可的任何形式的財務、投資、交易或其他類型的建議或推薦。請閱讀使用條款以了解更多資訊。
開源腳本
秉持TradingView一貫精神,這個腳本的創作者將其設為開源,以便交易者檢視並驗證其功能。向作者致敬!您可以免費使用此腳本,但請注意,重新發佈代碼需遵守我們的社群規範。
Knecht Alpha Signals (KAS)
Institutional-grade Volume Delta · Momentum · MTF Analysis for TradingView.
Built for traders who demand precision over noise.
Full indicator suite: whop.com/knecht-alpha-signals
Institutional-grade Volume Delta · Momentum · MTF Analysis for TradingView.
Built for traders who demand precision over noise.
Full indicator suite: whop.com/knecht-alpha-signals
免責聲明
這些資訊和出版物並非旨在提供,也不構成TradingView提供或認可的任何形式的財務、投資、交易或其他類型的建議或推薦。請閱讀使用條款以了解更多資訊。