OPEN-SOURCE SCRIPT
Swing Failure Pattern [ SFP ] - FloAlgo

This indicator detects Swing Failure Patterns (SFP) — a Smart Money Concepts technique that identifies liquidity sweeps followed by a Change in State of Delivery (CISD), signaling potential price reversals.
How It Works
The script operates in three stages:
Exit System — 5-Layer Logic
Rather than relying on a fixed take profit, this script uses a dynamic multi-layer exit system designed to protect capital and lock in gains:
Visual Elements
Key Settings
ParameterDescriptionPivot Detection LengthSensitivity of pivot high/low detectionMax Pivot EdgeMaximum bar distance for a valid sweepPatienceMax bars between sweep and CISD for signal confirmationTrend Noise FilterTolerance ratio to filter weak CISD movesTrailing Stop MultiplierATR multiplier controlling trailing stop tightnessMin Bars Before TrailingGrace period before trailing stop activates.
How It Works
The script operates in three stages:
- Liquidity Sweep Detection — Identifies when price briefly breaks above a pivot high or below a pivot low, sweeping resting liquidity beyond those levels.
- CISD Confirmation — Validates the sweep by detecting a Change in State of Delivery: a candle close that reverses back through a key open level, confirming institutional rejection.
- Signal Trigger — A bullish or bearish SFP signal is confirmed only when both the sweep and CISD occur within the defined patience window, reducing false positives significantly.
Exit System — 5-Layer Logic
Rather than relying on a fixed take profit, this script uses a dynamic multi-layer exit system designed to protect capital and lock in gains:
- Initial Stop Loss — Set at the high/low of the signal candle for immediate invalidation
- Trailing Stop — Tracks extreme price movement and trails by ATR × multiplier, activating after a minimum number of bars to avoid premature exits
- Reversal Candle — Exits on an opposing engulfing candle once the trade is in motion
- Timeout — Hard exit after a maximum number of bars
- Trend Flip — Exits if CISD confirms a full trend reversal against the position
Visual Elements
- Dashed lines marking swept pivot levels
- Solid CISD level lines from origin to signal bar
- Dotted stop loss projection lines
- Dynamic trailing stop plotted as a step line
- Bar coloring active while a signal is live
- ▲ / ▼ signal labels on the chart
Key Settings
ParameterDescriptionPivot Detection LengthSensitivity of pivot high/low detectionMax Pivot EdgeMaximum bar distance for a valid sweepPatienceMax bars between sweep and CISD for signal confirmationTrend Noise FilterTolerance ratio to filter weak CISD movesTrailing Stop MultiplierATR multiplier controlling trailing stop tightnessMin Bars Before TrailingGrace period before trailing stop activates.
Mã nguồn mở
Theo đúng tinh thần TradingView, tác giả của tập lệnh này đã công bố nó dưới dạng mã nguồn mở, để các nhà giao dịch có thể xem xét và xác minh chức năng. Chúc mừng tác giả! Mặc dù bạn có thể sử dụng miễn phí, hãy nhớ rằng việc công bố lại mã phải tuân theo Nội quy.
Thông báo miễn trừ trách nhiệm
Thông tin và các ấn phẩm này không nhằm mục đích, và không cấu thành, lời khuyên hoặc khuyến nghị về tài chính, đầu tư, giao dịch hay các loại khác do TradingView cung cấp hoặc xác nhận. Đọc thêm tại Điều khoản Sử dụng.
Mã nguồn mở
Theo đúng tinh thần TradingView, tác giả của tập lệnh này đã công bố nó dưới dạng mã nguồn mở, để các nhà giao dịch có thể xem xét và xác minh chức năng. Chúc mừng tác giả! Mặc dù bạn có thể sử dụng miễn phí, hãy nhớ rằng việc công bố lại mã phải tuân theo Nội quy.
Thông báo miễn trừ trách nhiệm
Thông tin và các ấn phẩm này không nhằm mục đích, và không cấu thành, lời khuyên hoặc khuyến nghị về tài chính, đầu tư, giao dịch hay các loại khác do TradingView cung cấp hoặc xác nhận. Đọc thêm tại Điều khoản Sử dụng.