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
開源腳本
本著TradingView的真正精神,此腳本的創建者將其開源,以便交易者可以查看和驗證其功能。向作者致敬!雖然您可以免費使用它,但請記住,重新發佈程式碼必須遵守我們的網站規則。
免責聲明
這些資訊和出版物並不意味著也不構成TradingView提供或認可的金融、投資、交易或其他類型的意見或建議。請在使用條款閱讀更多資訊。
開源腳本
本著TradingView的真正精神,此腳本的創建者將其開源,以便交易者可以查看和驗證其功能。向作者致敬!雖然您可以免費使用它,但請記住,重新發佈程式碼必須遵守我們的網站規則。
免責聲明
這些資訊和出版物並不意味著也不構成TradingView提供或認可的金融、投資、交易或其他類型的意見或建議。請在使用條款閱讀更多資訊。