Overview
Feature engineering is the first step in both training and inference.ml/feature_engineering.py transforms raw OHLCV candles into the 62-feature vector consumed by all four models.
The feature list is a contract. The training pipeline, inference pipeline, and ml_config.json must all reference the same 62 features in the same order. Any change requires retraining all 4 models.
Feature groups
Bollinger Bands (4 features)
Bollinger Bands (4 features)
Trend (8 features)
Trend (8 features)
Momentum (6 features)
Momentum (6 features)
Volatility (5 features)
Volatility (5 features)
Volume (4 features)
Volume (4 features)
Price structure (6 features)
Price structure (6 features)
Session and news (7 features) β PROTECTED
Session and news (7 features) β PROTECTED
These features must never be dropped based on SHAP analysis alone. Historical testing showed removing them increased drawdown significantly. They carry regime and timing information not captured by price alone.
Account state (7 features)
Account state (7 features)
These features are computed at runtime from live account data, not from candles. They allow the models to adapt to current account health.
Time features (12 features)
Time features (12 features)
Market regime (3 features) β Phase 17.2
Market regime (3 features) β Phase 17.2
Derived entirely from existing OHLCV data β no external API dependencies.
Labeling
ml/feature_engineering.py uses ATR-aware forward labeling to generate training targets.
For signal model labels:
tp_atr multiplier is tuned during Optuna search. Labels are generated using the same ATR-based SL/TP logic that the live bot uses, ensuring training distribution matches live inference distribution.
For position model labels, ml/position_labeling.py generates EXIT labels when the price subsequently reverses by more than a configurable threshold before reaching TP.
Adding or modifying features
The Three-File Rule applies to all feature changes:ml/feature_engineering.pyβ add the computationml_config.jsonβfeaturesarray β add the name in the correct position- Retrain all 4 models
python ml/hf_hub.py --push to publish the new models and models/model_compat.json to Hugging Face Hub.
Do not add features speculatively. Every added feature increases the risk of overfitting and must be validated with an OOS backtest showing improvement.