SL/TP Level Calculation
calculateSlTp() in slTpCalculator.ts computes stop-loss and three take-profit levels for every detected pattern. Each level can be scaled by per-pattern multipliers from a user’s TradingConfig (slMultiplier, tp1Multiplier, tp2Multiplier, tp3Multiplier).
All ± signs are direction-dependent: bullish patterns add to D, bearish patterns subtract.
Harmonic Patterns — Standard (Gartley, Bat, Shark)
D retraces toward X without exceeding it, so SL is placed beyond X.
| Level | Formula |
|---|---|
| SL | Beyond X (or prevSwingPrice if more extreme), ±0.1% buffer |
| TP1 | D ± 0.382 × |A − D| |
| TP2 | D ± 0.618 × |A − D| |
| TP3 | A price |
Butterfly & Crab
D extends beyond X, making D the most extreme point. SL must be placed beyond D.
| Level | Formula |
|---|---|
| SL | Beyond D, ±0.1% buffer |
| TP1 | D ± 0.382 × |A − D| |
| TP2 | D ± 0.618 × |A − D| |
| TP3 | A price |
Cypher
TPs use the full XC move as the measuring rod; SL is beyond X.
| Level | Formula |
|---|---|
| SL | Beyond X, ±0.1% buffer |
| TP1 | D ± 0.382 × |XC| |
| TP2 | D ± 0.618 × |XC| |
| TP3 | C price |
Three Drives
| Level | Formula |
|---|---|
| SL | Beyond X, ±0.1% buffer |
| TP1 | D ± 0.382 × drive1Size |
| TP2 | D ± 0.618 × drive1Size |
| TP3 | A price |
(drive1Size = |XA|)
ABCD
SL is proportional to the CD leg rather than an absolute swing extreme.
| Level | Formula |
|---|---|
| SL | 10% of |CD| beyond D |
| TP1 | D ± 0.618 × |CD| |
| TP2 | D ± 1.0 × |CD| |
| TP3 | A price |
Double Top & Double Bottom
patternHeight = |necklinePrice − peakOrTroughPrice|
| Level | Formula |
|---|---|
| SL | Beyond the higher peak (top) / lower trough (bottom), ±0.1% |
| TP1 | neckline ± 0.5 × patternHeight |
| TP2 | neckline ± 1.0 × patternHeight |
| TP3 | neckline ± 1.5 × patternHeight |
Head & Shoulders
headHeight = |headPrice − necklinePrice|
| Level | Formula |
|---|---|
| SL | Beyond the head, ±0.1% |
| TP1 | necklinePrice |
| TP2 | necklinePrice ± headHeight |
| TP3 | necklinePrice ± 1.5 × headHeight |
Candlestick Patterns
| Family | SL | TP1 | TP2 | TP3 |
|---|---|---|---|---|
| Hammer / Inv. Hammer | Below candle low | D + 0.5× wick | D + 1× wick | D + 1.5× wick |
| Shooting Star / Hanging Man | Above candle high | D − 0.5× wick | D − 1× wick | D − 1.5× wick |
| Doji | Beyond range extreme | ±0.5× range | ±1× range | ±1.5× range |
| Engulfing / Piercing / Harami (bullish) | Below c1 low | D + 0.618× range | D + 1× range | D + 1.618× range |
| Engulfing / Dark Cloud / Harami (bearish) | Above c1 high | D − 0.618× range | D − 1× range | D − 1.618× range |
| Tweezer | Beyond range extreme | ±1× risk | ±1.5× risk | ±2× risk |
| Morning / Evening Star | Beyond star low/high | ±0.5× c1 height | ±1× c1 height | ±1.5× c1 height |
| Three White Soldiers | Below c1 open | D + 0.382× full move | D + 0.618× full move | D + 1× full move |
| Three Black Crows | Above c1 open | D − 0.382× full move | D − 0.618× full move | D − 1× full move |