Pattern Reference
A complete walkthrough of every detection rule — rendered as real candles,
annotated exactly as sdt_logic.py implements them. Every demo
uses hand-crafted OHLCV that satisfies the rule precisely.
Overview — the full SDT flow
A complete SDT setup is a six-stage sequence. Price forms an SFP low, rallies to print two SFP highs (TARGET above MID), collapses into a 3R bottom, bounces above MID, completes a 3G breakout, and fires an entry with TP at TARGET and SL just below the 3R low.
SFP — Swing Failure Pattern
An SFP fires when price sweeps past a confirmed pivot then closes back on the original side. The extreme (the actual highest wick for an SFP HIGH, lowest wick for an SFP LOW) is what the setup measures against — not the pivot itself.
3R — three red candles, strict wick chain
The bottom formation. o0 is the newest red, walking backward to o3 (the wick candle, any color). Each lower wick's TIP must land strictly inside the next (lower) candle's body AND the bodies must not overlap — the pattern is a descending ladder, not a cluster.
close < open. o3 can be any color.low < body_bottom. No Doji / no-wick candle can start the chain.B.body_bot ≤ A.low ≤ B.body_top. Zero tolerance.A.body_bot ≥ B.body_top. A sits at or above B; they don't straddle.MID & TARGET — which SFP HIGHs matter
Once the 3R prints, the detector looks BACKWARD through every SFP HIGH recorded before the 3R bar and picks two of them:
HH — highest-high resistance line
HH is the single highest price printed in the window
[mid_sfp_bar, 3r_bar], inclusive. The 3G breakout candle
g2 must close strictly above this level to be valid.
If TARGET ≤ HH, no 3G can ever form — the setup is rejected
immediately.
SL tracking — the 5-bar lock rule
Stop-loss management is the only invalidation channel before 3G fires. There's no time-based expiry; the setup lives until SL breaks or a 3G confirms. The rules differ between the first 5 bars after 3R and anything after.
body_bottom < SL→ CANCELLED (hard kill on body close below)low < SLbut body holds → SL moves down to the new lowhigh ≥ TP→ CANCELLED_TP (price hit target before 3G)
body_bottom < SL→ CANCELLEDlow < SL(any wick) → CANCELLEDhigh ≥ TP→ CANCELLED_TP
3G — three green breakout candles
The mirror image of 3R, with an extra strictness twist. g2, g1, g0 are three consecutive BULLISH candles with upper wicks chaining UP into each next body. g3 is a separate anchor candle (any color) whose upper wick reaches into g2's body AND which g2 clearly broke above.
close > open, adjacent indices.A.high ∈ [B.body_bot, B.body_top] for (g3→g2), (g2→g1), (g1→g0).g2.close > g3.high. g2 must clear g3's entire wick, not just touch the body.H[k] < H[g2] for every bar k in [mid_sfp, g2-1].g2.close > HH.H[g2], H[g1], H[g0] < TARGET.⚡ SDT Fires — entry, TP, SL
The setup is LIVE the instant g0 closes. Entry is taken at g0's close.
TP is placed at the TARGET SFP extreme. SL is whatever
current_sl is at that moment — the original 3R low, possibly
adjusted down during Phase 1. From this bar forward, the outcome is
decided by whichever level gets hit first.
Win / Loss tracking
After g0, the setup is scanned forward bar by bar. Pine's optimistic order is preserved: TP is checked first, so if a single candle's wick touches both levels in the same bar, the outcome is WIN.
high ≥ TARGETlow < SL