OPEN-SOURCE SCRIPT
Alpha Supertrend Vector >_

A triple-validated trend-flip system that enters exclusively at the moment a Supertrend indicator changes direction — the earliest confirmation of a regime change — then requires two independent filters (ADX strength and Choppiness Index) to confirm that the flip is occurring within a genuine trending environment. Exits are managed through ATR%-normalized take profit and stop loss levels, with a secondary hard-cap Plug stop that enforces an absolute maximum loss boundary on every trade regardless of volatility conditions.
═══════════════════════════════════════
KEY FEATURES
═══════════════════════════════════════
Supertrend Flip Signal
— Enters on the exact bar where Supertrend direction changes polarity
— Long trigger: bearish-to-bullish flip (st_dir changes from 1 to -1)
— Short trigger: bullish-to-bearish flip (st_dir changes from -1 to 1)
— Configurable ATR multiplier and fast ATR length
— Supertrend line plotted on chart: green (bullish), red (bearish)
Choppiness Index Regime Filter
— CHOP Index must be below the configured threshold at signal bar
— Measures ATR range relative to total high-low range, log-normalized
— Blocks flip entries during sideways, range-bound market conditions
— Protects against the most common source of false Supertrend flip signals
ADX Directional Strength Filter
— ADX must exceed configurable minimum threshold at signal bar
— Full DMI calculation using DI+ and DI− via ta.dmi()
— Confirms sufficient trend force behind the directional flip
— Guards against low-energy drifts that trigger flips without follow-through
ATR% Normalized Exits
— TP and SL expressed as multiples of ATR% — volatility-proportional by design
— ATR% value locked at signal bar via entry_atr_pct variable
— Exit levels anchored to strategy.position_avg_price for live execution accuracy
— No mid-trade recalculation of the base ATR% — risk profile stays fixed
The Plug — Hard Stop Architecture
— Independent hard percentage stop applied to every trade
— For longs: avg_price × (1 − Plug%). For shorts: avg_price × (1 + Plug%)
— Compared to ATR SL using math.max() / math.min() — tighter stop always wins
— Prevents a single volatility spike from breaching a user-defined loss ceiling
═══════════════════════════════════════
HOW IT WORKS
═══════════════════════════════════════
Step 1 — Supertrend Flip Detection
ta.change(st_dir) evaluates to negative when Supertrend flips from bearish (1) to bullish (-1), and positive when it flips from bullish to bearish. These direction changes represent the earliest available structural confirmation of a trend reversal — before momentum indicators, before moving average crossovers.
Step 2 — Choppiness Gate
The Choppiness Index (CHOP) measures the ratio of summed 1-bar ATR to total high-low range over the lookback window, log-normalized to a 0–100 scale. Values below the threshold indicate the market is trending. Values above indicate choppiness. Flip signals that occur during high-CHOP environments — where Supertrend is most likely to whipsaw — are filtered entirely.
Step 3 — ADX Gate
ADX above the minimum confirms the trend has directional force. Even in trending markets, low ADX can indicate the trend is weak and unlikely to sustain a move through the TP level. Both CHOP and ADX must pass simultaneously with the Supertrend flip for entry to execute.
Step 4 — Entry
Entry is placed on the signal bar. The ATR% value at that exact moment is captured and stored for use in exit calculations throughout the life of the trade.
Step 5 — Exit Calculation
TP and SL are calculated dynamically off strategy.position_avg_price using the stored entry_atr_pct. The Plug stop is calculated independently as a fixed percentage from average price. Whichever stop is closer to entry price is applied via math.max() (longs) or math.min() (shorts). The strategy.exit() call runs on every bar while the position is open, ensuring levels remain accurate if average price shifts due to execution variance.
═══════════════════════════════════════
WHY SUPERTREND FLIPS — NOT SUSTAINED DIRECTION
═══════════════════════════════════════
Most Supertrend-based strategies enter whenever price is on the bullish or bearish side of the indicator. The Alpha Supertrend Vector enters only at the flip — the single bar where direction changes. This produces a lower-frequency, higher-conviction signal profile. The strategy is not trying to stay in a trend; it is trying to capture the initial thrust at the moment of regime change, before the move becomes consensus and crowded.
═══════════════════════════════════════
ATR% vs. ATR — THE DISTINCTION
═══════════════════════════════════════
Raw ATR is price-level dependent — a $5 ATR on a $50 stock is extreme; on a $500 stock, it is mild. By converting to ATR% (ATR / close × 100), exit distances become proportional to the instrument's current price level and volatility regime. A 1.0× ATR% TP means the same thing across different assets, different price levels, and different volatility environments — making the strategy's settings genuinely portable across instruments.
═══════════════════════════════════════
KEY FEATURES
═══════════════════════════════════════
Supertrend Flip Signal
— Enters on the exact bar where Supertrend direction changes polarity
— Long trigger: bearish-to-bullish flip (st_dir changes from 1 to -1)
— Short trigger: bullish-to-bearish flip (st_dir changes from -1 to 1)
— Configurable ATR multiplier and fast ATR length
— Supertrend line plotted on chart: green (bullish), red (bearish)
Choppiness Index Regime Filter
— CHOP Index must be below the configured threshold at signal bar
— Measures ATR range relative to total high-low range, log-normalized
— Blocks flip entries during sideways, range-bound market conditions
— Protects against the most common source of false Supertrend flip signals
ADX Directional Strength Filter
— ADX must exceed configurable minimum threshold at signal bar
— Full DMI calculation using DI+ and DI− via ta.dmi()
— Confirms sufficient trend force behind the directional flip
— Guards against low-energy drifts that trigger flips without follow-through
ATR% Normalized Exits
— TP and SL expressed as multiples of ATR% — volatility-proportional by design
— ATR% value locked at signal bar via entry_atr_pct variable
— Exit levels anchored to strategy.position_avg_price for live execution accuracy
— No mid-trade recalculation of the base ATR% — risk profile stays fixed
The Plug — Hard Stop Architecture
— Independent hard percentage stop applied to every trade
— For longs: avg_price × (1 − Plug%). For shorts: avg_price × (1 + Plug%)
— Compared to ATR SL using math.max() / math.min() — tighter stop always wins
— Prevents a single volatility spike from breaching a user-defined loss ceiling
═══════════════════════════════════════
HOW IT WORKS
═══════════════════════════════════════
Step 1 — Supertrend Flip Detection
ta.change(st_dir) evaluates to negative when Supertrend flips from bearish (1) to bullish (-1), and positive when it flips from bullish to bearish. These direction changes represent the earliest available structural confirmation of a trend reversal — before momentum indicators, before moving average crossovers.
Step 2 — Choppiness Gate
The Choppiness Index (CHOP) measures the ratio of summed 1-bar ATR to total high-low range over the lookback window, log-normalized to a 0–100 scale. Values below the threshold indicate the market is trending. Values above indicate choppiness. Flip signals that occur during high-CHOP environments — where Supertrend is most likely to whipsaw — are filtered entirely.
Step 3 — ADX Gate
ADX above the minimum confirms the trend has directional force. Even in trending markets, low ADX can indicate the trend is weak and unlikely to sustain a move through the TP level. Both CHOP and ADX must pass simultaneously with the Supertrend flip for entry to execute.
Step 4 — Entry
Entry is placed on the signal bar. The ATR% value at that exact moment is captured and stored for use in exit calculations throughout the life of the trade.
Step 5 — Exit Calculation
TP and SL are calculated dynamically off strategy.position_avg_price using the stored entry_atr_pct. The Plug stop is calculated independently as a fixed percentage from average price. Whichever stop is closer to entry price is applied via math.max() (longs) or math.min() (shorts). The strategy.exit() call runs on every bar while the position is open, ensuring levels remain accurate if average price shifts due to execution variance.
═══════════════════════════════════════
WHY SUPERTREND FLIPS — NOT SUSTAINED DIRECTION
═══════════════════════════════════════
Most Supertrend-based strategies enter whenever price is on the bullish or bearish side of the indicator. The Alpha Supertrend Vector enters only at the flip — the single bar where direction changes. This produces a lower-frequency, higher-conviction signal profile. The strategy is not trying to stay in a trend; it is trying to capture the initial thrust at the moment of regime change, before the move becomes consensus and crowded.
═══════════════════════════════════════
ATR% vs. ATR — THE DISTINCTION
═══════════════════════════════════════
Raw ATR is price-level dependent — a $5 ATR on a $50 stock is extreme; on a $500 stock, it is mild. By converting to ATR% (ATR / close × 100), exit distances become proportional to the instrument's current price level and volatility regime. A 1.0× ATR% TP means the same thing across different assets, different price levels, and different volatility environments — making the strategy's settings genuinely portable across instruments.
오픈 소스 스크립트
트레이딩뷰의 진정한 정신에 따라, 이 스크립트의 작성자는 이를 오픈소스로 공개하여 트레이더들이 기능을 검토하고 검증할 수 있도록 했습니다. 작성자에게 찬사를 보냅니다! 이 코드는 무료로 사용할 수 있지만, 코드를 재게시하는 경우 하우스 룰이 적용된다는 점을 기억하세요.
면책사항
해당 정보와 게시물은 금융, 투자, 트레이딩 또는 기타 유형의 조언이나 권장 사항으로 간주되지 않으며, 트레이딩뷰에서 제공하거나 보증하는 것이 아닙니다. 자세한 내용은 이용 약관을 참조하세요.
오픈 소스 스크립트
트레이딩뷰의 진정한 정신에 따라, 이 스크립트의 작성자는 이를 오픈소스로 공개하여 트레이더들이 기능을 검토하고 검증할 수 있도록 했습니다. 작성자에게 찬사를 보냅니다! 이 코드는 무료로 사용할 수 있지만, 코드를 재게시하는 경우 하우스 룰이 적용된다는 점을 기억하세요.
면책사항
해당 정보와 게시물은 금융, 투자, 트레이딩 또는 기타 유형의 조언이나 권장 사항으로 간주되지 않으며, 트레이딩뷰에서 제공하거나 보증하는 것이 아닙니다. 자세한 내용은 이용 약관을 참조하세요.