PROTECTED SOURCE SCRIPT
STC Hedging SMA Trend Gate

Schaff Trend Cycle (STC)–based hedging tool with a built-in higher-timeframe trend filter (“Trend Gate”) and a signal cooldown mechanism.
It is designed to provide long/short hedge entry signals only when both the momentum (STC) and the higher-timeframe trend agree, helping filter out noise and false trades.
Key Components
1. STC Core (Momentum Engine)
The Schaff Trend Cycle (STC) is calculated from a normalized MACD cycle:
Uses fastLength and slowLength EMAs.
Normalizes the EMA difference over a lengthSTC window.
Smooths and rescales into a 0–100 oscillator.
Thresholds:
Lower Threshold (default 20): potential long/hedge long entry if crossed upwards.
Upper Threshold (default 80): potential short/hedge short entry if crossed downwards.
2. Trend Gate (Higher-Timeframe Filter)
Pulls fast SMA and slow SMA from a higher timeframe (gateTF, default = 5m).
Defines the prevailing trend:
Bullish Trend: fast SMA > slow SMA.
Bearish Trend: fast SMA < slow SMA.
Requires persistence (trendBars) before validating a trend direction, avoiding “one-bar flips.”
3. Signal Debounce & Cooldown
Uses barstate.isconfirmed → ensures signals trigger only on bar close (prevents repainting).
Requires a minimum number of bars (cooldownBars) between signals.
Tracks the last signal bar (lastSigBar) so no new signals fire too close together.
4. Trade Signals
Long Hedge Signal:
STC crosses above the lower threshold.
Higher timeframe is bullish for at least trendBars bars.
Cooldown condition is satisfied.
Short Hedge Signal:
STC crosses below the upper threshold.
Higher timeframe is bearish for at least trendBars bars.
Cooldown condition is satisfied.
Signals are shown with:
Green ▲ triangles below bars = Long Hedge
Red ▼ triangles above bars = Short Hedge
5. Alerts
Built-in alertcondition() allows TradingView alerts for:
STC Long Hedge
STC Short Hedge
This indicator is intended for hedging strategies and trend-aligned momentum trading.
By combining:
STC cycle turns (momentum shifts), HTF moving average trend filter, and Signal cooldown (to reduce over-trading), Aims to generate cleaner long/short hedge entry signals with reduced noise and false triggers.
It is designed to provide long/short hedge entry signals only when both the momentum (STC) and the higher-timeframe trend agree, helping filter out noise and false trades.
Key Components
1. STC Core (Momentum Engine)
The Schaff Trend Cycle (STC) is calculated from a normalized MACD cycle:
Uses fastLength and slowLength EMAs.
Normalizes the EMA difference over a lengthSTC window.
Smooths and rescales into a 0–100 oscillator.
Thresholds:
Lower Threshold (default 20): potential long/hedge long entry if crossed upwards.
Upper Threshold (default 80): potential short/hedge short entry if crossed downwards.
2. Trend Gate (Higher-Timeframe Filter)
Pulls fast SMA and slow SMA from a higher timeframe (gateTF, default = 5m).
Defines the prevailing trend:
Bullish Trend: fast SMA > slow SMA.
Bearish Trend: fast SMA < slow SMA.
Requires persistence (trendBars) before validating a trend direction, avoiding “one-bar flips.”
3. Signal Debounce & Cooldown
Uses barstate.isconfirmed → ensures signals trigger only on bar close (prevents repainting).
Requires a minimum number of bars (cooldownBars) between signals.
Tracks the last signal bar (lastSigBar) so no new signals fire too close together.
4. Trade Signals
Long Hedge Signal:
STC crosses above the lower threshold.
Higher timeframe is bullish for at least trendBars bars.
Cooldown condition is satisfied.
Short Hedge Signal:
STC crosses below the upper threshold.
Higher timeframe is bearish for at least trendBars bars.
Cooldown condition is satisfied.
Signals are shown with:
Green ▲ triangles below bars = Long Hedge
Red ▼ triangles above bars = Short Hedge
5. Alerts
Built-in alertcondition() allows TradingView alerts for:
STC Long Hedge
STC Short Hedge
This indicator is intended for hedging strategies and trend-aligned momentum trading.
By combining:
STC cycle turns (momentum shifts), HTF moving average trend filter, and Signal cooldown (to reduce over-trading), Aims to generate cleaner long/short hedge entry signals with reduced noise and false triggers.
Script protégé
Ce script est publié en source fermée. Toutefois, vous pouvez l'utiliser librement et sans aucune restriction - en savoir plus ici.
Clause de non-responsabilité
Les informations et les publications ne sont pas destinées à être, et ne constituent pas, des conseils ou des recommandations en matière de finance, d'investissement, de trading ou d'autres types de conseils fournis ou approuvés par TradingView. Pour en savoir plus, consultez les Conditions d'utilisation.
Script protégé
Ce script est publié en source fermée. Toutefois, vous pouvez l'utiliser librement et sans aucune restriction - en savoir plus ici.
Clause de non-responsabilité
Les informations et les publications ne sont pas destinées à être, et ne constituent pas, des conseils ou des recommandations en matière de finance, d'investissement, de trading ou d'autres types de conseils fournis ou approuvés par TradingView. Pour en savoir plus, consultez les Conditions d'utilisation.