OPEN-SOURCE SCRIPT
MA & Divergence in RSI & MACD

This Pine Script is a multi-feature trading indicator for TradingView, titled:
🟢 "MA & Divergence in RSI & MACD"
It combines multiple moving averages, Golden/Death Cross signals, and RSI/MACD divergence detection from a lower timeframe (LTF), all on your main chart (overlay = true).
Main Features Breakdown:
The script dynamically adjusts the MA period lengths depending on your current chart timeframe:
These affect:
Pine Script®
You can also choose between EMA and SMA using the input:
📊 2. Moving Average Label Display
The script shows live MA values as labels on the most recent candle. Each label includes:
📈 3. Golden Cross & Death Cross Detection
Two sets of crossover events:
⚙️ Standard:
Pine Script®
Usually, these are MA 50 crossing MA 100 (medium vs long).
Pine Script®
📉 4. RSI & MACD Divergence Detection (from LTF)
Compares price movement to RSI and MACD values from a lower timeframe (default: 15 min).
Flags bullish and bearish divergence using pivot lows/highs.
🛠 Internal LTF Requests:
Uses request.security to pull lower-timeframe data into current chart:
Pine Script®
🔔 5. Alerts
Supports these alerts:
✅ Use Case Example
If you’re on a 1H or 4H chart:
🟢 "MA & Divergence in RSI & MACD"
It combines multiple moving averages, Golden/Death Cross signals, and RSI/MACD divergence detection from a lower timeframe (LTF), all on your main chart (overlay = true).
Main Features Breakdown:
The script dynamically adjusts the MA period lengths depending on your current chart timeframe:
- Daily
- 4-Hour
- 1-Hour
- Other Intraday
These affect:
ma1_default = 100 // Long MA
ma2_default = 200 // Very long MA
ma3_default = varies // Medium MA (50-72)
ma4_default = varies // Short MA (20-48)
ma5_default = varies // Fast MA (7-24)
You can also choose between EMA and SMA using the input:
📊 2. Moving Average Label Display
The script shows live MA values as labels on the most recent candle. Each label includes:
- The MA period
- The current value
- The type (EMA or SMA)
📈 3. Golden Cross & Death Cross Detection
Two sets of crossover events:
⚙️ Standard:
goldenCross = crossover(ma3, ma1)
deathCross = crossunder(ma3, ma1)
Usually, these are MA 50 crossing MA 100 (medium vs long).
goldenCrossFast = crossover(ma4, ma2)
deathCrossFast = crossunder(ma4, ma2)
📉 4. RSI & MACD Divergence Detection (from LTF)
Compares price movement to RSI and MACD values from a lower timeframe (default: 15 min).
Flags bullish and bearish divergence using pivot lows/highs.
🛠 Internal LTF Requests:
Uses request.security to pull lower-timeframe data into current chart:
rsiLtf = request.security(..., ltf, ta.rsi(...))
macdLtf = request.security(..., ltf, macdLineOnly(...))
priceLowLtf = request.security(..., ltf, low)
priceHighLtf = request.security(..., ltf, high)
🔔 5. Alerts
Supports these alerts:
- Golden Cross
- Death Cross
- Bullish Divergence
- Bearish Divergence
✅ Use Case Example
If you’re on a 1H or 4H chart:
- The script will auto-tune MA lengths
- Pull divergence signals from 15-min RSI and MACD
- Show if you’ve got a bullish divergence forming while a Golden Cross just occurred
- Provide a visual + alert-based system to decide trade entries/exits
Skrip sumber terbuka
Dalam semangat sebenar TradingView, pencipta skrip ini telah menjadikannya sumber terbuka supaya pedagang dapat menilai dan mengesahkan kefungsiannya. Terima kasih kepada penulis! Walaupun anda boleh menggunakannya secara percuma, ingat bahawa menerbitkan semula kod ini adalah tertakluk kepada Peraturan Dalaman kami.
Penafian
Maklumat dan penerbitan adalah tidak dimaksudkan untuk menjadi, dan tidak membentuk, nasihat untuk kewangan, pelaburan, perdagangan dan jenis-jenis lain atau cadangan yang dibekalkan atau disahkan oleh TradingView. Baca dengan lebih lanjut di Terma Penggunaan.
Skrip sumber terbuka
Dalam semangat sebenar TradingView, pencipta skrip ini telah menjadikannya sumber terbuka supaya pedagang dapat menilai dan mengesahkan kefungsiannya. Terima kasih kepada penulis! Walaupun anda boleh menggunakannya secara percuma, ingat bahawa menerbitkan semula kod ini adalah tertakluk kepada Peraturan Dalaman kami.
Penafian
Maklumat dan penerbitan adalah tidak dimaksudkan untuk menjadi, dan tidak membentuk, nasihat untuk kewangan, pelaburan, perdagangan dan jenis-jenis lain atau cadangan yang dibekalkan atau disahkan oleh TradingView. Baca dengan lebih lanjut di Terma Penggunaan.