PROTECTED SOURCE SCRIPT

STC Hedging EMA Trend Gate

18
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 EMA > slow EMA.
Bearish Trend: fast EMA < slow EMA.
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.

Aviso legal

As informações e publicações não devem ser e não constituem conselhos ou recomendações financeiras, de investimento, de negociação ou de qualquer outro tipo, fornecidas ou endossadas pela TradingView. Leia mais em Termos de uso.