OPEN-SOURCE SCRIPT
Confluence Trend and Fibo Reversal System

An In-Depth Overview of the "Confluence Trend and Fibo Reversal System"
Introduction: The Purpose and Core Architecture
The "Confluence Trend and Fibo Reversal System" is a sophisticated, highly adaptable Pine Script trading indicator designed to dynamically navigate fluctuating market conditions. The primary objective of this script is to solve a fundamental problem in technical analysis: the tendency of trend-following indicators to produce false signals during sideways markets, and the failure of mean-reversion oscillators during strong trends. To achieve this, the indicator operates as a dual-regime trading algorithm. It constantly analyzes price action to determine whether the current market environment is trending or ranging (sideways). Based on this real-time assessment, the script autonomously switches its internal logic, deploying either a momentum-based confluence engine for trends or a reversal-based engine strictly filtered by Fibonacci retracement levels for sideways markets.
Operating Mechanisms: How the Indicator Generates Signals
The technical architecture of this indicator is divided into four distinct analytical engines that work together to validate trading signals.
1. The Market Regime Filter (Range Detection)
Before any signal is generated, the system calculates a "Range Score" to determine the market state. It evaluates six specific technical conditions:
ADX (Average Directional Index): Checks if the ADX value is below 25, indicating weak trend strength.
Bollinger Bands Position: Verifies if the closing price is contained securely within the upper and lower bands.
Bollinger Bandwidth (BBW): Measures volatility by checking if the current bandwidth is narrower than its 20-period moving average.
RSI (Relative Strength Index): Checks if the RSI is hovering in a neutral zone between 40 and 60.
Stochastic Oscillator: Confirms that the Stochastic K-line is resting in a non-extreme zone between 20 and 80.
EMA Convergence:Measures the gap between the 20-period and 50-period Exponential Moving Averages, checking if they are tightly converged within half of the Average True Range (ATR).
If the total score meets a user-defined threshold (defaulting to 4 out of 6), the system classifies the market as "Ranging" and activates the Reversal engine; otherwise, it defaults to the Trend engine.
2. The Trend Engine (Confluence Scoring)
When the market is clearly trending, the script relies on a strict multi-indicator confluence system to prevent premature entries. It generates a bullish or bearish score out of five possible points:
Price positioning relative to the 50-period EMA.
Directional dominance using the ADX (+DI vs -DI).
Momentum confirmation via MACD baseline crossovers.
Trend alignment with the Supertrend indicator.
Price placement above or below the Ichimoku Kumo Cloud.
A final buy or sell signal in trend mode is only triggered if the accumulated score meets the "Minimum Confluence Score" threshold (defaulting to 4 out of 5).
3. The Reversal & Fibonacci Engine
If the market is ranging, the script hunts for mean-reversion opportunities by scanning for specific price action anomalies and oscillator extremes. It looks for Bullish/Bearish Engulfing candles, Pinbars (Hammers and Shooting Stars), RSI overbought/oversold crossovers, Stochastic extreme crossovers, and Bollinger Band boundary breakouts.
Crucially, these reversal patterns are deemed invalid unless they occur in close proximity to an automatically generated Fibonacci level. The script identifies the highest high and lowest low over a 100-bar lookback period to draw dynamic Fibonacci retracement lines (0.000 to 1.000). A reversal signal is only approved if the price action happens within a tight percentage tolerance zone around these key Fibonacci levels.
4. The Retest Engine
To drastically reduce false breakouts, the script features a built-in "Retest Mode". Instead of firing a buy or sell signal immediately when conditions are met, the script calculates a target "retest price" offset by an ATR multiplier. It will then hold the pending signal in memory for a maximum number of candles (defaulting to 4). The final execution signal is only printed on the chart if the price pulls back to successfully retest this calculated ATR level, proving the validity of the breakout.
Implementation and Usage Guidelines
Recommended Settings
Trade Direction: It is highly recommended to leave the trade direction set to "Both" to allow the dynamic regime filter to operate at its full potential. However, if trading against a higher timeframe macroeconomic trend, users can restrict the system to "Buy Only" or "Sell Only".
Retest Mode: Keep "Enable Retest Mode" activated. While it may cause you to miss trades that instantly aggressively rally, it will save you from substantial losses caused by "fake-out" signals.
Confluence Threshold: For aggressive traders, lowering the Trend Minimum Confluence Score to 3 will yield more signals. For conservative traders, leaving it at 4 or 5 ensures that only the highest probability momentum shifts are traded.
Visual Enhancements: Keep the "Highlight Range Market Background" enabled. This feature turns the chart background orange during sideways markets, providing excellent visual context as to why the indicator is currently ignoring standard trend breakouts.
Suitable Markets and Timeframes**
Because the "Confluence Trend and Fibo Reversal System" actively adapts to volatility and structural shifts rather than relying on static logic, it is exceptionally versatile. It is well-suited for high-liquidity markets such as major Forex pairs (EUR/USD, GBP/USD), large-cap Cryptocurrencies (Bitcoin, Ethereum), and major Equity indices. Due to its reliance on 100-period lookbacks for Fibonacci mapping and 50-period EMAs for trend detection, the indicator performs optimally on medium to higher timeframes—specifically the 1-Hour (H1), 4-Hour (H4), and Daily (D1) charts—where market noise is minimal, and true institutional support and resistance zones are respected.
Introduction: The Purpose and Core Architecture
The "Confluence Trend and Fibo Reversal System" is a sophisticated, highly adaptable Pine Script trading indicator designed to dynamically navigate fluctuating market conditions. The primary objective of this script is to solve a fundamental problem in technical analysis: the tendency of trend-following indicators to produce false signals during sideways markets, and the failure of mean-reversion oscillators during strong trends. To achieve this, the indicator operates as a dual-regime trading algorithm. It constantly analyzes price action to determine whether the current market environment is trending or ranging (sideways). Based on this real-time assessment, the script autonomously switches its internal logic, deploying either a momentum-based confluence engine for trends or a reversal-based engine strictly filtered by Fibonacci retracement levels for sideways markets.
Operating Mechanisms: How the Indicator Generates Signals
The technical architecture of this indicator is divided into four distinct analytical engines that work together to validate trading signals.
1. The Market Regime Filter (Range Detection)
Before any signal is generated, the system calculates a "Range Score" to determine the market state. It evaluates six specific technical conditions:
ADX (Average Directional Index): Checks if the ADX value is below 25, indicating weak trend strength.
Bollinger Bands Position: Verifies if the closing price is contained securely within the upper and lower bands.
Bollinger Bandwidth (BBW): Measures volatility by checking if the current bandwidth is narrower than its 20-period moving average.
RSI (Relative Strength Index): Checks if the RSI is hovering in a neutral zone between 40 and 60.
Stochastic Oscillator: Confirms that the Stochastic K-line is resting in a non-extreme zone between 20 and 80.
EMA Convergence:Measures the gap between the 20-period and 50-period Exponential Moving Averages, checking if they are tightly converged within half of the Average True Range (ATR).
If the total score meets a user-defined threshold (defaulting to 4 out of 6), the system classifies the market as "Ranging" and activates the Reversal engine; otherwise, it defaults to the Trend engine.
2. The Trend Engine (Confluence Scoring)
When the market is clearly trending, the script relies on a strict multi-indicator confluence system to prevent premature entries. It generates a bullish or bearish score out of five possible points:
Price positioning relative to the 50-period EMA.
Directional dominance using the ADX (+DI vs -DI).
Momentum confirmation via MACD baseline crossovers.
Trend alignment with the Supertrend indicator.
Price placement above or below the Ichimoku Kumo Cloud.
A final buy or sell signal in trend mode is only triggered if the accumulated score meets the "Minimum Confluence Score" threshold (defaulting to 4 out of 5).
3. The Reversal & Fibonacci Engine
If the market is ranging, the script hunts for mean-reversion opportunities by scanning for specific price action anomalies and oscillator extremes. It looks for Bullish/Bearish Engulfing candles, Pinbars (Hammers and Shooting Stars), RSI overbought/oversold crossovers, Stochastic extreme crossovers, and Bollinger Band boundary breakouts.
Crucially, these reversal patterns are deemed invalid unless they occur in close proximity to an automatically generated Fibonacci level. The script identifies the highest high and lowest low over a 100-bar lookback period to draw dynamic Fibonacci retracement lines (0.000 to 1.000). A reversal signal is only approved if the price action happens within a tight percentage tolerance zone around these key Fibonacci levels.
4. The Retest Engine
To drastically reduce false breakouts, the script features a built-in "Retest Mode". Instead of firing a buy or sell signal immediately when conditions are met, the script calculates a target "retest price" offset by an ATR multiplier. It will then hold the pending signal in memory for a maximum number of candles (defaulting to 4). The final execution signal is only printed on the chart if the price pulls back to successfully retest this calculated ATR level, proving the validity of the breakout.
Implementation and Usage Guidelines
Recommended Settings
Trade Direction: It is highly recommended to leave the trade direction set to "Both" to allow the dynamic regime filter to operate at its full potential. However, if trading against a higher timeframe macroeconomic trend, users can restrict the system to "Buy Only" or "Sell Only".
Retest Mode: Keep "Enable Retest Mode" activated. While it may cause you to miss trades that instantly aggressively rally, it will save you from substantial losses caused by "fake-out" signals.
Confluence Threshold: For aggressive traders, lowering the Trend Minimum Confluence Score to 3 will yield more signals. For conservative traders, leaving it at 4 or 5 ensures that only the highest probability momentum shifts are traded.
Visual Enhancements: Keep the "Highlight Range Market Background" enabled. This feature turns the chart background orange during sideways markets, providing excellent visual context as to why the indicator is currently ignoring standard trend breakouts.
Suitable Markets and Timeframes**
Because the "Confluence Trend and Fibo Reversal System" actively adapts to volatility and structural shifts rather than relying on static logic, it is exceptionally versatile. It is well-suited for high-liquidity markets such as major Forex pairs (EUR/USD, GBP/USD), large-cap Cryptocurrencies (Bitcoin, Ethereum), and major Equity indices. Due to its reliance on 100-period lookbacks for Fibonacci mapping and 50-period EMAs for trend detection, the indicator performs optimally on medium to higher timeframes—specifically the 1-Hour (H1), 4-Hour (H4), and Daily (D1) charts—where market noise is minimal, and true institutional support and resistance zones are respected.
オープンソーススクリプト
TradingViewの精神に則り、このスクリプトの作者はコードをオープンソースとして公開してくれました。トレーダーが内容を確認・検証できるようにという配慮です。作者に拍手を送りましょう!無料で利用できますが、コードの再公開はハウスルールに従う必要があります。
免責事項
これらの情報および投稿は、TradingViewが提供または承認する金融、投資、取引、またはその他の種類の助言もしくは推奨であることを意図したものではなく、またこれらに該当するものでもありません。詳細は利用規約をご覧ください。
オープンソーススクリプト
TradingViewの精神に則り、このスクリプトの作者はコードをオープンソースとして公開してくれました。トレーダーが内容を確認・検証できるようにという配慮です。作者に拍手を送りましょう!無料で利用できますが、コードの再公開はハウスルールに従う必要があります。
免責事項
これらの情報および投稿は、TradingViewが提供または承認する金融、投資、取引、またはその他の種類の助言もしくは推奨であることを意図したものではなく、またこれらに該当するものでもありません。詳細は利用規約をご覧ください。