OPEN-SOURCE SCRIPT

Divergence Screener [Trendoscope®]

1 239
🎲Overview
The Divergence Screener is a powerful TradingView indicator designed to detect and visualize bullish and bearish divergences, including hidden divergences, between price action and a user-selected oscillator. Built with flexibility in mind, it allows traders to customize the oscillator type, trend detection method, and other parameters to suit various trading strategies. The indicator is non-overlay, displaying divergence signals directly on the oscillator plot, with visual cues such as lines and labels on the chart for easy identification.

This indicator is ideal for traders seeking to identify potential reversal or continuation signals based on price-oscillator divergences. It supports multiple oscillators, trend detection methods, and alert configurations, making it versatile for different markets and timeframes.

🎲Features
🎯Customizable Oscillator Selection
  • Built-in Oscillators: Choose from a variety of oscillators including RSI, CCI, CMO, COG, MFI, ROC, Stochastic, and WPR.
  • External Oscillator Support: Users can input an external oscillator source, allowing integration with custom or third-party indicators.
  • Configurable Length: Adjust the oscillator’s period (e.g., 14 for RSI) to fine-tune sensitivity.

快照
🎯Divergence Detection
The screener identifies four types of divergences:
  • Bullish Divergence: Price forms a lower low, but the oscillator forms a higher low, signaling potential upward reversal.
  • Bearish Divergence: Price forms a higher high, but the oscillator forms a lower high, indicating potential downward reversal.
  • Bullish Hidden Divergence: Price forms a higher low, but the oscillator forms a lower low, suggesting trend continuation in an uptrend.
  • Bearish Hidden Divergence: Price forms a lower high, but the oscillator forms a higher high, suggesting trend continuation in a downtrend.

快照
快照
🎯Flexible Trend Detection
  • The indicator offers three methods to determine the trend context for divergence detection:
  • Zigzag: Uses zigzag pivots to identify trends based on higher highs (HH), higher lows (HL), lower highs (LH), and lower lows (LL).
  • MA Difference: Calculates the trend based on the difference in a moving average (e.g., SMA, EMA) between divergence pivots.
  • External Trend Signal: Allows users to input an external trend signal (positive for uptrend, negative for downtrend) for custom trend analysis.

快照
🎯Zigzag-Based Pivot Analysis
  • Customizable Zigzag Length: Adjust the zigzag length (default: 13) to control the sensitivity of pivot detection.
  • Repaint Option: Choose whether divergence lines repaint based on the latest data or wait for confirmed pivots, balancing responsiveness and reliability.

🎯Visual and Alert Features
  • Divergence Visualization: Divergence lines are drawn between price pivots and oscillator pivots, color-coded for easy identification:
    Bullish Divergence: Green
    Bearish Divergence: Red
    Bullish Hidden Divergence: Lime
    Bearish Hidden Divergence: Orange
  • Labels and Tooltips: Labels (e.g., “D” for divergence, “H” for hidden) appear on price and oscillator pivots, with tooltips providing detailed information such as price/oscillator values, ratios, and pivot directions.
  • Alerts: Configurable alerts for each divergence type (bullish, bearish, bullish hidden, bearish hidden) trigger on bar close, ensuring timely notifications.

快照
🎲 How It Works
🎯Oscillator Calculation
  • The indicator calculates the selected oscillator (or uses an external source) and plots it on the chart.
  • Oscillator values are stored in a map for reference during divergence calculations.

🎯Pivot Detection
  • A zigzag algorithm identifies pivots in the oscillator data, with configurable length and repainting options.
  • Price and oscillator pivots are compared to detect divergences based on their direction and ratio.

🎯Divergence Identification
  • The indicator compares price and oscillator pivot directions (HH, HL, LH, LL) to identify divergences.
  • Trend context is determined using the selected method (Zigzag, MA Difference, or External).
  • Divergences are classified as bullish, bearish, bullish hidden, or bearish hidden based on price-oscillator relationships and trend direction.

🎯Visualization and Alerts
  • Valid divergences are drawn as lines connecting price and oscillator pivots, with corresponding labels.
  • Alerts are triggered for allowed divergence types, providing detailed information via tooltips.

🎯Validation
Divergence lines are validated to ensure no intermediate bars violate the divergence condition, enhancing signal reliability.

