Fibonacci Scoring
Relevant source files
The following files were used as context for generating this wiki page:
Fibonacci Scoring in the Rabid Raccoon project refers to the systematic calculation, visualization, and predictive modeling of Fibonacci retracement and extension levels to evaluate market setups. The system transitions from raw geometric price action calculations to sophisticated machine learning models that score the probability of these levels being reached during a trading session.
The engine identifies "Swing Highs" and "Swing Lows" to establish anchors, calculates standard ratios (retracements and extensions), and applies a binary classification model to predict "Take Profit" (TP) hits versus "Stop Loss" (SL) events. This scoring is a critical component of the Break-Hook-Go (BHG) strategy used primarily for MES (Micro E-mini S&P 500) futures.
Sources: src/lib/fibonacci.ts, scripts/train-fib-scorer.py:1-25, README.md
Core Fibonacci Engine
The Auto-Fibonacci Engine is the foundation of the scoring system. It identifies market direction based on the relative timing of the most recent swing points. If the most recent swing low has a higher bar index than the most recent swing high, the engine classifies the regime as bullish.
Calculation Logic
The engine uses the distance between the anchorHigh and anchorLow to derive levels.
- Retracements: Derived by adding (bullish) or subtracting (bearish) a portion of the range from the anchor low or high.
- Extensions: Projected beyond the 1.0 (100%) retracement level to identify potential targets.
The diagram above shows the logic flow for determining market direction and calculating price levels.
Sources: src/lib/fibonacci.ts:15-60
Fibonacci Levels and Ratios
The system tracks specific ratios assigned with distinct labels and colors for UI representation.
| Ratio | Type | Label | Color |
|---|---|---|---|
| 0.0 | Retracement | 0 | (Internal) |
| 0.236 | Retracement | .236 | #787b86 |
| 0.382 | Retracement | .382 | #787b86 |
| 0.500 | Retracement | .5 | #787b86 |
| 0.618 | Retracement | .618 | #787b86 |
| 0.786 | Retracement | .786 | #787b86 |
| 1.000 | Retracement | 1 | #787b86 |
| 1.272 | Extension | 1.272 | #787b86 |
| 1.618 | Extension | 1.618 | #787b86 |
Sources: src/lib/fibonacci.ts:18-30, src/lib/fibonacci.ts:65-90
Predictive Scoring Model
The train-fib-scorer.py script implements a machine learning pipeline to assign probability-based scores to Fibonacci setups. It specifically targets the likelihood of hitting extension levels before a stop-loss is triggered.
Target Classification
The model trains two binary classifiers using AutoGluon:
- y1272: Probability of hitting the 1.272 extension (TP1) within a 4-hour horizon.
- y1618: Probability of hitting the 1.618 extension (TP2) within an 8-hour horizon.
Sources: scripts/train-fib-scorer.py:7-15, scripts/train-fib-scorer.py:65-80
Composite Scoring and Grading
A final score is calculated as a weighted average of the two targets, which is then converted into a letter grade to provide a clear qualitative assessment for traders.
Formula:
Score = (0.30 * P(TP1)) + (0.70 * P(TP2))
| Grade | Score Threshold |
|---|---|
| A | >= 0.65 |
| B | >= 0.50 |
| C | >= 0.35 |
| D | < 0.35 |
Sources: scripts/train-fib-scorer.py:12-14, scripts/train-fib-scorer.py:90-95
Data Engineering for Scoring
The scoring system relies on a rich feature set extracted during the "GO" event of a Fibonacci setup. This involves merging technical indicators with macro-economic context.
Feature Categories
- Fib Context: Touch levels, distances to 50% or 61.8% levels in ticks, and risk-reward (R) ratios.
- Trap/Sweep Detection: Identifies if price broke a prior swing extreme before reversing (liquidity sweeps).
- Open-Space/Blockers: Calculates "Blocker Density" by counting other Fibonacci levels between the entry and the target.
- Macro Enrichment: Lags FRED data (VIX, DXY) by one day to prevent data leakage during training.
Sources: scripts/build-bhg-dataset.ts:10-30, scripts/build-bhg-dataset.ts:125-180
The diagram represents the dataset construction process for training the Fibonacci Scorer.
Sources: scripts/build-bhg-dataset.ts:360-450
Integration with Analysis Engines
Fibonacci scoring is consumed by the Instant Analysis Engine and the Forecast Engine to provide live trade signals.
Instant Multi-Timeframe Analysis
The analysis engine computes Fibonacci structure and position as specific signals:
- Structure Signal: Evaluates if the anchor points suggest a bullish or bearish trend.
- Position Signal: Identifies where the current price sits relative to the levels (e.g., "above .618").
- Measured Move Integration: Links Fibonacci levels to AB=CD patterns to identify "active" targets.
Sources: src/lib/instant-analysis.ts:193-215, src/lib/forecast.ts:80-100
Automated Forecasting
The forecast module uses Fibonacci extension levels to infer key support and resistance zones when generating automated narratives.
- Bullish Scenario: Support is inferred from the entry and stop levels of the Fibonacci setup; resistance is the 1.272 or 1.618 target.
- Level Ordering: The engine enforces strict directional consistency (e.g., for a BUY,
stop < entry < target).
Sources: src/lib/forecast.ts:102-125, src/lib/instant-analysis.ts:515-540
Conclusion
Fibonacci Scoring in the Rabid Raccoon project is a multi-layered system that validates price action geometry through statistical modeling. By combining deterministic calculations with machine learning grades (A-D), the system provides traders with a probabilistic assessment of whether a Fibonacci-based trade setup is likely to reach its projected extension targets.