Pattern Matching Algorithms
The pattern matching system supports three algorithms for finding similar candlestick patterns across stocks. Each algorithm offers different trade-offs between precision and flexibility.
1. Direction Only
DefaultHow it works: Each candle is encoded as a single character based on direction:
- G = Green candle (close ≥ open)
- R = Red candle (close < open)
Matching Modes
| Mode | Description | Example |
|---|---|---|
| Strict | Exact match required | GGRR matches only GGRR |
| Lax | Allows +/- 1 candle per run | GGRR matches GRR, GGGRR, GGRRR |
Best for: Simple directional patterns, short sequences (2-8 candles)
2. Direction + Size
How it works: Matches both direction and relative candle body sizes.
Size Categories
Each candle's body size is compared to the pattern's average:
| Category | Criteria | Meaning |
|---|---|---|
| Small | < 50% of average | Narrow body, indecision |
| Medium | 50% - 150% of average | Normal movement |
| Large | > 150% of average | Strong conviction |
Matching Modes
| Mode | Direction | Size |
|---|---|---|
| Strict | Must match exactly | Must match exactly |
| Lax | Must match exactly | Can differ by one level (S↔M, M↔L) |
Best for: Finding patterns with similar magnitude moves
3. Candlestick Patterns
AdvancedHow it works: Detects recognized candlestick formations and encodes them as pattern symbols. This dramatically reduces pattern length and finds semantically similar patterns.
GGRRRGGGGRGGGRRRRGG
BE-U3-D-MS-U2
Detected Patterns
Single Candle Patterns
| Symbol | Name | Detection |
|---|---|---|
D |
Doji | Body < 10% of range (indecision) |
H |
Hammer | Body < 30% of range, lower wick > 2x body, upper wick < body |
SS |
Shooting Star | Body < 30% of range, upper wick > 2x body, lower wick < body |
M |
Marubozu | Body > 90% of range (almost no wicks) |
Two Candle Patterns
| Symbol | Name | Detection |
|---|---|---|
BE |
Bullish Engulfing | Red candle followed by larger green that completely engulfs its body |
XE |
Bearish Engulfing | Green candle followed by larger red that completely engulfs its body |
BH |
Bullish Harami | Large red candle, small green (< 50% body) contained inside |
XH |
Bearish Harami | Large green candle, small red (< 50% body) contained inside |
Three Candle Patterns
| Symbol | Name | Detection |
|---|---|---|
MS |
Morning Star | Large red (body > 50%), small middle (< 30%), large green closing above first's midpoint |
ES |
Evening Star | Large green (body > 50%), small middle (< 30%), large red closing below first's midpoint |
3W |
Three White Soldiers | Three consecutive strong green candles (body > 50%), each closing higher |
3B |
Three Black Crows | Three consecutive strong red candles (body > 50%), each closing lower |
Directional Runs
| Symbol | Name | Detection |
|---|---|---|
U# |
Up Run | # consecutive green candles (not matching a specific pattern) |
R# |
Down Run | # consecutive red candles (not matching a specific pattern) |
Matching Modes
| Mode | Behavior |
|---|---|
| Strict | Pattern symbols must match exactly |
| Lax |
|
Best for: Long patterns (10+ candles), finding semantically similar chart formations