OPEN-SOURCE SCRIPT
Diupdate Dept Fractals

Description:
Dept Fractals is a multi-filter reversal detection indicator that identifies high-probability pivot points by requiring three independent conditions to fire simultaneously on the same bar. It is designed for higher timeframes (1H+) across crypto, forex, and futures markets.
The problem it solves
Standard fractal indicators (Williams Fractals, built-in Pivot Points) mark every local high and low, producing dozens of signals per chart with no context filtering. Most of these pivots are noise — minor fluctuations that do not lead to meaningful reversals. Dept Fractals addresses this by requiring three statistically independent confirmations before marking a reversal point.
How the three filters work together
Filter 1 — Adaptive Volatility Envelope (determines IF price is at an extreme)
The script constructs a dynamic envelope around price using the following specific method:
Price data is log-transformed before processing. This makes the envelope symmetrical in percentage terms — a critical difference from standard Bollinger Bands, which produce asymmetric zones on trending instruments because they operate on linear price.
The log-price is smoothed using an Ehlers two-pole super smoother (imported via the KevanoTrades/Ehlers_Super_Smoother library). This smoother has significantly less lag than a simple or exponential moving average of equivalent period, allowing the envelope to track structural price shifts more responsively.
Envelope width is determined by the smoothed true range of the log-price series, multiplied by a user-configurable amplitude parameter. This means the envelope automatically widens during high-volatility regimes and contracts during low-volatility regimes — no manual adjustment needed when switching instruments.
A bearish signal requires the pivot high to reach or exceed the upper envelope. A bullish signal requires the pivot low to touch or breach the lower envelope.
Why this matters: RSI and Stochastic use fixed periods and static overbought/oversold levels (70/30). They generate false signals during strong trends because they stay pegged at extremes. The adaptive envelope avoids this by dynamically scaling with volatility.
Filter 2 — Structural Pivot with ATR Gate (determines WHERE the reversal formed)
The script uses ta.pivothigh() and ta.pivotlow() with a configurable left/right period (default: 3 bars each side = 7-bar confirmation window).
An ATR(14)-based minimum range filter requires the pivot candle to have a range of at least [ATR Gate multiplier] x ATR(14). This removes small, indecisive candles that technically satisfy the pivot definition but carry no real reversal weight.
Filter 3 — Momentum Confirmation + Follow-through (determines WHEN the reversal is confirmed)
A long-period ta.mom() oscillator (default: 50 bars) must already be changing direction at the pivot candle. For bearish fractals, momentum at the pivot must be lower than the previous bar's momentum. For bullish fractals, momentum must be higher.
Additionally, the candle immediately following the pivot (bar at offset pLen-1) must close in the direction of the reversal: bearish close for short signals, bullish close for long signals. This follow-through requirement filters out pivots where price forms an extreme but immediately continues in the original direction.
All three filters must pass simultaneously. If any single filter fails, no signal is generated.
Built-in win rate statistics
The indicator tracks historical performance using ATR-based stop loss and configurable R:R take profit. The counting method is intentionally conservative:
Stop loss = user-defined ATR multiplier beyond the pivot extreme
Take profit = user-defined risk-reward ratio
If a new signal appears before the previous trade resolves, the unresolved trade is counted as a loss
If both TP and SL are hit on the same bar, it is counted as a loss
This ensures the displayed win rate is not inflated by incomplete or ambiguous trades.
Signals
L (green label below bar) — confirmed bullish reversal: price was in the oversold envelope zone, pivot candle was significant relative to ATR, momentum turned up, and the next candle confirmed with a bullish close.
S (red label above bar) — confirmed bearish reversal: price was in the overbought envelope zone, pivot candle was significant, momentum turned down, and the next candle confirmed with a bearish close.
Signals appear with a delay equal to the Pivot Period setting (default: 3 bars) because this time is required for structural confirmation. The indicator does not repaint — once a signal appears, it stays.
Settings
Core parameters:
Pivot Period (default 3): bars left and right for pivot detection. Range 1-15.
ATR Gate (default 0.5): minimum pivot candle range as multiple of ATR(14). Range 0.1-3.0.
Momentum Period (default 50): period for ta.mom() oscillator. Range 10-200.
Adaptive Envelope parameters:
Source (default hlc3): price input for envelope calculation.
Lookback (default 200): period for Ehlers two-pole smoother. Range 50-500.
Amplitude (default 3.5): envelope width multiplier. Lower = wider zones, more signals. Range 1.0-10.0.
Statistics parameters:
SL multiplier (default 0.5): ATR-based stop distance for win rate calculation.
TP R:R (default 1.5): risk-reward target for win rate calculation.
Show statistics toggle.
Appearance: bullish and bearish colors.
Timeframe restriction
The indicator is disabled below 1H and displays an on-chart warning. Recommended timeframes: 4H and 1D.
Open-source
Full source code is available. The script uses one external library: KevanoTrades/Ehlers_Super_Smoother for the two-pole smoothing function.
Dept Fractals is a multi-filter reversal detection indicator that identifies high-probability pivot points by requiring three independent conditions to fire simultaneously on the same bar. It is designed for higher timeframes (1H+) across crypto, forex, and futures markets.
The problem it solves
Standard fractal indicators (Williams Fractals, built-in Pivot Points) mark every local high and low, producing dozens of signals per chart with no context filtering. Most of these pivots are noise — minor fluctuations that do not lead to meaningful reversals. Dept Fractals addresses this by requiring three statistically independent confirmations before marking a reversal point.
How the three filters work together
Filter 1 — Adaptive Volatility Envelope (determines IF price is at an extreme)
The script constructs a dynamic envelope around price using the following specific method:
Price data is log-transformed before processing. This makes the envelope symmetrical in percentage terms — a critical difference from standard Bollinger Bands, which produce asymmetric zones on trending instruments because they operate on linear price.
The log-price is smoothed using an Ehlers two-pole super smoother (imported via the KevanoTrades/Ehlers_Super_Smoother library). This smoother has significantly less lag than a simple or exponential moving average of equivalent period, allowing the envelope to track structural price shifts more responsively.
Envelope width is determined by the smoothed true range of the log-price series, multiplied by a user-configurable amplitude parameter. This means the envelope automatically widens during high-volatility regimes and contracts during low-volatility regimes — no manual adjustment needed when switching instruments.
A bearish signal requires the pivot high to reach or exceed the upper envelope. A bullish signal requires the pivot low to touch or breach the lower envelope.
Why this matters: RSI and Stochastic use fixed periods and static overbought/oversold levels (70/30). They generate false signals during strong trends because they stay pegged at extremes. The adaptive envelope avoids this by dynamically scaling with volatility.
Filter 2 — Structural Pivot with ATR Gate (determines WHERE the reversal formed)
The script uses ta.pivothigh() and ta.pivotlow() with a configurable left/right period (default: 3 bars each side = 7-bar confirmation window).
An ATR(14)-based minimum range filter requires the pivot candle to have a range of at least [ATR Gate multiplier] x ATR(14). This removes small, indecisive candles that technically satisfy the pivot definition but carry no real reversal weight.
Filter 3 — Momentum Confirmation + Follow-through (determines WHEN the reversal is confirmed)
A long-period ta.mom() oscillator (default: 50 bars) must already be changing direction at the pivot candle. For bearish fractals, momentum at the pivot must be lower than the previous bar's momentum. For bullish fractals, momentum must be higher.
Additionally, the candle immediately following the pivot (bar at offset pLen-1) must close in the direction of the reversal: bearish close for short signals, bullish close for long signals. This follow-through requirement filters out pivots where price forms an extreme but immediately continues in the original direction.
All three filters must pass simultaneously. If any single filter fails, no signal is generated.
Built-in win rate statistics
The indicator tracks historical performance using ATR-based stop loss and configurable R:R take profit. The counting method is intentionally conservative:
Stop loss = user-defined ATR multiplier beyond the pivot extreme
Take profit = user-defined risk-reward ratio
If a new signal appears before the previous trade resolves, the unresolved trade is counted as a loss
If both TP and SL are hit on the same bar, it is counted as a loss
This ensures the displayed win rate is not inflated by incomplete or ambiguous trades.
Signals
L (green label below bar) — confirmed bullish reversal: price was in the oversold envelope zone, pivot candle was significant relative to ATR, momentum turned up, and the next candle confirmed with a bullish close.
S (red label above bar) — confirmed bearish reversal: price was in the overbought envelope zone, pivot candle was significant, momentum turned down, and the next candle confirmed with a bearish close.
Signals appear with a delay equal to the Pivot Period setting (default: 3 bars) because this time is required for structural confirmation. The indicator does not repaint — once a signal appears, it stays.
Settings
Core parameters:
Pivot Period (default 3): bars left and right for pivot detection. Range 1-15.
ATR Gate (default 0.5): minimum pivot candle range as multiple of ATR(14). Range 0.1-3.0.
Momentum Period (default 50): period for ta.mom() oscillator. Range 10-200.
Adaptive Envelope parameters:
Source (default hlc3): price input for envelope calculation.
Lookback (default 200): period for Ehlers two-pole smoother. Range 50-500.
Amplitude (default 3.5): envelope width multiplier. Lower = wider zones, more signals. Range 1.0-10.0.
Statistics parameters:
SL multiplier (default 0.5): ATR-based stop distance for win rate calculation.
TP R:R (default 1.5): risk-reward target for win rate calculation.
Show statistics toggle.
Appearance: bullish and bearish colors.
Timeframe restriction
The indicator is disabled below 1H and displays an on-chart warning. Recommended timeframes: 4H and 1D.
Open-source
Full source code is available. The script uses one external library: KevanoTrades/Ehlers_Super_Smoother for the two-pole smoothing function.
Catatan Rilis
Dept Fractals detects high-probability reversal points by combining three independent filters: a structural pivot (fractal), an adaptive log-space envelope built on an Ehlers two-pole super smoother, and a momentum reversal gate. All three must align simultaneously for a signal — this multi-condition architecture separates valid pivots from noise on any timeframe from 1 minute to monthly.─── HOW IT WORKS ───
1. Structural pivot (fractal confirmation)
A pivot high or low is identified using ta.pivothigh / ta.pivotlow with a user-defined confirmation window (Pivot Period). A period of 3 means the bar must be the extreme point across a 7-bar window (3 left + pivot + 3 right). This is the classical Williams fractal concept, used here strictly as a structure gate, not a standalone signal.
2. Adaptive log-space envelope
The pivot must occur at or beyond the boundary of a volatility-adaptive envelope computed in logarithmic price space. The envelope uses an Ehlers two-pole super smoother (John Ehlers, Cybernetic Analysis for Stocks and Futures, 2004) — the same engine as in Dept Zones. Band width scales with a smoothed log-space true range, so it self-adjusts to current volatility. Pivots that do not reach the envelope are discarded.
3. ATR range gate
The pivot candle's high-to-low range must exceed a minimum threshold as a multiple of ATR(14). This removes doji-like micro-range pivots that are structurally valid but carry no directional force.
4. Momentum reversal gate
Rate of change (ta.mom) is evaluated at the pivot bar. For a bullish signal, momentum must be increasing. For a bearish signal, it must be decreasing. This confirms that price pressure was already shifting at the pivot.
5. First follow-through candle
The candle immediately after the pivot must close in the direction of the expected reversal — adding a basic price-action confirmation before the label is printed.
Adaptive periods by timeframe
When Auto Lookback and Auto Momentum Period are enabled, both the envelope period and momentum lookback scale automatically:
• 1 min → envelope 500, momentum 500 (cap)
• 15 min → envelope 384, momentum 240
• 1 hour → envelope 96, momentum 50
• 4 hour → envelope 30, momentum 13
• Daily → envelope 200, momentum 50
• Weekly → envelope 29, momentum 7
─── BUILT-IN TRADE STATISTICS ───
A live win rate table is calculated on the chart using forward-test logic: each signal is tracked bar-by-bar until price hits the take profit or stop loss. SL is placed beyond the pivot extreme by a user-defined ATR multiple; TP is set at a fixed risk-reward ratio. Results show total signals, wins, losses, and win rate. This is a transparency tool to evaluate parameter sensitivity in real time — not a backtester.
─── INPUTS ───
Core
Pivot Period — bars left/right to confirm a fractal (default 3)
ATR Gate — minimum pivot range as ATR multiple (default 0.5×)
Momentum Period — rate-of-change lookback, manual (default 50)
Auto Momentum — scales momentum period to timeframe (default: on)
Adaptive Envelope
Source — price input (default HLC3)
Lookback — envelope smoother period, manual (default 200)
Auto Lookback — scales lookback to timeframe (default: on)
Amplitude — envelope width multiplier (default 3.5)
Statistics
Show Win Rate — toggle the stats table
SL × ATR — stop distance for stats (default 0.5)
TP R:R — take profit risk multiple for stats (default 1.5)
─── ALERTS ───
Three alert conditions:
• Bearish Fractal
• Bullish Fractal
• Any Fractal
All carry {{ticker}}, {{interval}}, and {{close}} tokens.
Catatan Rilis
Dept Fractals detects high-probability reversal points by combining five independent filters that must all align simultaneously: a structural pivot, an adaptive log-space envelope, an ATR range gate, a momentum reversal gate, and a follow-through candle. Works on all timeframes from 1 minute to monthly.─── HOW IT WORKS ───
1. Structural pivot
A pivot high or low is confirmed using ta.pivothigh / ta.pivotlow with a user-defined window (Pivot Period). Period 3 means the bar must be the extreme across a 7-bar window. This is the classical Williams fractal concept, used here strictly as a structure gate — not a standalone signal.
2. Adaptive log-space envelope
The pivot must reach or exceed the envelope boundary. The envelope is computed in logarithmic price space using an Ehlers two-pole super smoother (John Ehlers, Cybernetic Analysis for Stocks and Futures, 2004). Band width scales with a smoothed log-space true range, self-adjusting to current volatility. The filter uses two fully independent state variable pairs — one for the price series, one for the true range — ensuring correct computation when both series are smoothed simultaneously.
3. ATR range gate
The pivot candle's range must exceed a minimum threshold as a multiple of ATR(14), filtering out doji-like micro pivots that carry no directional force.
4. Momentum reversal gate
Rate of change (ta.mom) is evaluated at the pivot bar. For a bullish signal, momentum must be increasing; for a bearish signal, decreasing. This confirms that directional pressure was already shifting at the pivot.
5. Follow-through candle
The candle immediately after the pivot must close in the direction of the expected reversal before the label is printed.
Adaptive periods by timeframe
When Auto Lookback and Auto Momentum Period are enabled, both periods scale automatically:
• 1 min → envelope 500, momentum 500 (cap)
• 15 min → envelope 384, momentum 240
• 1 hour → envelope 96, momentum 50
• 4 hour → envelope 30, momentum 13
• Daily → envelope 200, momentum 50
• Weekly → envelope 29, momentum 7
─── BUILT-IN TRADE STATISTICS ───
A live win rate table tracks each signal bar-by-bar until price hits the take profit or stop loss. SL is placed beyond the pivot extreme by a user-defined ATR multiple; TP is a fixed risk-reward ratio from entry. Results show total signals, wins, losses, and win rate. This is a transparency tool to evaluate parameter sensitivity in real time — not a backtester.
─── INPUTS ───
Core
Pivot Period — bars left/right to confirm a fractal (default 3)
ATR Gate — minimum pivot range as ATR multiple (default 0.5×)
Momentum Period — rate-of-change lookback, manual (default 50)
Auto Momentum — scales momentum period to timeframe (default: on)
Adaptive Envelope
Source — price input (default HLC3)
Lookback — envelope smoother period, manual (default 200)
Auto Lookback — scales lookback to timeframe (default: on)
Amplitude — envelope width multiplier (default 3.5)
Statistics
Show Win Rate — toggle the stats table
SL × ATR — stop distance for stats (default 0.5)
TP R:R — take profit risk multiple for stats (default 1.5)
─── ALERTS ───
Three alert conditions:
• Bearish Fractal
• Bullish Fractal
• Any Fractal
All carry {{ticker}}, {{interval}}, and {{close}} tokens.
Catatan Rilis
Dept Fractals detects high-probability reversal points by combining five independent filters that must all align simultaneously: a structural pivot, an adaptive log-space envelope, an ATR range gate, a momentum reversal gate, and a follow-through candle. Works on all timeframes from 1 minute to monthly.─── HOW IT WORKS ───
1. Structural pivot
A pivot high or low is confirmed using ta.pivothigh / ta.pivotlow with a user-defined window (Pivot Period). Period 3 means the bar must be the extreme across a 7-bar window. This is the classical Williams fractal concept, used here strictly as a structure gate — not a standalone signal.
2. Adaptive log-space envelope
The pivot must reach or exceed the envelope boundary. The envelope is computed in logarithmic price space using an Ehlers two-pole super smoother (John Ehlers, Cybernetic Analysis for Stocks and Futures, 2004). Band width scales with a smoothed log-space true range, self-adjusting to current volatility. The filter uses two fully independent state variable pairs — one for the price series, one for the true range — ensuring correct computation when both series are smoothed simultaneously.
3. ATR range gate
The pivot candle's range must exceed a minimum threshold as a multiple of ATR(14), filtering out doji-like micro pivots that carry no directional force.
4. Momentum reversal gate
Rate of change (ta.mom) is evaluated at the pivot bar. For a bullish signal, momentum must be increasing; for a bearish signal, decreasing. This confirms that directional pressure was already shifting at the pivot.
5. Follow-through candle
The candle immediately after the pivot must close in the direction of the expected reversal before the label is printed.
Adaptive periods by timeframe
When Auto Lookback and Auto Momentum Period are enabled, both periods scale automatically:
• 1 min → envelope 500, momentum 500 (cap)
• 15 min → envelope 384, momentum 240
• 1 hour → envelope 96, momentum 50
• 4 hour → envelope 30, momentum 13
• Daily → envelope 200, momentum 50
• Weekly → envelope 29, momentum 7
─── BUILT-IN TRADE STATISTICS ───
A live win rate table tracks each signal bar-by-bar until price hits the take profit or stop loss. SL is placed beyond the pivot extreme by a user-defined ATR multiple; TP is a fixed risk-reward ratio from entry. Results show total signals, wins, losses, and win rate. This is a transparency tool to evaluate parameter sensitivity in real time — not a backtester.
─── INPUTS ───
Core
Pivot Period — bars left/right to confirm a fractal (default 3)
ATR Gate — minimum pivot range as ATR multiple (default 0.5×)
Momentum Period — rate-of-change lookback, manual (default 50)
Auto Momentum — scales momentum period to timeframe (default: on)
Adaptive Envelope
Source — price input (default HLC3)
Lookback — envelope smoother period, manual (default 200)
Auto Lookback — scales lookback to timeframe (default: on)
Amplitude — envelope width multiplier (default 3.5)
Statistics
Show Win Rate — toggle the stats table
SL × ATR — stop distance for stats (default 0.5)
TP R:R — take profit risk multiple for stats (default 1.5)
─── ALERTS ───
Three alert conditions:
• Bearish Fractal
• Bullish Fractal
• Any Fractal
All carry {{ticker}}, {{interval}}, and {{close}} tokens.
Catatan Rilis
Dept Fractals detects high-probability reversal points by combining five independent filters that must all align simultaneously: a structural pivot, an adaptive log-space envelope, an ATR range gate, a momentum reversal gate, and a follow-through candle. Designed for 1H timeframe and above.─── HOW IT WORKS ───
1. Structural pivot
A pivot high or low is confirmed using ta.pivothigh / ta.pivotlow with a user-defined window (Pivot Period). Period 3 means the bar must be the extreme across a 7-bar window (3 left + pivot + 3 right). This is the classical Williams fractal concept, used here strictly as a structure gate — not a standalone signal.
2. Adaptive log-space envelope
The pivot must reach or exceed the envelope boundary. The envelope is computed in logarithmic price space using an Ehlers two-pole super smoother (John Ehlers, Cybernetic Analysis for Stocks and Futures, 2004). Band width scales with a smoothed log-space true range, self-adjusting to current volatility. Pivots that do not reach the envelope boundary are discarded regardless of structural validity.
3. ATR range gate
The pivot candle's range must exceed a minimum threshold as a multiple of ATR(14), filtering out doji-like micro pivots that carry no directional force.
4. Momentum reversal gate
Rate of change (ta.mom) is evaluated at the pivot bar. For a bullish signal, momentum must be increasing; for a bearish signal, decreasing. This confirms that directional pressure was already shifting at the pivot.
5. Follow-through candle
The candle immediately after the pivot must close in the direction of the expected reversal before the label is printed.
─── BUILT-IN TRADE STATISTICS ───
A live win rate table tracks each signal bar-by-bar until price hits the take profit or stop loss. SL is placed beyond the pivot extreme by a user-defined ATR multiple; TP is a fixed risk-reward ratio from entry. Results show total signals, wins, losses, and win rate. This is a transparency tool to evaluate parameter sensitivity in real time — not a backtester.
─── INPUTS ───
Core
Pivot Period — bars left/right to confirm a fractal (default 3)
ATR Gate — minimum pivot range as ATR multiple (default 0.5×)
Momentum Period — rate-of-change lookback (default 50)
Adaptive Envelope
Source — price input (default HLC3)
Lookback — envelope smoother period (default 200)
Amplitude — envelope width multiplier (default 3.5)
Statistics
Show Win Rate — toggle the stats table
SL × ATR — stop distance for stats (default 0.5)
TP R:R — take profit risk multiple for stats (default 1.5)
─── TIMEFRAME ───
Designed for 1H and higher. On lower timeframes signal quality degrades due to noise in momentum and envelope calculations. A warning banner is shown automatically below 1H.
─── ALERTS ───
Three alert conditions:
• Bearish Fractal
• Bullish Fractal
• Any Fractal
All carry {{ticker}}, {{interval}}, and {{close}} tokens.
Skrip open-source
Dengan semangat TradingView yang sesungguhnya, pembuat skrip ini telah menjadikannya sebagai sumber terbuka, sehingga para trader dapat meninjau dan memverifikasi fungsinya. Salut untuk penulisnya! Meskipun Anda dapat menggunakannya secara gratis, perlu diingat bahwa penerbitan ulang kode ini tunduk pada Tata Tertib kami.
Pernyataan Penyangkalan
Informasi dan publikasi ini tidak dimaksudkan, dan bukan merupakan, saran atau rekomendasi keuangan, investasi, trading, atau jenis lainnya yang diberikan atau didukung oleh TradingView. Baca selengkapnya di Ketentuan Penggunaan.
Skrip open-source
Dengan semangat TradingView yang sesungguhnya, pembuat skrip ini telah menjadikannya sebagai sumber terbuka, sehingga para trader dapat meninjau dan memverifikasi fungsinya. Salut untuk penulisnya! Meskipun Anda dapat menggunakannya secara gratis, perlu diingat bahwa penerbitan ulang kode ini tunduk pada Tata Tertib kami.
Pernyataan Penyangkalan
Informasi dan publikasi ini tidak dimaksudkan, dan bukan merupakan, saran atau rekomendasi keuangan, investasi, trading, atau jenis lainnya yang diberikan atau didukung oleh TradingView. Baca selengkapnya di Ketentuan Penggunaan.