🎲 Usage Instructions as Indicator
🎯Add to Chart:
  • Add the “Divergence Screener [Trendoscope®]” to your TradingView chart.
  • The indicator appears in a separate pane below the price chart, plotting the oscillator and divergence signals.

🎯Configure Settings:
  • Adjust the oscillator type and length to match your trading style.
  • Select a trend detection method and configure related parameters (e.g., MA type/length or external signal).
  • Set the zigzag length and repainting preference.
  • Enable/disable alerts for specific divergence types.

I🎯nterpret Signals:
  • Bullish Divergence (Green): Look for potential buy opportunities in a downtrend.
  • Bearish Divergence (Red): Consider sell opportunities in an uptrend.
  • Bullish Hidden Divergence (Lime): Confirm continuation in an uptrend.
  • Bearish Hidden Divergence (Orange): Confirm continuation in a downtrend.
  • Use tooltips on labels to review detailed pivot and divergence information.

🎯Set Alerts:
  • Create alerts for each divergence type to receive notifications via TradingView’s alert system.
  • Alerts include detailed text with price, oscillator, and divergence information.


🎲 Example Scenarios as Indicator
🎯 With External Oscillator (Use MACD Histogram as Oscillator)
In order to use MACD as an oscillator for divergence signal instead of the built in options, follow these steps.
  1. Load MACD Indicator from Indicator library
  2. From Indicator settings of Divergence Screener, set Use External Oscillator and select MACD Histograme from the dropdown
  3. You can now see that the oscillator pane shows the data of selected MACD histogram and divergence signals are generated based on the external MACD histogram data.

快照
🎯 With External Trend Signal (Supertrend Ladder ATR)
Now let's demonstrate how to use external direction signals using Supertrend Ladder ATR indicator. Please note that in order to use the indicator as trend source, the indicator should return positive integer for uptrend and negative integer for downtrend. Steps are as follows:
  1. Load the desired trend indicator. In this example, we are using Supertrend Ladder ATR
  2. From the settings of Divergence Screener, select "External" as Trend Detection Method
  3. Select the trend detection plot Direction from the dropdown. You can now see that the divergence signals will rely on the new trend settings rather than the built in options.

快照

🎲 Using the Script with Pine Screener
The primary purpose of the Divergence Screener is to enable traders to scan multiple instruments (e.g., stocks, ETFs, forex pairs) for divergence signals using TradingView’s Pine Screener, facilitating efficient comparison and identification of trading opportunities.

To use the Divergence Screener as a screener, follow these steps:
  • Add to Favorites: Add the Divergence Screener [Trendoscope®] to your TradingView favorites to make it available in the Pine Screener.
  • Create a Watchlist: Build a watchlist containing the instruments (e.g., stocks, ETFs, or forex pairs) you want to scan for divergences.
  • Access Pine Screener: Navigate to the Pine Screener via TradingView’s main menu: Products -> Screeners -> Pine, or directly visit tradingview.com/pine-screener/.
  • Select Watchlist: Choose the watchlist you created from the Watchlist dropdown in the Pine Screener interface.
  • Choose Indicator: Select Divergence Screener [Trendoscope®] from the Choose Indicator dropdown.
  • Configure Settings: Set the desired timeframe (e.g., 1 hour, 1 day) and adjust indicator settings such as oscillator type, zigzag length, or trend detection method as needed.
  • Select Filter Criteria: Select the condition on which the watchlist items needs to be filtered. Filtering can only be done on the plots defined in the script.
  • Run Scan: Press the Scan button to display divergence signals across the selected instruments. The screener will show which instruments exhibit bullish, bearish, bullish hidden, or bearish hidden divergences based on the configured settings.

快照

🎲 Limitations and Possible Future Enhancements
Limitations are
  • Custom input for oscillator and trend detection cannot be used in pine screener.
  • Pine screener has max 500 bars available.
  • Repaint option is by default enabled. When in repaint mode expect the early signal but the signals are prone to repaint.

Possible future enhancements
  • Add more built-in options for oscillators and trend detection methods so that dependency on external indicators is limited
  • Multi level zigzag support

免責聲明

這些資訊和出版物並不意味著也不構成TradingView提供或認可的金融、投資、交易或其他類型的意見或建議。請在使用條款閱讀更多資訊。