Commit Graph

9 Commits

Author SHA1 Message Date
harwinder 541ef7ff4a Remove WebSocket: use candle-boundary scanning only
- Remove websockets import, _ws_monitor, _handle_breach, _breach_tasks
- Remove _WS_TO_PAIR, _WS_SYMBOLS, _WS_URL, _WS_COOLDOWN constants
- Remove _last_prices, _scan_cooldowns, _cleanup_cooldowns
- Remove ws_cooldown_seconds from PlatformConfig
- Remove websockets from requirements.txt
- Simplify _check_level_breach to proximity-based detection
- Update dashboard to use report prices instead of WS prices
- Clean up status/help messages, _start/_stop_scheduler
- Update tests to match new level breach behavior

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-05-18 17:38:25 -04:00
harwinder e6e09c587e Fix 3 bugs (swing NaN, ROC div-by-zero, currency matching) and add 77 new tests
Bug fixes:
- Swing point detection: false positives when all neighbors are NaN (all([]) == True)
- ROC indicator: division by zero when historical close price is zero
- News currency extraction: substring matching ("usd" in "usda") replaced with word-boundary regex
- ADX DX calculation: use epsilon instead of NaN to avoid cascade
- Signal aggregator: refactor ternary append, add pip_value<=0 guard

New tests (77) cover: swing point edge cases, ROC/ADX/RSI/MACD/BB boundaries,
regime classification, composite scoring, quality grade thresholds, EUR filter
pipeline, trade setup edge cases, MTF agreement, weekend filter, and integration.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-05-18 17:25:52 -04:00
harwinder 08d7c9ade1 Optimize EUR/USD to 78.7% WR on 2-year M15 backtest
Three-layer optimization:

1. Entry filters (signal_aggregator.py section 6e):
   - Block ranging regime
   - Only A+/A/B quality grades
   - min_entry_score=38, min_entry_confidence=60
   - Block RSI > 70 for BUY, RSI < 30 for SELL

2. Trade setup (config.py EurUsdStrategyConfig):
   - RR=0.50 with uniform quality scale
   - SL floor 1.2 ATR, TP 1.0 ATR

3. Breakeven trail (backtest/gpu_backtest.py):
   - When MFE reaches 0.3R, move SL to entry + 0.05R buffer
   - Converts 4 of 14 losses to +0.05R small wins
   - Bar-by-bar simulation integrated into simulate_trades()

Results (EUR/USD M15, 2024-05-18 to 2026-05-18):
  47 trades | 78.7% WR | +1.81R | PF 1.18 | MaxDD 3.35R
XAU/USD unchanged: 77.8% WR on 30-day, 68.7% WR on 2-year.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-05-18 14:00:59 -04:00
harwinder 74b723ba06 Tune EUR/USD trade setup: quality-scaled TP and tighter SL
EUR/USD A-grade signals had inverted quality curve (-1.65R) because all
trades got RR≈0.50 and mature_move logic penalized high-score entries.

Fix: add per-pair trade setup params (sl_atr_floor=1.2, min_rr=1.0,
mature_move_threshold=35) and apply quality_scale to both tp_mult and
min_rr so A-grade gets wider TP targets. Also wire EUR config into
backtest via PAIR_PRODUCERS registry.

Result: A-grade now +1.24R (was -1.65R), total EUR/USD +10.06R (was +4.20R).
XAU/USD unchanged at +13.01R.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-05-18 12:56:34 -04:00
harwinder 3146a632d4 Add EUR/USD support with modular per-pair signal producer pattern
- Register EUR/USD in config (pip 0.0001, EurUsdStrategyConfig)
- Create pair_signals/ module: registry + dispatcher with per-pair
  config factories (xauusd.py, eurusd.py) for easy add/remove
- EUR/USD gets forex-tuned regime weights, London+NY session hours,
  XAU strategy gates disabled
- Add defense-in-depth display_name guards in signal_aggregator
- Rename telegram_bot.py → testing_telegram_bot.py with separate
  bot token, both pairs with dedicated button rows
- Add EUR/USD to news engine affected pairs map
- 9 new tests (146 total, all passing)
- Zero changes to engine.py, data_provider.py, main.py, backtest/

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-05-18 12:18:55 -04:00
harwinder b61818330b Fix weekend filter: use precise forex market hours (Fri 22:00–Sun 22:00 UTC)
The old `weekday() >= 5` check blocked all of Sunday, but the forex
market reopens Sunday 22:00 UTC (Sydney open). Now uses proper time-based
check so the bot fetches data and generates signals on Sunday evening.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-05-17 19:23:21 -04:00
harwinder 8ed6454ea5 Refocus on XAU/USD: add momentum indicators, tune TP, exhaustion block
Strip EUR/USD, GBP/USD, USD/JPY pairs and strategies from entire codebase.
Add 3 new scored indicators (ROC, Keltner/TTM Squeeze, ADX slope) and
enable MACD-as-pillar + divergence detection for early trend entry.
Introduce "transitioning" regime (ADX < 25, slope > 3.0) to catch trend
births before ADX confirms. Gold-specific composite weights per regime.

Tune TP multipliers: quality-tiered scaling (A+/A get 1.5-2.0x ATR via
XAU ATR method, B/C use swing-level targeting). Backtest: +24R total,
65% WR, PF 1.12 over 365 days.

Add momentum-confirmed exhaustion block: hard-reject trades when 2+
static exhaustion signals fire AND ROC/MACD confirm fading momentum.
Prevents late trend entries without killing strong trend trades.

Telegram: simplify buttons to timeframe-only labels, add "Scan All TFs"
multi-timeframe summary, add /scan command, fix BB/KC level breach keys,
fix price formatting (.2f for gold), fix deprecated asyncio call, fix
"1 pairs" grammar and 60s/30s dashboard refresh mismatch.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-05-15 10:51:51 -04:00
harwinder 98daf71a52 Add web dashboard (Redis + FastAPI + WebSocket), scope XAU penalties
Signal daemon (signal_web.py): candle-boundary scanner mirroring
telegram_bot.py, publishes serialized SignalReport JSON to Redis.
Web API (web/app.py): thin FastAPI reader behind Apache, serves
/api/signals REST + /ws WebSocket from Redis pub/sub.
Frontend (web/static/index.html): 3-pair grid, color-coded signals,
indicator breakdown per timeframe, trade setup display.

Also: XAU-specific penalty scoping in signal_aggregator (softer
confidence penalties for gold, original strict values for forex),
pair-aware session filter routing XAU to its own blocked hours.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-05-14 23:15:37 -04:00
harwinder bf9609708c Fix duplicate-index crash in data validation, add Telegram flood control
- Move index dedup before OHLC consistency fix in _validate_and_clean
  to prevent crash when df.loc[dup_idx] returns Series instead of scalar
- Add global flood backoff: detect RetryAfter, pause all sends/edits
  until ban expires instead of retrying and escalating the ban
- Stop dashboard edit-fail → new-message spam cascade: track consecutive
  failures, only resend after 3 failed edits
- Increase dashboard refresh from 5s to 30s, min send interval to 1.5s
- Add comprehensive QA test suite (140 tests across all 7 modules)

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-05-14 13:04:28 -04:00