Break-Hook-Go (BHG)
Relevant source files
The following files were used as context for generating this wiki page:
Break-Hook-Go (BHG) is a specialized state-machine engine and trading methodology within the Rabid Raccoon project designed to detect high-probability intraday setups for the Micro E-mini S&P 500 (MES). It focuses on identifying structure breaks, retests (hooks), and continuation patterns based on Fibonacci retracement levels.
The system processes raw OHLCV candle data alongside Fibonacci results and measured moves to identify sequential phases of a trade setup. Once a setup reaches the "GO" phase, the engine automatically calculates entry, stop-loss, and multiple take-profit targets based on Fibonacci extensions and market structure.
Sources: src/lib/bhg-engine.ts:1-12, README.md:16
Architecture and Core Logic
The BHG system is built as a stateless engine that recomputes setup states from a provided history of candles. It follows a strict sequential state machine: Touch → Hook → Go.
Setup Phases
The engine tracks setups through the following lifecycle phases:
| Phase | Description |
|---|---|
AWAITING_TOUCH | Initial state before price interacts with key Fibonacci levels. |
TOUCHED | Price has tagged the 0.5 or 0.618 Fibonacci retracement level. |
HOOKED | A wick rejection candle has occurred at the touched Fibonacci level. |
GO_FIRED | Price has broken or closed past the extreme of the "Hook" candle, confirming entry. |
EXPIRED | The setup failed to progress within the allowed expiryBars (default 20). |
INVALIDATED | The price action violated the setup requirements. |
Sources: src/lib/bhg-engine.ts:15-20, src/lib/bhg-engine.ts:37-41
Logic Flow Diagram
The following diagram illustrates the progression of a BHG setup from initial detection to trade confirmation.
The state machine advances from TOUCHED to HOOKED and finally GO_FIRED based on specific price action triggers.
Sources: src/lib/bhg-engine.ts:251-315
Technical Implementation
State Transitions
The engine implements specific mathematical checks for each transition:
- Touch Detection: Occurs when a candle's range (high/low) overlaps with the 0.5 or 0.618 Fibonacci levels.
- Hook Detection: Requires a "wick rejection." For a bullish setup, the candle must low-tag the level, close above it, and the rejection wick (close - low) must be greater than or equal to the candle body size.
- Go Detection: Occurs when price either breaks (
high > hookHighfor bullish) or closes beyond the high of the hook candle. The system prioritizes "BREAK" over "CLOSE" triggers.
Sources: src/lib/bhg-engine.ts:103-116, src/lib/bhg-engine.ts:133-149, src/lib/bhg-engine.ts:187-205
Target Calculation
When a setup fires a GO signal, the engine computes trade levels:
- Entry: Set at the hook's close price.
- Stop Loss: Placed beyond the next Fibonacci level (e.g., a 0.618 stop for a 0.5 touch).
- TP1/TP2: Calculated using 1.272 and 1.618 Fibonacci extensions, though TP1 is overridden if an aligned Measured Move target exists.
Sources: src/lib/bhg-engine.ts:251-285, src/lib/bhg-engine.ts:311-331
Visualization and UI Components
The BHG system includes custom rendering primitives for integration with lightweight-charts.
Chart Markers
The BhgMarkersPrimitive class handles the visual representation of setups:
- TOUCH: Rendered as a small grey circle at the Fibonacci level.
- HOOK: Rendered as an amber triangle pointing in the rejection direction.
- GO: Rendered as a filled green (bullish) or red (bearish) diamond.
- Levels: Dashed lines project the Entry, SL, TP1, and TP2 into future chart whitespace.
Sources: src/lib/charts/BhgMarkersPrimitive.ts:24-40, src/lib/charts/BhgMarkersPrimitive.ts:88-142
Setup Log
The SetupLog component provides a real-time list of detected setups, sorted by relevance (active "GO" signals first, followed by "HOOKED" signals). It displays the direction, time, phase, and Fibonacci ratio for each event.
Sources: src/components/MesIntraday/SetupLog.tsx:43-61
Data and Machine Learning Integration
The project includes scripts to build datasets specifically for training machine learning models (like AutoGluon) to score these setups.
The relationship between BHG setups, candle data, and Fibonacci results as utilized in the training pipeline.
Sources: scripts/build-bhg-dataset.ts:601-625
Dataset Features
The build-bhg-dataset.ts script extracts over 85 features per setup, including:
- Fib Context: Distances to levels in ticks and R-multiples.
- Trap/Sweep Flags: Detects if price swept prior swing extremes before the hook.
- Open-Space Ratio: Measures "blocker density" (Fib levels) between entry and TP1.
- Market Regime: Enriches setups with VIX levels and daily macro context from FRED.
Sources: scripts/build-bhg-dataset.ts:108-160, scripts/build-bhg-dataset.ts:503-518
Summary
Break-Hook-Go is a technical analysis framework that automates the identification of Fibonacci-based continuation trades. By combining a rigid state machine with structural market analysis (measured moves and swing detection), it provides a systematic approach to intraday MES trading, supported by both visual charting tools and a data-rich pipeline for machine learning refinement.