Divergence Regime Filter + FVG Entries

333
Divergence Regime Filter + FVG Entries

A trend-vs-range filter built on divergence behavior, with counter-trend entries confirmed by a displacement Fair Value Gap.

Concept

In strong trends, clean and meaningful divergences tend to form (bearish divergences in uptrends, bullish divergences in downtrends). In ranges, price rarely makes a proper higher high or lower low, so clean divergences don't form, or bullish and bearish ones appear together. This script uses that behavior to classify the market as Bullish Trend, Bearish Trend or Ranging, then trades the divergence against the trend once it confirms.

How it works

1. Divergence detection
The script finds regular bullish and bearish divergences using pivots on your choice of oscillator (RSI, MACD Histogram, CCI, Stoch RSI or MFI). A divergence must pass quality checks to count:

The price move between pivots must be at least a set multiple of ATR.
The oscillator difference must be at least a set multiple of the oscillator's own standard deviation.
The pivots must be within a minimum and maximum number of bars of each other.

Divergences are confirmed only after the right-side pivot bars have printed, so there is a built-in confirmation delay.

2. Dynamic regime filter

Bullish trend: price is above a rising EMA, the slope is strong relative to its own 100-bar average (so it adapts to volatility), and bearish divergences have formed recently and outnumber bullish ones.
Bearish trend: the mirror image, with bullish divergences outnumbering bearish ones.
Ranging: anything else, such as no clean divergences, mixed divergences or a weak slope.

The chart background and the EMA color show the current regime.

3. Entry signals (counter-trend)

Buy: a bullish divergence confirms during a bearish trend.
Sell: a bearish divergence confirms during a bullish trend.

A small circle marks the early signal on the bar where the divergence confirms.

4. FVG confirmation
A full BUY or SELL label prints when a significant FVG forms in the signal direction within N bars (default 10) of the divergence confirming. The FVG needs a minimum gap size and a strong displacement candle in the middle, both measured in ATR. The FVG is drawn as a box. A pending setup is cancelled if price closes beyond the divergence pivot (optional) or the window expires.

Features
Sensitivity presets: Loose, Balanced, Strict and Custom
Five oscillator choices
Divergence lines, colored by whether they align with the regime
Dashboard showing regime, divergence counts, slope strength and remaining FVG window for pending setups
Alerts for Buy, Sell, early signals and regime changes
Option to disable the FVG requirement and trade the early signal alone
Settings guide
Sensitivity preset: the fastest way to get more or fewer signals. Custom unlocks the individual inputs.
Divergence memory: how many bars back divergences count toward the regime.
Min aligned divergences: raise it to demand more evidence before calling a trend.
FVG window / size / displacement: control how strict the confirmation is.
Usage tips
Use the regime background as a filter. Signals are only generated in trending regimes, so treat a ranging background as a reason to stand aside.
Signals are counter-trend, so consider your own stop placement (for example beyond the divergence pivot or the FVG) and higher-timeframe context.
Test different oscillators and presets per market and timeframe.
Notes
Divergence signals are confirmed after the pivot forms, so entries come later than the actual pivot. This is by design, to avoid repainting.
Signals are evaluated on closed bars.

Disclaimer: This indicator is for educational and informational purposes only and is not financial advice. Past performance does not guarantee future results. Always backtest and use proper risk management.

إخلاء المسؤولية

لا يُقصد بالمعلومات والمنشورات أن تكون، أو تشكل، أي نصيحة مالية أو استثمارية أو تجارية أو أنواع أخرى من النصائح أو التوصيات المقدمة أو المعتمدة من TradingView. اقرأ المزيد في شروط الاستخدام.