PROTECTED SOURCE SCRIPT

Divergence Multi

16
1. Indicator Overview
Divergence Multi is to detect spread divergence signals between two financial market instruments. It provides references for trading decisions through visualizing spread curves and divergence marks filtered by multiple conditions, and supports various spread calculation methods and dynamic noise reduction functions.

2. My thoughts
In fact, this script is a template. When analyzing trading targets, we often need to compare different assets — divergences derived from the comparison of stock indices, treasury bonds, forex pairs and commodities are highly referenceable. Divergences based on other indicators tend to be overly complicated; we only need simple comparisons. What we should focus on is the turning points of major trends, rather than divergences at various highs and lows or indicator-specific divergences.

3. Detailed Parameter Settings
After loading the indicator, you can adjust various parameters through "Indicator Settings" (click the gear icon on the right side of the indicator name). The parameters are divided into the following categories and can be configured as needed:
3.1 Basic Market Configuration
Market 1: The first reference financial instrument, with a default value of "CME_MINI:ES1!" (E-mini S&P 500 Futures). You can manually enter other instrument codes (e.g., "FX:EURUSD" for EUR/USD forex pair, "NASDAQ:AAPL" for Apple stock).
Market 2: The second reference financial instrument, with a default value of "CBOE:VX1!" (CBOE Volatility Index Futures). It is recommended to select instruments with a certain correlation with Market 1 for more effective divergence detection.
Resolution: The data resolution (timeframe) for calculating the spread, with a default value of "15" (15-minute K-line). Optional values include "1" (1 minute), "60" (1 hour), "D" (1 day), etc.
Use current resolution?: A boolean option (enabled by default). When checked, the indicator uses the current timeframe of the chart for spread calculation; when unchecked, it uses the timeframe set in the "Resolution" parameter.
3.2 Spread Calculation Settings
Spread Calculation Type: The type of spread calculation, with three optional options:
Ratio: Calculates as (Market 1 / Market 2) * 100, suitable for comparing instruments with different price scales.
Difference: Calculates as Market 1 - Market 2, suitable for instruments with similar price ranges and high correlation.
Rate Change: Calculates as [(Market 1/Market 1[1] - 1) - (Market 2/Market 2[1] - 1)] * 100, which reflects the difference in the rate of price change between the two instruments.
EMA Length: The period of the EMA (Exponential Moving Average) for smoothing the raw spread, with a default value of 2 (minimum value is 1). A larger value will result in a smoother spread curve but may lag behind price changes.
3.3 Divergence Detection Settings
Show Divergence: A boolean option (enabled by default). When checked, the indicator displays bullish and bearish divergence signals on the chart; when unchecked, the divergence marks are hidden.
Lookback Bars: The number of bars used to calculate price and spread changes, with a default value of 1 (minimum value is 1). It determines the time interval for comparing current and historical data to identify divergence.
Extreme Filter Bars: The number of bars used to judge local price extremes, with a default value of 5 (minimum value is 3). The indicator will only detect divergence when the current price is the highest or lowest within this bar range, which helps filter invalid signals.
3.4 Dynamic Filter Settings
Enable Dynamic Filter: A boolean option (enabled by default). It is used to reduce noise and invalid divergence signals by dynamically adjusting the detection threshold.
ATR Period: The period of ATR (Average True Range) for calculating price volatility, with a default value of 14 (minimum value is 5). It provides a reference for judging the significance of price changes.
Min Ratio Multiplier: The minimum ratio multiplier for divergence strength, with a default value of 0.5 (minimum value is 0.1, adjustable in steps of 0.1). It is used to set the minimum threshold for valid divergence strength.
Strength Period: The period for calculating the moving average of divergence strength, with a default value of 10 (minimum value is 5). It is used to form a dynamic baseline for judging divergence strength.
3.5 Alert Settings
Enable Alerts: A boolean option (enabled by default). When checked, the indicator will trigger pop-up or push alerts when divergence signals are generated; when unchecked, no alerts will be sent.

4. How to Use the Indicator
4.1 Chart Display Interpretation
Spread Curve: The white curve on the chart represents the smoothed spread between the two selected instruments (calculated based on the selected spread type). It reflects the relative price relationship between the two instruments.
Divergence Marks:
Green Tiny Circles: Mark bullish divergence signals. This signal appears when the price of the current chart instrument drops (forms a local low), but the spread rises, and the signal passes the filter conditions. It is a potential bullish reversal reference signal.
Red Tiny Circles: Mark bearish divergence signals. This signal appears when the price of the current chart instrument rises (forms a local high), but the spread drops, and the signal passes the filter conditions. It is a potential bearish reversal reference signal.

Information Table: A white table is displayed in the top left corner of the chart (only on the last bar), which shows:
Current spread calculation type
Current smoothed spread value
The two selected market instruments (Market 1 and Market 2)

4.2 Practical Operation Steps
Configure Parameters: According to your trading variety and timeframe, adjust the "Market 1", "Market 2" and "Resolution" parameters first; then select the appropriate spread calculation type based on the price characteristics of the two instruments.
Filter Signals: If there are too many invalid signals, you can optimize the parameters such as "Extreme Filter Bars", "ATR Period" and "Min Ratio Multiplier" to improve the quality of divergence signals.
Reference Signals: Combine the divergence marks with the current market trend, volume and other technical indicators for comprehensive judgment (do not rely solely on this indicator for trading decisions).
Receive Alerts: Ensure that the "Enable Alerts" option is checked, and configure the alert receiving method in TradingView (e.g., email, push notification) to receive divergence signal reminders in a timely manner.

5. Notes
This indicator is only a technical analysis reference tool and cannot guarantee 100% accurate trading signals. It is recommended to combine with other analysis methods for decision-making.
When selecting Market 1 and Market 2, it is recommended to choose instruments with a certain correlation (e.g., stock index and its volatility index, related futures varieties) to improve the effectiveness of divergence detection.
Different market environments may require adjusting parameter settings (e.g., increasing the EMA length in a volatile market to smooth noise), which needs to be optimized according to actual trading experience.

Wyłączenie odpowiedzialności

Informacje i publikacje nie stanowią i nie powinny być traktowane jako porady finansowe, inwestycyjne, tradingowe ani jakiekolwiek inne rekomendacje dostarczane lub zatwierdzone przez TradingView. Więcej informacji znajduje się w Warunkach użytkowania.