OPEN-SOURCE SCRIPT

Smart Price Divergence (MACD Filter) + EMA

120
📌 Purpose
This indicator detects Price Divergences with MACD filtered by a 200 EMA trend condition.
It helps identify high-probability reversal zones aligned with market trend context.

🧠 How It Works
1. MACD Divergence Logic
Bearish Divergence:

Price makes a higher high.

MACD makes a lower high.

Price is above EMA (indicating possible exhaustion in bullish trend).

Bullish Divergence:

Price makes a lower low.

MACD makes a higher low.

Price is below EMA (indicating possible exhaustion in bearish trend).

2. EMA Trend Filter
EMA(200) is used as a directional filter:

Bearish divergences considered above EMA (extended bullish conditions).

Bullish divergences considered below EMA (extended bearish conditions).

3. Visual & Alerts
EMA(200) plotted on chart in orange.

Red triangles for Bearish Divergence.

Green triangles for Bullish Divergence.

Alerts fire for both divergence types.

📈 How to Use
Look for divergence signals as potential reversal alerts.

Combine with support/resistance or price action for confirmation.

EMA ensures signals occur in extended zones, increasing reliability.

Recommended Timeframes: 1h, 4h, D.
Markets: Forex, Crypto, Stocks.

⚙️ Inputs
MACD Fast / Slow / Signal Length

EMA Length (default 200)

⚠️ Disclaimer
This script is for educational purposes only. It does not constitute financial advice.
Always test thoroughly before live trading.

Disclaimer

The information and publications are not meant to be, and do not constitute, financial, investment, trading, or other types of advice or recommendations supplied or endorsed by TradingView. Read more in the Terms of Use.