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
Script open-source
In pieno spirito TradingView, il creatore di questo script lo ha reso open-source, in modo che i trader possano esaminarlo e verificarne la funzionalità. Complimenti all'autore! Sebbene sia possibile utilizzarlo gratuitamente, ricorda che la ripubblicazione del codice è soggetta al nostro Regolamento.
Declinazione di responsabilità
Le informazioni ed i contenuti pubblicati non costituiscono in alcun modo una sollecitazione ad investire o ad operare nei mercati finanziari. Non sono inoltre fornite o supportate da TradingView. Maggiori dettagli nelle Condizioni d'uso.
Script open-source
In pieno spirito TradingView, il creatore di questo script lo ha reso open-source, in modo che i trader possano esaminarlo e verificarne la funzionalità. Complimenti all'autore! Sebbene sia possibile utilizzarlo gratuitamente, ricorda che la ripubblicazione del codice è soggetta al nostro Regolamento.
Declinazione di responsabilità
Le informazioni ed i contenuti pubblicati non costituiscono in alcun modo una sollecitazione ad investire o ad operare nei mercati finanziari. Non sono inoltre fornite o supportate da TradingView. Maggiori dettagli nelle Condizioni d'uso.