feat(core): SMF Cloud — adaptive trailing stop, 12 strategy cells, indicators - #10
Merged
Merged
Conversation
…erformance eviction - Replace atr_multiplier with pct across all 13 strategy templates (scalping, intraday, swing) — exits now deterministic without ATR dependency - Add max_per_symbol to RiskManager: prevents one symbol from hogging all slots - Add cell performance eviction: when max_positions is reached, cells with higher win rate can evict the worst-performing cell's position - Add per_cell_stats() to TradeTracker for per-cell win rate queries - Handle eviction in EventEngine: closes evicted position before opening new one - Pass trade_tracker to RiskManager in main.py to enable performance ranking
…cy tracking - Add reentry_cooldown to prevent rapid flip-flop after STOP-LOSS exit - Add min_signal_interval to throttle rapid-fire signals from same cell - Add min_signal_move_pct to skip signals when market barely moved - Add efficiency counters (signals generated/approved/rejected) + log_efficiency() - Wire record_approval/record_rejection into EventEngine pipeline - Add side param to support_resistance condition (support/resistance/both) - Fix touch_count to filter clustered levels instead of raw pivots - Add missing STOP-LOSS and TAKE-PROFIT entries to all strategy templates - Add exit_pct_scale, min_signal_interval, min_signal_move_pct to intraday template - Update MockCell with efficiency tracking methods
…ent-driven + batch Add configurable notification system combining all five approaches: - Levels (silent|normal|verbose|debug): control verbosity per user preference - Event-driven: entries and exits sent immediately (no waiting for batch) - Threshold gating: periodic summary only if equity changed > X% or events occurred - Batch summaries: rejects accumulate and flush at summary_interval - Entry/exit messages formatted concisely with PnL and capital Config parameters: - telegram_level: silent|normal|verbose|debug (default: normal) - telegram_equity_threshold: min %% equity change for summary (default: 1.0) - telegram_summary_interval: minutes between summaries (default: 15) Legacy batch builder, _fmt_single, _fmt_rejected, _fmt_close preserved for backward compatibility. 32 telegram tests passing.
…fitting detection, survivorship check - Added compute_benchmark() — compares strategy vs BTC buy-and-hold (alpha, beta, outperformance) - Added detect_overfitting() — Monte Carlo shuffle of trade PnLs, flags if Sharpe < 95th percentile - Added check_survivorship_bias() — warns if backtest data predates Binance listing date - Added bars_per_year() — 14 timeframe->calendar mapping for crypto 24/7 markets - Added run_with_benchmark() — enhanced BacktestResult with benchmark + overfitting + survivorship fields - Created scripts/run_backtest.py — CLI: --symbol --strategy --timeframe --days, downloads Binance OHLCV, runs full backtest, Rich report, saves JSON - Lazy numpy/pandas imports throughout to avoid Termux broken C extensions - 54 tests collected (12 pass, 31 numpy-skip, 5 pre-existing PaperBroker failures unchanged) - Crypto-only: BTC benchmark, 24/7 calendar bars, Binance listing dates
…Rate limiting, OrderManager, KillSwitch
Four-phase production readiness upgrade:
Phase 1 — Backtesting profesional (previous commit)
benchmark, overfitting, survivorship, CLI runner
Phase 4 — Rate limiting + Fee modeling
- PaperBroker: commission_pct (0.1%) + slippage_pct (0.05%) on fill
- BinanceBroker: weight-based rate limiting (x-mbx-used-weight-1m, 80%→backoff)
- BinanceFeed: exponential backoff reconnect (1s→60s, 5 max retries)
- Engine: fill_price for trade events, effective_price for portfolio cost basis
Phase 3 — Reconciliation + Kill switch
- OrderManager: 7-state machine (CREATED→PENDING_SUBMIT→SUBMITTED→FILLED|CANCELLED|REJECTED|EXPIRED)
with partial fill accumulation, orphan detection, reconcile()
- KillSwitch: manual/auto trigger, cancel_all_orders + close_all_positions,
auto-trigger at configurable drawdown threshold, engine gate
- 33 state machine + kill switch tests
Phase 2 — Binance real broker wiring
- OrderManager wired into both brokers (PaperBroker + BinanceBroker)
- KillSwitch wired into EventEngine + main.py startup
- client_order_id (symbol+timestamp+nonce) for all outgoing orders
- Reconcile on startup for Binance live mode
- Config: kill_switch_drawdown field (default 0.30)
- 12 integration wiring tests
Total: 232 passed, 2 skipped — no regressions
…ort) Binance deprecated HMAC for new API keys. Migrated from python-binance to the official binance-connector SDK which supports Ed25519 signing. - Swap imports: binance.client.Client → binance.spot.Spot - Constructor accepts private_key (PEM) for Ed25519 or api_secret for backward-compatible HMAC - new_order() instead of create_order(), account() instead of get_asset_balance() - Rate limiting: conservative 10 req/s timestamp window (binance-connector doesn't expose response headers like python-binance did) - .env + .env.example updated with BINANCE_PRIVATE_KEY - Verified: API key fW0No1... connects to Binance mainnet, balance OK - Config stays on paper mode until user deposits funds
…egy cells Implement Smart Money Flow Cloud (BOSWaves) volume-flow-aware trend detection with: - 5 new indicators: smf_flow, smf_strength, smf_basis, smf_upper, smf_lower - adaptive_mult() utility for dynamic band width and trailing stops - Per-cycle cache for SMF computation (avoids 15x recomputation) - Adaptive trailing in _check_exit() with min_mult/max_mult - _PARAM_RANGES for SMF params in optimizer + shared-param linking - 12 replacement strategy cells across 15m, 1h, 1d timeframes - 57 new tests (34 unit + 23 integration), 0 regressions - Updated README with current architecture (CellMesh, Binance)
Six new indicator functions registered in _INDICATORS: - _compute_smf() — single-pass SMF Cloud pipeline (CLV->Flow->Strength->Bands) - smf_upper / smf_lower / smf_basis / smf_flow / smf_strength — wrapper functions - adaptive_mult() — maps flow strength to ATR multiplier Full test suite in test_smf_indicators.py covers: - Sufficient/insufficient data paths - Edge cases: zero volume, NaN strength, clamped ranges - Compound operators (price > smf_basis) - Caching and thread safety
12 new YAML-based SMF Cloud cells (4 per timeframe: scalping, intraday, swing): - SMF Flow Continuation / Reversal / Strength / Breakout variants - Each with entry/exit conditions, trailing stop, and risk params Adaptive trailing stop: - Expands ATR multiplier when SMF strength is high (trending) - Contracts when strength is low (choppy, tighter exit) - Configurable via min_atr_mult / max_atr_mult Integration tests covering full cell lifecycle
3 tasks done
# Conflicts: # tests/test_smf_indicators.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Chain Context
Chain Overview
This PR is a DRAFT tracker. Do not merge. Merge only after all child PRs are reviewed and integrated.