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.
Script open-source
Nello spirito di TradingView, l'autore di questo script lo ha reso open source, in modo che i trader possano esaminarne e verificarne la funzionalità. Complimenti all'autore! Sebbene sia possibile utilizzarlo gratuitamente, ricordiamo che la ripubblicazione del codice è soggetta al nostro Regolamento.
Declinazione di responsabilità
Le informazioni e le pubblicazioni non sono intese come, e non costituiscono, consulenza o raccomandazioni finanziarie, di investimento, di trading o di altro tipo fornite o approvate da TradingView. Per ulteriori informazioni, consultare i Termini di utilizzo.
Script open-source
Nello spirito di TradingView, l'autore di questo script lo ha reso open source, in modo che i trader possano esaminarne e verificarne la funzionalità. Complimenti all'autore! Sebbene sia possibile utilizzarlo gratuitamente, ricordiamo che la ripubblicazione del codice è soggetta al nostro Regolamento.
Declinazione di responsabilità
Le informazioni e le pubblicazioni non sono intese come, e non costituiscono, consulenza o raccomandazioni finanziarie, di investimento, di trading o di altro tipo fornite o approvate da TradingView. Per ulteriori informazioni, consultare i Termini di utilizzo.