OPEN-SOURCE SCRIPT
Multi-Timeframe SFP (Swing Failure Pattern)

How to Use
1. Set Pivot Timeframe: Choose the timeframe for identifying major swing points (e.g., 'D' for Daily pivots).
2. Set SFP Timeframe: Choose the timeframe to find the SFP candle (e.g., '240' for the 4-Hour chart).
3. Set Confirmation Bars: Set how many SFP Timeframe bars must pass without invalidating the level. A value of '0' confirms immediately on the SFP bar's close. A value of '1' waits for one more bar to close.
4. Adjust Filters (Optional): Enable the 'Wick % Filter' to add a quality check for strong rejections.
5. Watch & Wait: The indicator will draw lines and labels and fire alerts for fully confirmed signals.
In-Depth Explanation
1. Overview
The Dynamic Pivot SFP Engine is a multi-timeframe tool designed to identify and validate Swing Failure Patterns (SFPs) at significant price levels.
An SFP is a common price action pattern where price briefly trades beyond a previous swing high or low (sweeping liquidity) but then fails to hold those new prices, closing back inside the previous range. This "failure" often signals a reversal.
This indicator enhances SFP detection by separating the Pivot (Liquidity) from the SFP (Rejection), allowing you to monitor them on different timeframes.
2. The Core Multi-Timeframe Logic
The indicator's power comes from two key inputs:
• Pivot Timeframe (Pivot Timeframe)
This is the "high timeframe" used to establish significant support and resistance levels. The script finds standard pivots (swing highs and lows) on this timeframe based on the Pivot Left Strength and Pivot Right Strength inputs. These pivots are the "liquidity" levels the SFP will target. The Pivot Lookback input controls how long (in Pivot Timeframe bars) a pivot remains active and monitored.
• SFP Timeframe (SFP Timeframe)
This is the "execution timeframe" where the script looks for the actual SFP. On every new bar of this timeframe, the script checks if price has swept and rejected any of the active pivots.
Example Setup:
You might set Pivot Timeframe to 'D' (Daily) to find major daily swing points. You then set SFP Timeframe to '240' (4-Hour) to find a 4-hour candle that sweeps a daily pivot and closes back below/above it.
3. The SFP Confirmation Process
An SFP is not confirmed instantly. It must pass a rigorous, multi-step validation process.
Step 1: The SFP Candle (The Sweep)
A potential SFP is identified when an SFP Timeframe bar does the following:
• Bearish SFP: The bar's high trades above an active pivot high, but the bar closes below that same pivot high.
• Bullish SFP: The bar's low trades below an active pivot low, but the bar closes above that same pivot low.
Step 2: The Wick Filter (Optional Quality Check)
If Enable Wick % Filter is checked, the SFP candle from Step 1 is also measured.
• For a bearish SFP, the upper wick (from the high to the open/close) must be at least Min. Wick % of the entire candle's range (high-to-low).
• For a bullish SFP, the lower wick (from the low to the open/close) must meet the same percentage requirement.
If the SFP candle fails this test, it is discarded, even if it met the sweep/close criteria.
Step 3: The Validation Window (The Confirmation)
This is the most critical feature, controlled by Confirmation Bars.
• If Confirmation Bars = 0: The SFP is confirmed immediately on the SFP candle's close (assuming it passed the optional wick check). The label, line, and alert are triggered at this moment.
• If Confirmation Bars > 0: The SFP enters a "pending" state. The script will wait for $N$ more SFP Timeframe bars to close.
o Invalidation: If, during this waiting period, any bar closes back across the pivot (e.g., a close above the pivot for a bearish SFP), the SFP is considered failed and invalidated. All pending plots are deleted.
o Confirmation: If the $N$ confirmation bars all complete without invalidating the level, the SFP is finally confirmed. The label, line, and alert are only triggered after this entire process is complete. This adds a significant layer of robustness, ensuring the rejection holds for a period of time.
4. Visuals & Alerts
• Lines: A horizontal line is drawn from the original pivot to the SFP bar, showing which level was targeted. Note: These lines will only be drawn on chart timeframes equal to or lower than the 'SFP Timeframe'.
• Labels: A label is placed at the SFP's extreme (the high/low of the SFP bar). The label text conveniently includes the Ticker, Pivot TF, SFP TF, and Confirmation bar settings (e.g., "Bearish SFP BTCUSD / Pivot: 1D / SFP: 4H | Conf: 1").
• MTF Boxes (Show SFP Box, Show Conf. Boxes): These boxes highlight the SFP and confirmation bars. Crucially, they are only visible when your chart timeframe is lower than the SFP Timeframe. For example, if your SFP Timeframe is '240' (4H), you will only see these boxes on the 1H, 15M, 5M, etc., charts. This allows you to see the higher-timeframe SFP unfolding on your lower-timeframe chart.
• Alerts (Enable Alerts): An alert is fired only when an SFP is fully confirmed (i.e., after the Confirmation Bars have passed successfully). For efficient, real-time monitoring, it is highly recommended to run this indicator server-side by creating an alert on TradingView set to trigger on "Any alert() function call".
1. Set Pivot Timeframe: Choose the timeframe for identifying major swing points (e.g., 'D' for Daily pivots).
2. Set SFP Timeframe: Choose the timeframe to find the SFP candle (e.g., '240' for the 4-Hour chart).
3. Set Confirmation Bars: Set how many SFP Timeframe bars must pass without invalidating the level. A value of '0' confirms immediately on the SFP bar's close. A value of '1' waits for one more bar to close.
4. Adjust Filters (Optional): Enable the 'Wick % Filter' to add a quality check for strong rejections.
5. Watch & Wait: The indicator will draw lines and labels and fire alerts for fully confirmed signals.
In-Depth Explanation
1. Overview
The Dynamic Pivot SFP Engine is a multi-timeframe tool designed to identify and validate Swing Failure Patterns (SFPs) at significant price levels.
An SFP is a common price action pattern where price briefly trades beyond a previous swing high or low (sweeping liquidity) but then fails to hold those new prices, closing back inside the previous range. This "failure" often signals a reversal.
This indicator enhances SFP detection by separating the Pivot (Liquidity) from the SFP (Rejection), allowing you to monitor them on different timeframes.
2. The Core Multi-Timeframe Logic
The indicator's power comes from two key inputs:
• Pivot Timeframe (Pivot Timeframe)
This is the "high timeframe" used to establish significant support and resistance levels. The script finds standard pivots (swing highs and lows) on this timeframe based on the Pivot Left Strength and Pivot Right Strength inputs. These pivots are the "liquidity" levels the SFP will target. The Pivot Lookback input controls how long (in Pivot Timeframe bars) a pivot remains active and monitored.
• SFP Timeframe (SFP Timeframe)
This is the "execution timeframe" where the script looks for the actual SFP. On every new bar of this timeframe, the script checks if price has swept and rejected any of the active pivots.
Example Setup:
You might set Pivot Timeframe to 'D' (Daily) to find major daily swing points. You then set SFP Timeframe to '240' (4-Hour) to find a 4-hour candle that sweeps a daily pivot and closes back below/above it.
3. The SFP Confirmation Process
An SFP is not confirmed instantly. It must pass a rigorous, multi-step validation process.
Step 1: The SFP Candle (The Sweep)
A potential SFP is identified when an SFP Timeframe bar does the following:
• Bearish SFP: The bar's high trades above an active pivot high, but the bar closes below that same pivot high.
• Bullish SFP: The bar's low trades below an active pivot low, but the bar closes above that same pivot low.
Step 2: The Wick Filter (Optional Quality Check)
If Enable Wick % Filter is checked, the SFP candle from Step 1 is also measured.
• For a bearish SFP, the upper wick (from the high to the open/close) must be at least Min. Wick % of the entire candle's range (high-to-low).
• For a bullish SFP, the lower wick (from the low to the open/close) must meet the same percentage requirement.
If the SFP candle fails this test, it is discarded, even if it met the sweep/close criteria.
Step 3: The Validation Window (The Confirmation)
This is the most critical feature, controlled by Confirmation Bars.
• If Confirmation Bars = 0: The SFP is confirmed immediately on the SFP candle's close (assuming it passed the optional wick check). The label, line, and alert are triggered at this moment.
• If Confirmation Bars > 0: The SFP enters a "pending" state. The script will wait for $N$ more SFP Timeframe bars to close.
o Invalidation: If, during this waiting period, any bar closes back across the pivot (e.g., a close above the pivot for a bearish SFP), the SFP is considered failed and invalidated. All pending plots are deleted.
o Confirmation: If the $N$ confirmation bars all complete without invalidating the level, the SFP is finally confirmed. The label, line, and alert are only triggered after this entire process is complete. This adds a significant layer of robustness, ensuring the rejection holds for a period of time.
4. Visuals & Alerts
• Lines: A horizontal line is drawn from the original pivot to the SFP bar, showing which level was targeted. Note: These lines will only be drawn on chart timeframes equal to or lower than the 'SFP Timeframe'.
• Labels: A label is placed at the SFP's extreme (the high/low of the SFP bar). The label text conveniently includes the Ticker, Pivot TF, SFP TF, and Confirmation bar settings (e.g., "Bearish SFP BTCUSD / Pivot: 1D / SFP: 4H | Conf: 1").
• MTF Boxes (Show SFP Box, Show Conf. Boxes): These boxes highlight the SFP and confirmation bars. Crucially, they are only visible when your chart timeframe is lower than the SFP Timeframe. For example, if your SFP Timeframe is '240' (4H), you will only see these boxes on the 1H, 15M, 5M, etc., charts. This allows you to see the higher-timeframe SFP unfolding on your lower-timeframe chart.
• Alerts (Enable Alerts): An alert is fired only when an SFP is fully confirmed (i.e., after the Confirmation Bars have passed successfully). For efficient, real-time monitoring, it is highly recommended to run this indicator server-side by creating an alert on TradingView set to trigger on "Any alert() function call".
开源脚本
本着TradingView的真正精神,此脚本的创建者将其开源,以便交易者可以查看和验证其功能。向作者致敬!虽然您可以免费使用它,但请记住,重新发布代码必须遵守我们的网站规则。
免责声明
这些信息和出版物并不意味着也不构成TradingView提供或认可的金融、投资、交易或其它类型的建议或背书。请在使用条款阅读更多信息。
开源脚本
本着TradingView的真正精神,此脚本的创建者将其开源,以便交易者可以查看和验证其功能。向作者致敬!虽然您可以免费使用它,但请记住,重新发布代码必须遵守我们的网站规则。
免责声明
这些信息和出版物并不意味着也不构成TradingView提供或认可的金融、投资、交易或其它类型的建议或背书。请在使用条款阅读更多信息。