Version: 1.0.0
Last Updated: 2025-01-17
Status: Initial public documentation
Complex mode analyzes custom candle sequences such as [1, 1, -1, 1] rather than a plain N-candle streak. It extends the simple streak engine with pullback-quality analysis, signal scoring, short-signal logic, and richer chart-oriented outputs.
graph TD
A["API request"] --> B["Build AnalysisContext"]
B --> C["Validate context"]
C --> D{"Complex mode?"}
D -->|Yes| E["Load and prepare data"]
E --> F["Calculate indicators"]
F --> G["Match complex pattern"]
G --> H{"Pattern found?"}
H -->|No| I["Return no-match payload"]
H -->|Yes| J["Analyze pullback quality"]
J --> K["Apply filters and score signals"]
K --> L["Compute C1 / C2 performance"]
L --> M["Calculate volatility stats"]
M --> N["Run optional short-signal and interval studies"]
N --> O["Build response payload"]
- Request reaches
backend/modules/streak/router.py. AnalysisContextvalidates the complex pattern and determines the mode.- Shared data loaders return a normalized OHLCV DataFrame.
- Complex-mode logic calculates indicators required for quality scoring.
- Pattern-matching logic finds every matching sequence.
- Pullback and volume quality are measured.
- C1/C2 performance, volatility, and optional side analyses are computed.
- The frontend receives a structured payload for tables, filters, and charting.
Complex mode relies on indicator columns beyond the base OHLCV set. Typical fields include:
- ATR
- RSI
- disparity
- volume-derived helpers
Pattern matching is handled through the shared streak utilities and checks that the ordered candle sequence matches the requested array.
Example input patterns:
[1, 1, -1, 1]
[1, 1, 1, -1, -1, 1]
[-1, -1, 1, 1]
The quality step measures whether the matched sequence contains a healthy pullback rather than random noise.
Typical signals:
- retracement ratio
- pullback volume ratio
- momentum context
Signal scoring combines pattern quality and context indicators into a ranked output. The goal is not only to say that a pattern occurred, but also to estimate whether it happened in a stronger or weaker setup.
Complex mode keeps the same candle definitions as simple mode:
C1: first candle after pattern completion (T+1)C2: second candle after pattern completion (T+2)
Computed outputs include:
c1_success_countc1_total_countc2_success_countc2_total_count- average profit or body metrics for
C1andC2
The module computes post-pattern drawdown and rise behavior, including practical and extreme downside metrics.
Typical outputs:
- average dip
- average rise
- dip standard deviation
- ATR percentage
- practical max dip
- extreme max dip
Complex mode can also test short setups when the pattern ends in an overheated bullish configuration.
Typical checks:
- filter overbought cases
- define an entry threshold
- test whether price reaches the entry zone
- measure fill rate and short win rate
Interval studies bucket matched cases by derived indicators such as RSI or disparity and then compute:
C1probability by bucket- Wilson confidence intervals
- Bonferroni-adjusted significance flags
| Value | Meaning | Rule |
|---|---|---|
1 |
Green candle | close > open |
-1 |
Red candle | close < open |
| Metric | Preferred zone | Interpretation |
|---|---|---|
| Retracement ratio | 20-40% | Healthy pullback depth |
| Volume ratio | < 0.8 |
Lower pullback volume is healthier |
| RSI | 45-65 | Neutral-to-stable momentum context |
C1 (T+1): first candle after pattern completionC2 (T+2): second candle after pattern completion- success is defined relative to the analysis rule being applied
run_complex_analysis()
-> compute indicators
-> find_complex_pattern()
-> analyze_pullback_quality()
-> calculate_signal_score()
-> compute C1/C2 performance
-> build chart and table outputs
- Complex strategy:
backend/strategy/streak/complex_strategy.py - Shared utilities:
backend/strategy/streak/common.py,backend/strategy/streak/statistics.py - API endpoint:
backend/modules/streak/router.py - Controller:
backend/strategy/streak/__init__.py
| Capability | Simple Mode | Complex Mode |
|---|---|---|
| Input form | n_streak |
complex_pattern array |
| Example | 3 green candles in a row | [1, 1, -1, 1] |
| Pullback-quality analysis | No | Yes |
| Signal scoring | No | Yes |
| Indicator-based filtering | Limited | Expanded |
C1 analysis |
Yes | Yes |
C2 analysis |
Yes | Yes |
| Chart-oriented payloads | Minimal | Richer |
| Best use case | Repeated simple streaks | Repeated structured sequences |
- Replaced
sum(1 for x in pattern if x == 1)withpattern.count(1) - Consolidated multiple
C1/C2loops into a single pass - Replaced separate confidence-count loops with list-comprehension paths
- Very long patterns can slow down matching
- practical recommendation: keep pattern length near 5-7 candles when possible
- large match sets can increase memory use
- chart payload generation involves extra copying and formatting
max_retracementwas removed from hard filtering in favor of scoring and user interpretation
- Initial document creation
- Added Mermaid-style flow documentation
- Added detailed execution stages, key concepts, and optimization notes