Halsey Module (Python)
Relevant source files
The following files were used as context for generating this wiki page:
The Halsey Module is a standalone Python-based intraday scanning and forecasting system specifically designed for Micro E-mini S&P 500 (MES) futures. It integrates high-resolution market data, macroeconomic indicators, and machine learning to identify specific "Halsey-style" price action patterns and generate predictive market regimes.
Sources: mes_hft_halsey/README.md:1-12, README.md:129-135
Module Overview and Architecture
The module operates as a high-frequency trading (HFT) utility that bypasses the primary Next.js application's data layer, opting instead for direct integration with Databento for trade-level data and FRED for macroeconomic context. It consists of three primary functional layers: a pattern scanner, an AutoGluon-powered time-series forecasting engine, and an optional API wrapper.
System Components
| Component | File Path | Description |
|---|---|---|
| CLI Scanner | mes_intraday_halsey.py | Core logic for detecting measured moves and exporting CSV signals. |
| ML Trainer | mes_autogluon_timeseries.py | Training pipeline for AutoGluon TimeSeries models using global symbol universes. |
| API Wrapper | mes_api.py | FastAPI interface providing endpoints for signals and forecasts. |
| Documentation | README.md | Configuration, setup, and rule definitions for the module. |
Sources: mes_hft_halsey/README.md:8-12, mes_hft_halsey/mes_intraday_halsey.py:24-60
High-Level Data Flow
The following diagram illustrates how the Halsey Module ingests data from external APIs to produce trading signals and forecasts.
The diagram shows the multi-source ingestion process used to generate signals and ML-based price projections.
Sources: mes_hft_halsey/mes_intraday_halsey.py:101-180, mes_hft_halsey/mes_autogluon_timeseries.py:230-260
Halsey Signal Detection Logic
The core of the Halsey Module is a deterministic pattern recognition engine that identifies "Measured Move" setups. These setups are based on a three-point price structure (A-B-C) and specific Fibonacci retracement zones.
Pattern Rules and Retracement Zones
- Bullish Setup: An impulse from point A (Low) to point B (High), followed by a retracement to point C (Low). Point C must fall within the 50% to 61.8% retracement zone of the A-B move.
- Bearish Setup: An impulse from point A (High) to point B (Low), followed by a retracement to point C (High). Point C must also fall within the 50% to 61.8% zone.
- Targets: Projections are set at the 100% and 123.6% measured move levels from point C.
- Risk Management: Minimum Risk/Reward (R:R) ratio of 1:2 is required for an enabled signal.
Sources: mes_hft_halsey/README.md:58-66, mes_hft_halsey/mes_intraday_halsey.py:317-438
Macroeconomic Filtering (VIX Regime)
The module applies a VIX-based filter to prevent taking trades in unsuitable volatility environments:
- Longs Filtered: Damped or disabled when VIX > 18.
- Shorts Filtered: Damped or disabled when VIX < 16.
Sources: mes_hft_halsey/README.md:65-68, mes_hft_halsey/mes_intraday_halsey.py:461-470
AutoGluon TimeSeries Integration
The module includes an "extreme" quality training pipeline that utilizes the AutoGluon 1.5 model zoo to forecast MES price action across multiple horizons.
Training Pipeline
The system can train on over 60 symbols simultaneously to leverage cross-asset patterns. It supports a diverse range of models:
- Statistical: AutoARIMA, AutoETS, Theta.
- Deep Learning: Temporal Fusion Transformer (TFT), PatchTST, DeepAR.
- Foundation Models: Chronos (tiny to large versions).
Sources: mes_hft_halsey/mes_autogluon_timeseries.py:425-475, TRAINING-COMPLETE.md:20-40
Horizon and Quality Settings
| Setting | Options / Values | Description |
|---|---|---|
| Timeframes | 5m, 15m, 1h, 4h, 1d | The base granularity of the model data. |
| Horizons | 5m to 7d | The specific future points predicted by the model. |
| Quality | fast, medium, high, best, extreme | Maps to AutoGluon presets and determines training time limits. |
| Time Limit | Up to 14,400s (4h) | The maximum duration for "extreme" quality training. |
Sources: mes_hft_halsey/mes_autogluon_timeseries.py:65-95, mes_hft_halsey/README.md:94-105
Data Models and Structures
HalseySignal Data Class
The HalseySignal dataclass represents a detected pattern in the market.
@dataclass
class HalseySignal:
timeframe: Timeframe
timestamp: str
direction: Direction
pattern: str
impulse_points: float
retrace_pct: float
entry: float
stop: float
target_100: float
target_1236: float
risk_reward_100: float
risk_reward_1236: float
enabled: bool
filter_reason: str
volume_confirmed: bool
Sources: mes_hft_halsey/mes_intraday_halsey.py:48-64
Model Summary Data Class
The MesRealModelSummary stores the results and metadata of a machine learning training run.
@dataclass
class MesRealModelSummary:
timeframe: Timeframe
quality: str
symbols_used: List[str]
bias: Literal["LONG", "SHORT", "FLAT"]
horizon_forecast: Dict[str, float]
leaderboard_top_model: str
leaderboard_top_score: float
Sources: mes_hft_halsey/mes_autogluon_timeseries.py:112-140
Summary
The Halsey Module provides a specialized, high-performance environment for futures trading analysis. By combining strict price action rules (Measured Moves) with advanced deep learning ensembles (AutoGluon), it serves as the primary quantitative backbone for MES intraday strategy generation within the Rabid Raccoon repository.
Sources: mes_hft_halsey/README.md:1-12, TRAINING-COMPLETE.md:160-170