OPEN-SOURCE SCRIPT
已更新 Divergences - Elliott Wave Filtered

Divergences — Elliott Wave Filtered
A multi-oscillator divergence detection system that filters signals through a three-degree Elliott Wave engine and Bayesian probability fusion. Distinguishes between Regular divergences (reversal signals at wave ends) and Hidden divergences (continuation signals during corrections) using wave position scoring, Hurst regime analysis, and statistical quality metrics.
What It Does
This indicator scans for price-oscillator divergences across four technical indicators (RSI, Stochastic RSI, MFI, ROC) and validates them against real-time Elliott Wave structure. Unlike standard divergence indicators that fire indiscriminately, this system employs a wave-context gate — divergences only trigger if they align with specific wave positions (e.g., W5 endings for reversals, W2/W4 depths for continuations) across Small, Medium, and Large degrees.
The Six Analytical Pillars
Key Features
Inputs & Parameters
Divergence Detection
Wave Filter — Regular vs Hidden
Multi-Oscillator Concordance
Statistical Quality & Bayesian Weights
Wave Engine (Three Degrees)
How to Read It
Signal Logic & Validation
Important Notes
Mathematical Summary
Wave Position Base Scores (Regular)
W5 = 0.92, Diagonal = 0.88, Corr C = 0.65, Tri E = 0.60,
W4 = 0.42, W2 = 0.38, Neutral = 0.50, W3 = 0.12
Wave Position Base Scores (Hidden)
W2 = 0.90, W4 = 0.88, Corr C = 0.70, Neutral = 0.50,
W5 = 0.15, W3 = 0.35
Cross-Degree Modifiers
Triple Agreement = +0.20 (Tri Boost)
Dual Agreement = +0.15 (Agree Boost)
Single High vs Others Low = -0.20 to -0.28 (Conflict Penalty)
Bayesian Fusion
L = PriorLO + Σ(Weight_i × log(p_i / (1 - p_i)))
Posterior = 1 / (1 + exp(-L))
Impulse Quality
Quality = (Momentum × 0.35) + (Channel × 0.35) + (Alternation × 0.30)
FinalWaveScore = BaseScore + (BaseScore - 0.5) × Quality × 0.3
A multi-oscillator divergence detection system that filters signals through a three-degree Elliott Wave engine and Bayesian probability fusion. Distinguishes between Regular divergences (reversal signals at wave ends) and Hidden divergences (continuation signals during corrections) using wave position scoring, Hurst regime analysis, and statistical quality metrics.
What It Does
This indicator scans for price-oscillator divergences across four technical indicators (RSI, Stochastic RSI, MFI, ROC) and validates them against real-time Elliott Wave structure. Unlike standard divergence indicators that fire indiscriminately, this system employs a wave-context gate — divergences only trigger if they align with specific wave positions (e.g., W5 endings for reversals, W2/W4 depths for continuations) across Small, Medium, and Large degrees.
- Regular Divergences (Reversal): Price makes higher high / lower low while oscillator makes lower high / higher low. Filtered for W5, Diagonal, Corrective C, Triangle E, and W4/W2 endings where trend exhaustion is probable.
- Hidden Divergences (Continuation): Price makes higher low / lower high while oscillator makes lower low / higher high. Filtered for W2, W4, and Corrective C positions where trend resumption is probable.
The Six Analytical Pillars
- Multi-Oscillator Concordance: Requires minimum 2-of-4 oscillators (RSI, Stoch RSI, MFI, ROC) to simultaneously register divergence, eliminating single-indicator false positives.
- Tri-Degree Wave Engine: Runs independent swing detection on Small (micro), Medium (minor), and Large (primary) degrees to determine if the divergence occurs at a significant wave node.
- Wave Position Scoring: Assigns base probabilities (0.0–1.0) to wave positions — W5 (0.92), Diagonal (0.88), W2 (0.38), W4 (0.42), etc. — with separate score tables for Regular vs Hidden divergence contexts.
- Cross-Degree Modifiers: Boosts probability when multiple degrees agree (e.g., Small=W5 + Medium=W5) or penalizes when they conflict (e.g., Small=W5 + Medium=W3).
- Regime Detection: Integrates Hurst Exponent (mean-reversion vs persistence) and Shannon Entropy (market disorder) to weight divergence reliability — low Hurst (<0.5) favors reversal divergences, high entropy reduces signal confidence.
- Bayesian Fusion: Combines concordance, z-score magnitude, wave context, trend agreement, and over-extension ratios through log-odds transformation to produce a final 0.0–1.0 probability score.
Key Features
- Wave Type Filtering: Independent toggle sets for Regular vs Hidden divergences — e.g., allow W5+Diagonal+Triangle E for reversals, but only W2+W4+Corr C for continuations.
- Slope Non-Intersection: Optional validation ensuring price does not cross the linear slope between P1 and P2 pivots (clean divergence requirement).
- Dynamic Target Projection: Upon valid divergence, projects Fibonacci extension targets (61.8%, 100%, 161.8%) from the swing leg and plots invalidation levels (pivot ± ticks).
- Degree Proximity Scaling: Small degree waves must be within 12 bars of divergence, Medium within 24 bars, Large within 48 bars — ensuring temporal relevance.
- Quality Gradient: Impulse and Diagonal patterns receive quality scores (0.0–1.0) based on momentum, channel alignment, and alternation, scaling the base wave position probability.
- Trend Agreement Check: Validates that divergence direction opposes (Regular) or aligns with (Hidden) the detected wave trend direction across degrees.
Inputs & Parameters
Divergence Detection
- Pivot Left/Right Bars: Confirmation delay and lookback for pivot detection (default 3/1).
- Min/Max Bars P1→P2: Time window constraints for valid divergence legs (default 5–unlimited).
- Cooldown Bars: Minimum spacing between same-direction signals to prevent clustering (default 8).
- Require Slope Non-Intersection: Toggle strict linear slope validation.
Wave Filter — Regular vs Hidden
- Enable wave filter: Master toggle for each divergence type.
- Degree to check: Any, Small, Medium, Large, or All Degrees (consensus requirement).
- Allowed wave positions: Independent toggles for W5, Diagonal, W3, W2, W4, Corr C, Triangle E, and No Context.
Multi-Oscillator Concordance
- Individual length settings for RSI (33), Stoch RSI (33, %K 6), MFI (33), ROC (33).
- Min concordance: Required number of oscillators showing divergence (default 2 of 4).
- OB/OS Zones: Overbought/oversold thresholds for RSI (70/30), Stoch (80/20), MFI (80/20).
Statistical Quality & Bayesian Weights
- Z-score threshold: RSI deviation sensitivity (default 1.5).
- Hurst lookback/entropy bins: Regime calculation windows.
- Fusion weights: Concordance (0.28), Z-score (0.12), Hurst (0.12), Entropy (0.08), Wave context (0.25), Over-extension (0.08), Trend agreement (0.07).
- Prior log-odds: Base bias adjustment (−3 to +3).
- Min Score: Probability threshold for signal emission (default 0.85).
Wave Engine (Three Degrees)
- Small: Left 3–30, Right 1–3, Min swing 0.08%.
- Medium: Left 10–80, Right 1–5, Min swing 0.20%.
- Large: Left 25–200, Right 2–10, Min swing 0.50%.
- Wave-div proximity: 12 bars (Small), scaled 2×/4× for Medium/Large.
How to Read It
- Divergence Labels:
- R↑ (Green): Regular Bullish divergence — price lower low, oscillator higher low. Expect reversal up.
- R↓ (Red): Regular Bearish divergence — price higher high, oscillator lower high. Expect reversal down.
- H↑ (Teal): Hidden Bullish divergence — price higher low, oscillator lower low. Expect continuation up.
- H↓ (Orange): Hidden Bearish divergence — price lower high, oscillator higher high. Expect continuation down.
- R↑ (Green): Regular Bullish divergence — price lower low, oscillator higher low. Expect reversal up.
- Label Annotations: Format "Type Concordance/Total Score% WavePos" — e.g., "R↑ 3/4 92% W5/mW5" indicates 3 of 4 oscillators agree, 92% Bayesian probability, Small=W5, Medium=W5.
- Dotted Lines: Connect P1 (previous pivot) to P2 (current pivot) showing the divergence slope.
- Target Lines: Horizontal dashed lines at T1 (61.8%), T2 (100%), T3 (161.8%) projected from the divergence leg.
- Invalidation Line: Solid grey line at the pivot price ± tick buffer — crossing this invalidates the divergence setup.
- Dashboard (Top-Right): Displays current Hurst (green <0.5 mean-reverting, red >0.5 trending), Entropy (high = disorder), and detected wave positions for S/M/L degrees.
Signal Logic & Validation
- Base Conditions: Price pivot confirmed, oscillator divergence detected, concordance ≥ minimum, within P1–P2 time window, cooldown satisfied.
- Wave Filter Gate: Divergence bar must be within proximity window of a classified wave end (W5, Diag, W2, W4, etc.) on the specified degree(s).
- Bayesian Calculation: Each component (concordance, z-score, Hurst, entropy, wave context, over-extension, trend) is converted to log-odds, weighted, summed with prior, and transformed back to probability.
- Emission Threshold: Final probability must exceed Min Score (default 85%) to plot signal.
- Over-Extension Ratio: Measures leg length vs previous similar leg — ratios >2.0 increase reversal probability (exhaustion signature).
Important Notes
- Wave Position Scoring: Regular and Hidden divergences use inverted score tables. W5 scores 0.92 for Regular (strong reversal) but only 0.15 for Hidden (weak continuation). Conversely, W2 scores 0.38 for Regular but 0.90 for Hidden.
- Cross-Degree Conflict: When degrees disagree (e.g., Small=W5 bullish, Medium=W3 bullish continuation), the system applies conflict penalties (−0.20 to −0.28) to the composite score, often suppressing the signal unless other factors compensate.
- Hurst Interpretation: Hurst < 0.5 (mean-reversion regime) adds probability to Regular divergences (reversal expected) and reduces Hidden divergence scores. Hurst > 0.5 (trending) does the opposite.
- Entropy Impact: High entropy (>0.7) indicates chaotic, non-cyclical market conditions — the system reduces confidence in all divergences during high entropy regimes.
- Non-Intersection Validation: When enabled, the system checks that no intermediate bar crosses the linear interpolation between P1 and P2 pivots, ensuring "clean" divergence without whipsaw noise.
- Quality Scaling: Impulse patterns are scored on momentum (W3 strength), channel parallelism, and alternation (W2 vs W4 slope difference). Higher quality waves boost the base position score by up to 30%.
- No Repainting: Uses confirmed pivots (right bars ≥ 1) and historical bar indexing. Once a divergence is plotted at P2 confirmation bar, it remains fixed.
Mathematical Summary
Wave Position Base Scores (Regular)
W5 = 0.92, Diagonal = 0.88, Corr C = 0.65, Tri E = 0.60,
W4 = 0.42, W2 = 0.38, Neutral = 0.50, W3 = 0.12
Wave Position Base Scores (Hidden)
W2 = 0.90, W4 = 0.88, Corr C = 0.70, Neutral = 0.50,
W5 = 0.15, W3 = 0.35
Cross-Degree Modifiers
Triple Agreement = +0.20 (Tri Boost)
Dual Agreement = +0.15 (Agree Boost)
Single High vs Others Low = -0.20 to -0.28 (Conflict Penalty)
Bayesian Fusion
L = PriorLO + Σ(Weight_i × log(p_i / (1 - p_i)))
Posterior = 1 / (1 + exp(-L))
Impulse Quality
Quality = (Momentum × 0.35) + (Channel × 0.35) + (Alternation × 0.30)
FinalWaveScore = BaseScore + (BaseScore - 0.5) × Quality × 0.3
版本注释
Added alerts 开源脚本
秉承TradingView的精神,该脚本的作者将其开源,以便交易者可以查看和验证其功能。向作者致敬!您可以免费使用该脚本,但请记住,重新发布代码须遵守我们的网站规则。
免责声明
这些信息和出版物并非旨在提供,也不构成TradingView提供或认可的任何形式的财务、投资、交易或其他类型的建议或推荐。请阅读使用条款了解更多信息。
开源脚本
秉承TradingView的精神,该脚本的作者将其开源,以便交易者可以查看和验证其功能。向作者致敬!您可以免费使用该脚本,但请记住,重新发布代码须遵守我们的网站规则。
免责声明
这些信息和出版物并非旨在提供,也不构成TradingView提供或认可的任何形式的财务、投资、交易或其他类型的建议或推荐。请阅读使用条款了解更多信息。