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.

LevelFormula
SLBeyond X (or prevSwingPrice if more extreme), ±0.1% buffer
TP1D ± 0.382 × |A − D|
TP2D ± 0.618 × |A − D|
TP3A price

Butterfly & Crab

D extends beyond X, making D the most extreme point. SL must be placed beyond D.

LevelFormula
SLBeyond D, ±0.1% buffer
TP1D ± 0.382 × |A − D|
TP2D ± 0.618 × |A − D|
TP3A price

Cypher

TPs use the full XC move as the measuring rod; SL is beyond X.

LevelFormula
SLBeyond X, ±0.1% buffer
TP1D ± 0.382 × |XC|
TP2D ± 0.618 × |XC|
TP3C price

Three Drives

LevelFormula
SLBeyond X, ±0.1% buffer
TP1D ± 0.382 × drive1Size
TP2D ± 0.618 × drive1Size
TP3A price

(drive1Size = |XA|)


ABCD

SL is proportional to the CD leg rather than an absolute swing extreme.

LevelFormula
SL10% of |CD| beyond D
TP1D ± 0.618 × |CD|
TP2D ± 1.0 × |CD|
TP3A price

Double Top & Double Bottom

patternHeight = |necklinePrice − peakOrTroughPrice|

LevelFormula
SLBeyond the higher peak (top) / lower trough (bottom), ±0.1%
TP1neckline ± 0.5 × patternHeight
TP2neckline ± 1.0 × patternHeight
TP3neckline ± 1.5 × patternHeight

Head & Shoulders

headHeight = |headPrice − necklinePrice|

LevelFormula
SLBeyond the head, ±0.1%
TP1necklinePrice
TP2necklinePrice ± headHeight
TP3necklinePrice ± 1.5 × headHeight

Candlestick Patterns

FamilySLTP1TP2TP3
Hammer / Inv. HammerBelow candle lowD + 0.5× wickD + 1× wickD + 1.5× wick
Shooting Star / Hanging ManAbove candle highD − 0.5× wickD − 1× wickD − 1.5× wick
DojiBeyond range extreme±0.5× range±1× range±1.5× range
Engulfing / Piercing / Harami (bullish)Below c1 lowD + 0.618× rangeD + 1× rangeD + 1.618× range
Engulfing / Dark Cloud / Harami (bearish)Above c1 highD − 0.618× rangeD − 1× rangeD − 1.618× range
TweezerBeyond range extreme±1× risk±1.5× risk±2× risk
Morning / Evening StarBeyond star low/high±0.5× c1 height±1× c1 height±1.5× c1 height
Three White SoldiersBelow c1 openD + 0.382× full moveD + 0.618× full moveD + 1× full move
Three Black CrowsAbove c1 openD − 0.382× full moveD − 0.618× full moveD − 1× full move