OPEN-SOURCE SCRIPT
Enhanced MFI Divergence with Pivot Signals

Enhanced MFI Divergence with Pivot Signals
This custom Pine Script indicator identifies bullish and bearish divergences between price action and the Money Flow Index (MFI), enhancing the trader's ability to spot potential reversal zones with visual clarity and optional confirmation filters.
📊 Key Features:
🔹 MFI Divergence Detection
The script detects:
Bullish divergence when price forms a lower low but MFI forms a higher low.
Bearish divergence when price forms a higher high but MFI forms a lower high.
🔹 Pivot-Based Logic
To ensure high-confidence signals, the script uses pivot point logic to mark local highs and lows on both price and MFI. This avoids noise and focuses only on meaningful swing points.
🔹 Optional Confirmation Filter
You can enable a filter that checks if MFI is above 50 during bullish divergence (implying buying pressure) and below 50 for bearish divergence (implying selling pressure), adding an extra layer of confirmation.
🔹 Signal Markers
Signals are visually displayed on the chart using colored triangles:
Green triangle up for bullish divergence
Red triangle down for bearish divergence
🔹 Background Color Shading
The background is optionally shaded green or red based on MFI’s relationship to its smoothed WMA, helping you visually interpret trend bias.
🔹 Pivot Point Debugging Tools
Circles and crosses mark pivot points on price and MFI for debugging and visual clarity.
🔹 Alerts Ready
Real-time alerts notify you instantly when a bullish or bearish MFI divergence occurs, allowing for quick decision-making.
⚙️ How It Helps
This indicator is designed to help traders:
Anticipate price reversals by identifying hidden strength or weakness in momentum,
Avoid false breakouts,
Confirm entries or exits based on volume-weighted momentum divergence.
It works especially well when used alongside trend-following tools like moving averages, support/resistance zones, or additional volume indicators.
This custom Pine Script indicator identifies bullish and bearish divergences between price action and the Money Flow Index (MFI), enhancing the trader's ability to spot potential reversal zones with visual clarity and optional confirmation filters.
📊 Key Features:
🔹 MFI Divergence Detection
The script detects:
Bullish divergence when price forms a lower low but MFI forms a higher low.
Bearish divergence when price forms a higher high but MFI forms a lower high.
🔹 Pivot-Based Logic
To ensure high-confidence signals, the script uses pivot point logic to mark local highs and lows on both price and MFI. This avoids noise and focuses only on meaningful swing points.
🔹 Optional Confirmation Filter
You can enable a filter that checks if MFI is above 50 during bullish divergence (implying buying pressure) and below 50 for bearish divergence (implying selling pressure), adding an extra layer of confirmation.
🔹 Signal Markers
Signals are visually displayed on the chart using colored triangles:
Green triangle up for bullish divergence
Red triangle down for bearish divergence
🔹 Background Color Shading
The background is optionally shaded green or red based on MFI’s relationship to its smoothed WMA, helping you visually interpret trend bias.
🔹 Pivot Point Debugging Tools
Circles and crosses mark pivot points on price and MFI for debugging and visual clarity.
🔹 Alerts Ready
Real-time alerts notify you instantly when a bullish or bearish MFI divergence occurs, allowing for quick decision-making.
⚙️ How It Helps
This indicator is designed to help traders:
Anticipate price reversals by identifying hidden strength or weakness in momentum,
Avoid false breakouts,
Confirm entries or exits based on volume-weighted momentum divergence.
It works especially well when used alongside trend-following tools like moving averages, support/resistance zones, or additional volume indicators.
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.