## Goal
- Build and improve an ML trading strategy for MOEX instruments with directional probability model (long/short success predictions), DQN reinforcement learning, and robust walk-forward validation.

## Constraints & Preferences
- SL = 1.5×ATR, TP = 3.0×ATR (RR 1:2)
- MySQL bitcoin_tickers on nlbotinterface.ru:3306 (user bitcoin / g49020007)
- Chronological train/test split (80/20), never shuffle
- Features must not look ahead (rolling windows only, D1/W1 shifted by 1 period)
- No multi-TF D1/W1 lookahead — fixed by shifting higher-TF timestamps +86400s / +604800s

## Progress
### Done
- Project structure, DB modules, feature engineering, target computation (3-class + dual long/short)
- Directional probability model (`features/directional.py`): 8 signals + 15 technical features + 5 interaction features + 8 context = 36 total (35 after dedup)
- Multi-TF (D1, W1) support, chart context module, multi-ticker training
- DQN agent with chronological episodes, dense reward, entry penalty, LR scheduler
- LSTM model tested (underperforms tree models)
- Lookahead bug fixed (D1/W1 shifted by 1 period)
- DQN reward improvements (dense PnL, entry penalty, best-epoch save)
- **Feature importance analysis**: identified top-12 features, 5 dead features (doji, engulfing, hh_streak, ll_streak, volume_signal)
- **Stacking ensemble**: RF + XGB + LightGBM with logistic meta-learner
- **Probability calibration**: Platt + Isotonic tested (limited benefit due to weak signal)
- **Interaction features**: 5 best pairs added (bb_width_x_atr_pct #5, bb_width_x_rsi #8, cts50_x_ret20 #9)
- **macd_signal dedup bug fixed**

### Best Model
**RF top-12 with interaction features** — walk-forward results:

| Model | Avg WR/fold | Avg Ret/fold | Pos folds | Trades |
|---|---|---|---|---|
| **RF top-12 (interactions)** | **41.6%** | **+92.95%** | **5/7** | **2536** |
| RF all 35 (interactions) | 41.2% | +73.65% | 5/7 | 1929 |
| RF 30 (no interactions) | 42.4% | +53.58% | 6/7 | 1769 |
| Stacking (RF+XGB+LGBM) | 37.1% | +71.71% | 5/7 | 9014 |
| XGB all 30 | 38.2% | +57.52% | 5/7 | 5359 |
| DQN (best epoch) | 50.0% | +13.2% | - | 68 |

### CLI
- `--importance` — feature importance ranking + reduced model comparison
- `--top-k N` — train with top N features by importance
- `--stacking` — stacking ensemble (RF + XGB + LGBM)
- `--calibrate` — isotonic probability calibration
- `--list` — list MOEX instruments

### Key Findings
- **Interaction features improved returns by +73%** over baseline RF (+92.95% vs +53.58%)
- **Top-12 features are optimal** — more trades (2536) than all-35 (1929), similar WR
- **3 interaction features in top 12**: bb_width_x_atr_pct (#5), bb_width_x_rsi (#8), cts50_x_ret20 (#9)
- L2-regularized meta-learner with stacking trades 5x more but lower WR
- Probability calibration doesn't help — model signal inherently capped at ~37-39% accuracy

### Next Steps
1. Adaptive threshold per fold (optimize on val set within walk-forward)
2. Position sizing (Kelly Criterion) instead of equal bets
3. Multi-ticker training with single-TF SBER+GAZP+LKOH
4. PPO as alternative RL algorithm
5. LightGBM standalone (was tested as part of stacking only)
