The PolyClaw Trading engine recognizes sixteen deterministic candlestick patterns implemented inDocumentation Index
Fetch the complete documentation index at: https://mintlify.com/deniszidbaev-cmyk/polyclaw-trading/llms.txt
Use this file to discover all available pages before exploring further.
src/polyclaw_engine/patterns.py. Patterns are detected on completed candles only ("complete": true) using the 5m series for execution and evaluated against configurable thresholds sourced from EngineConfig. Each pattern is assigned a fixed strength score used to rank and tiebreak competing signals. All threshold comparisons use epsilon-guarded inclusive boundaries (EPSILON = 1e-12).
All boundary comparisons are inclusive. The engine adds
EPSILON = 1e-12 to one side of every >= and <= comparison to guard against floating-point rounding at exact boundary values. These guards are unit-tested at every documented threshold.Pattern summary table
| Pattern | Direction | Key threshold |
|---|---|---|
| Bullish Engulfing | YES | Current body >= 2.00× previous body |
| Bearish Engulfing | NO | Current body >= 2.00× previous body |
| Bullish Harami | YES | Current body <= 0.60× previous body |
| Bearish Harami | NO | Current body <= 0.60× previous body |
| Tweezer Bottom | YES | Relative extreme difference <= 10% |
| Tweezer Top | NO | Relative extreme difference <= 10% |
| Morning Star | YES | Third candle retraces >= 60%; strong >= 70%; middle body <= 40% |
| Evening Star | NO | Third candle retraces >= 60%; strong >= 70%; middle body <= 40% |
| Three White Soldiers | YES | Exactly 3; body >= 0.20× ATR; counter-wick <= 0.75× body |
| Three Black Crows | NO | Exactly 3; body >= 0.20× ATR; counter-wick <= 0.75× body |
| Bullish Shadow Breakout | YES | Lower wick >= 1.50× ATR; close location >= 65% |
| Bearish Shadow Breakout | NO | Upper wick >= 1.50× ATR; close location <= 35% (inverse of 65%) |
| Bullish Order-Block Sweep | YES | Excursion below 20-candle support >= 2%; close recovers above support |
| Bearish Order-Block Sweep | NO | Excursion above 20-candle resistance >= 2%; close falls below resistance |
| Bullish Impulse | context | Body >= 2.00× prior 20-candle average body (current excluded) |
| Bearish Impulse | context | Body >= 2.00× prior 20-candle average body (current excluded) |
| POC Context | context | |close − poc| / poc <= 1% |
Pattern strength scores
Each pattern has a fixed strength score. When multiple patterns fire simultaneously, the strongest compatible pattern takes priority, and the score for thepatterns confidence component is boosted by 0.05 per additional compatible pattern (clamped to [0, 1]):
| Pattern | Strength |
|---|---|
| Bullish / Bearish Engulfing | 0.90 |
| Morning / Evening Star | 0.90 |
| Three White Soldiers / Three Black Crows | 0.85 |
| Bullish / Bearish Order-Block Sweep | 0.85 |
| Bullish / Bearish Shadow Breakout | 0.80 |
| Bullish / Bearish Impulse | 0.75 |
| Tweezer Bottom / Top | 0.70 |
| Bullish / Bearish Harami | 0.60 |
Configurable thresholds
All pattern thresholds are sourced fromEngineConfig and can be overridden via environment variables. The defaults reflect the values documented in btc_strategy_engine.md and enforced by the config validator:
| Env var | Default | Controls |
|---|---|---|
ENGULFING_BODY_MULTIPLIER | 2.0 | Minimum ratio of current body to previous body for engulfing patterns |
HARAMI_BODY_MAX_RATIO | 0.60 | Maximum ratio of current body to previous body for harami patterns |
TWEEZER_WICK_DIFFERENCE_PCT | 0.10 | Maximum relative difference between the two extreme wicks |
STAR_MIN_RETRACE_RATIO | 0.60 | Minimum retrace ratio for morning/evening star (standard) |
STAR_STRONG_RETRACE_RATIO | 0.70 | Minimum retrace ratio for a strong morning/evening star |
STAR_MIDDLE_BODY_MAX_RATIO | 0.40 | Maximum middle-candle body as a fraction of the first candle’s body |
THREE_CANDLE_PATTERN_LENGTH | 3 | Fixed length for three-candle patterns (not user-adjustable in practice) |
THREE_CANDLE_MIN_BODY_ATR_RATIO | 0.20 | Minimum body size as a multiple of ATR14 for each soldier/crow candle |
THREE_CANDLE_MAX_COUNTER_WICK_BODY_RATIO | 0.75 | Maximum counter-direction wick as a fraction of the body |
SHADOW_BREAKOUT_ATR_MULTIPLIER | 1.5 | Minimum wick size as a multiple of ATR14 for shadow breakout |
SHADOW_CLOSE_LOCATION_MIN | 0.65 | Minimum close-location ratio for bullish shadow breakout (must be > 0.5) |
ORDER_BLOCK_SWEEP_PCT | 0.02 | Minimum excursion beyond the 20-candle support/resistance level (2%) |
ORDER_BLOCK_LOOKBACK | 20 | Number of prior candles used to compute support/resistance |
IMPULSE_BODY_MULTIPLIER | 2.0 | Minimum body size as a multiple of the 20-candle average body |
IMPULSE_BODY_LOOKBACK | 20 | Lookback window for average body (current candle excluded) |
POC_CONTEXT_DISTANCE_PCT | 0.01 | Maximum distance from POC as a fraction of POC (1%) |
Detailed pattern specifications
Engulfing (Bullish / Bearish)
A two-candle reversal pattern. The current candle completely covers the prior candle’s body in both directions.previous.bullish and current.bearish with the same size and coverage conditions.
Harami (Bullish / Bearish)
A two-candle inside-bar pattern. The current candle’s body fits entirely within the prior candle’s body and is at mostHARAMI_BODY_MAX_RATIO times as large.
previous.bullish and current.close <= current.open.
Tweezer Bottom / Top
A two-candle pattern where both candles share nearly identical lows (bottom) or highs (top).relative_difference(a, b) = |a - b| / max(|a|, |b|, EPSILON)
Morning / Evening Star
A three-candle reversal pattern. The middle candle must be small; the third candle must retrace a significant portion of the first candle’s body.STAR_STRONG_RETRACE_RATIO (0.70) is documented for classification purposes (strong vs. standard confirmation) but the execution gate uses STAR_MIN_RETRACE_RATIO (0.60).
The evening star mirrors this with first.bullish, third.bearish, and retrace = (first.close - third.close) / first.body.
Three White Soldiers / Three Black Crows
Three consecutive candles of the same direction, each closing higher (soldiers) or lower (crows) than the previous, with substantial bodies and minimal counter-direction wicks.bar.bearish, bars[i].close < bars[i-1].close, and capping lower_wick instead of upper_wick.
Shadow Breakout (Bullish / Bearish)
The current candle’s wick spikes through the prior candle’s extreme, then the close recovers back inside.close_location = (close - low) / (high - low) — 0.0 is the session low, 1.0 is the session high.
Order-Block Sweep (Bullish / Bearish)
The current candle sweeps a key support or resistance level established over the priorORDER_BLOCK_LOOKBACK candles, then closes back inside that level.
Impulse (Bullish / Bearish)
A single-candle momentum pattern where the current candle’s body is significantly larger than the recent average.context direction in the summary table because they do not independently determine YES/NO outcome mapping — they amplify an existing trend signal.
POC Context
Not a candlestick pattern per se, but detected alongside patterns. If the latest close is withinPOC_CONTEXT_DISTANCE_PCT (default 1%) of the sample-density POC, the near_poc flag is set to True and the poc_context confidence component contributes 0.30 (weight 0.05) to the raw score.
Execution gate requirements
The following additional pattern-related conditions also force aHOLD:
- High-strength collision — both
bullishandbearishpattern lists are non-empty, and both sides have at least one pattern with strength>= 0.80. The blocking reason is"bullish and bearish high-strength pattern collision". - EMA-pattern conflict — the strongest incompatible pattern has a higher strength score than the strongest compatible pattern. The blocking reason is
"EMA direction conflicts with the strongest candle pattern".
HOLD record in runtime/manual_review.json rather than a low-confidence live order.