17 Commits

Author SHA1 Message Date
mindesbunister
186101920a feat: Add v11 indicator filter to optimization analytics page 2025-12-15 11:39:36 +01:00
copilot-swe-agent[bot]
4f913a7ab8 feat: Add indicator version filtering to analytics dashboard
- Add version dropdown selector (v9, v8, v6, v5, all) to frontend
- Update backend API to accept ?version= query parameter
- Add version filter to all 5 broken SQL queries using Prisma parameterized queries
- Update Data Collection Status to use selected version instead of hardcoded v8
- Add version context to all recommendations
- Add URL encoding for version parameter (security best practice)
- Validate version parameter against whitelist (SQL injection protection)

Co-authored-by: mindesbunister <32161838+mindesbunister@users.noreply.github.com>
2025-12-05 14:01:41 +00:00
mindesbunister
9d7932ff2f feat: Add distinction between regular SL and trailing SL
User Request: Distinguish between SL and Trailing SL in analytics overview

Changes:
1. Position Manager:
   - Updated ExitResult interface to include 'TRAILING_SL' exit reason
   - Modified trailing stop exit (line 1457) to use 'TRAILING_SL' instead of 'SL'
   - Enhanced external closure detection (line 937) to identify trailing stops
   - Updated handleManualClosure to detect trailing SL at price target

2. Database:
   - Updated UpdateTradeExitParams interface to accept 'TRAILING_SL'

3. Frontend Analytics:
   - Updated last trade display to show 'Trailing SL' with special formatting
   - Purple background/border for TRAILING_SL vs blue for regular SL
   - Runner emoji (🏃) prefix for trailing stops

Impact:
- Users can now see when trades exit via trailing stop vs regular SL
- Better understanding of runner system performance
- Trailing stops visually distinct in analytics dashboard

Files Modified:
- lib/trading/position-manager.ts (4 locations)
- lib/database/trades.ts (UpdateTradeExitParams interface)
- app/analytics/page.tsx (exit reason display)
- .github/copilot-instructions.md (Common Pitfalls #61, #62)
2025-11-24 08:40:09 +01:00
mindesbunister
1e64e8145b fix: Correct SQL column names and add navigation links
- Fixed tp1Hit/tp2Hit -> tp1Filled/tp2Filled in Runner Performance query
- Fixed atr -> atrAtEntry in ATR vs MFE Correlation and Data Collection queries
- Added Analytics card to homepage with link to /analytics/optimization
- Added Home button to optimization page header
- All 7 analyses now working without SQL errors
2025-11-23 20:28:33 +01:00
mindesbunister
11ae0938ba feat: Add comprehensive optimization analytics dashboard
- Created /api/optimization/analyze endpoint with 7 SQL analyses
- Replaced old TP/SL page with comprehensive dashboard
- Analyses: Quality Score Distribution, Direction Performance, Blocked Signals, Runner Performance, ATR vs MFE, Indicator Versions, Data Collection Status
- Real-time refresh capability
- Actionable recommendations based on data thresholds
- Roadmap links at bottom
- Addresses user request for automated SQL analysis dashboard
2025-11-23 20:07:24 +01:00
mindesbunister
bba91c1df8 feat: Archive old indicator versions, focus on v8 production system
Version Management:
- v8 Money Line: PRODUCTION (8 trades, 57.1% WR, +$262.70, quality ≥95 = 100% wins)
- v5/v6/v7: ARCHIVED (historical baseline for future v9 comparison)

API Changes (app/api/analytics/version-comparison/route.ts):
- Added 'archived' flag to version stats
- Added 'production' field pointing to v8
- Updated sort order: v8 first, then archived versions
- Enhanced descriptions with PRODUCTION/ARCHIVED labels

UI Changes (app/analytics/page.tsx):
- v8 highlighted with blue gradient + 🚀 PRODUCTION badge
- Archived versions greyed out (60% opacity) + ARCHIVED badge
- Updated header: 'Indicator Versions (v8 Production)'
- Data collection notice: v8 shows 8/50 trades progress
- Kept comparison infrastructure for future v9 development

Documentation (.github/copilot-instructions.md):
- Updated Indicator Version Tracking section
- Documented perfect quality separation (≥95 = 100% wins)
- Clarified v8 production status, archived versions purpose
- Analytics UI behavior documented

Purpose: Keep comparison infrastructure for statistical validation
and future v9 testing while focusing user attention on v8 results.
2025-11-22 14:45:48 +01:00
mindesbunister
01427ce3eb fix: Display MAE/MFE as dollars not percentages in analytics UI
- Changed 'Avg MFE: +X.XX%' to 'Avg MFE: +$X.XX'
- Changed 'Avg MAE: -X.XX%' to 'Avg MAE: -$X.XX'
- Database already stores dollar values (fixed Nov 19)
- UI was incorrectly displaying dollars with % suffix
- V8 trades: Avg MFE $34.23, Avg MAE -$11.06 (correct)
- Part of MAE/MFE data corruption fix series

Also corrected existing v8 trade in database:
- Before: MFE 19.73% (account %), MAE -1.53% (account %)
- After: MFE $95.11, MAE -$7.39 (actual dollars)
- SQL: UPDATE based on maxFavorablePrice/maxAdversePrice
2025-11-19 07:57:17 +01:00
mindesbunister
be36d6aa86 feat: Add live position monitor to analytics dashboard
FEATURE: Real-time position monitoring with auto-refresh every 3 seconds

Implementation:
- New LivePosition interface for real-time trade data
- Auto-refresh hook fetches from /api/trading/positions every 3s
- Displays when Position Manager has active trades
- Shows: P&L (realized + unrealized), current price, TP/SL status, position age

Live Display Includes:
- Header: Symbol, direction (LONG/SHORT), leverage, age, price checks
- Real-time P&L: Profit %, account P&L %, color-coded green/red
- Price Info: Entry, current, position size (with % after TP1), total P&L
- Exit Targets: TP1 (✓ when hit), TP2/Runner, SL (@ B/E when moved)
- P&L Breakdown: Realized, unrealized, peak P&L

Technical:
- Added NEXT_PUBLIC_API_SECRET_KEY to .env for frontend auth
- Positions endpoint requires Bearer token authorization
- Updates every 3s via useEffect interval
- Only shows when monitoring.isActive && positions.length > 0

User Experience:
- Live pulsing green dot indicator
- Auto-updates without page refresh
- Position size shows % remaining after TP1 hit
- SL shows '@ B/E' badge when moved to breakeven
- Color-coded P&L (green profit, red loss)

Files:
- app/analytics/page.tsx: Live position monitor section + auto-refresh
- .env: Added NEXT_PUBLIC_API_SECRET_KEY

User Request: 'i would like to see a live status on the analytics page about an open position'
2025-11-15 18:29:33 +01:00
mindesbunister
2cda751dc4 fix: update analytics UI to show TradingView indicator versions correctly
- Changed section title: 'Signal Quality Logic Versions' → 'TradingView Indicator Versions'
- Updated current version marker: v3 → v6
- Added version sorting: v6 first, then v5, then unknown
- Updated description to reflect indicator strategy comparison

Context:
- User clarified: V4 display = v6 data, V1 display = v5 data
- Dashboard now shows indicator versions in proper order
- 154 unknown (pre-tracking), 15 v6 (HalfTrend), 4 v5 (Buy/Sell)
2025-11-14 13:15:30 +01:00
mindesbunister
ebe5e1ab5f feat: Add Dynamic ATR Analysis UI to TP/SL Optimization page
- Added dynamicATRAnalysis interface to page component
- New section displays after Current Configuration Performance
- Progress bar shows data collection: 14/30 trades (46.7%)
- Side-by-side comparison: Fixed vs Dynamic ATR targets
- Highlights advantage: +.72 (+39.8%) with current sample
- Color-coded recommendation: Yellow (WAIT) → Green (IMPLEMENT)
- Shows avg ATR (0.32%), dynamic TP2 (0.64%), dynamic SL (0.48%)
- Auto-updates as more v6 trades are collected
- Responsive design with gradient backgrounds

Enables user to track progress toward 30-trade threshold for implementation decision
2025-11-14 09:09:08 +01:00
mindesbunister
711ff9aaf4 Add signal quality version comparison to analytics dashboard
- Created /api/analytics/version-comparison endpoint
- Shows performance metrics for v1, v2, v3 scoring logic
- Compares: trade count, win rate, P&L, quality scores, MFE/MAE
- Special focus on extreme positions (< 15% or > 85% range)
- Tracks weak ADX count (< 18) for each version
- Visual indicators for current version (v3)
- Data collection progress notice for v3 (need 20+ trades)
- Legend explaining MFE, MAE, extreme positions, weak ADX

Enables data-driven optimization by comparing algorithm performance
with clean, version-tagged datasets.
2025-11-07 13:05:48 +01:00
mindesbunister
056440bf8f feat: add quality score display and timezone fixes
- Add qualityScore to ExecuteTradeResponse interface and response object
- Update analytics page to always show Signal Quality card (N/A if unavailable)
- Fix n8n workflow to pass context metrics and qualityScore to execute endpoint
- Fix timezone in Telegram notifications (Europe/Berlin)
- Fix symbol normalization in /api/trading/close endpoint
- Update Drift ETH-PERP minimum order size (0.002 ETH not 0.01)
- Add transaction confirmation to closePosition() to prevent phantom closes
- Add 30-second grace period for new trades in Position Manager
- Fix execution order: database save before Position Manager.addTrade()
- Update copilot instructions with transaction confirmation pattern
2025-11-01 17:00:37 +01:00
mindesbunister
49a09ef04e Add 'Clear Manual Closes' button to analytics
- New button in analytics page to clear orphaned trades
- API endpoint /api/trading/clear-manual-closes
- Intelligently checks Drift positions before deleting
- Only removes trades with no matching position or mismatched entry price
- Safe operation: keeps trades on error (false positives better than deletions)
- User-friendly confirmation dialog
2025-11-01 02:41:26 +01:00
mindesbunister
3c79ecbe55 Display signal quality score on analytics dashboard
- Add signalQualityScore to LastTrade interface
- Display quality score badge in last trade section (0-100)
- Color-coded: green (80+), yellow (70-79), orange (60-69)
- Shows 'Excellent', 'Good', or 'Marginal' label
- Gracefully handles null values (old trades without scores)
- Better layout when quality score is present
2025-10-31 11:34:46 +01:00
mindesbunister
aecdc108f6 Add last trade details to analytics dashboard
- Add getLastTrade() function to database service
- Create /api/analytics/last-trade endpoint
- Display last trade with full details on analytics page
- Show entry/exit prices, P&L, position size, targets
- Visual indicators for trade direction and exit reason
- Helps quickly diagnose where trades went (TP1, TP2, or SL)
2025-10-31 10:47:19 +01:00
mindesbunister
6e87fc8749 Phase 4: TP/SL Optimization Visual Dashboard
- Created /analytics/optimization page with comprehensive UI
- Displays MAE/MFE analysis with percentiles
- Shows current TP/SL performance with hit rate bars
- Visualizes optimal recommendations vs current levels
- Projects impact of optimization (win rate, profit factor, P&L improvement)
- Provides reasoning for each recommended level
- Added navigation link from main analytics page

Dashboard features:
- Overview stats: total trades, win rate, profit factor, money left on table
- MAE analysis: avg, median, 25th/75th percentile, worst
- MFE analysis: avg, median, 25th/75th percentile, best
- Current config: TP1/TP2/SL hit rates with progress bars
- Recommendations: optimal levels with color-coded cards
- Reasoning cards: explanation for each recommendation
- Projected impact: win rate change, profit factor change, profit improvement
- Direct link to Settings page to apply recommendations

Access at: http://localhost:3001/analytics/optimization

Phase 1-4 Complete! System now tracks MAE/MFE, captures market context,
analyzes performance, and provides data-driven TP/SL recommendations.
2025-10-29 21:19:52 +01:00
mindesbunister
f571d459e4 Add landing page and analytics dashboard
- Created landing page at / with navigation to analytics and settings
- Built analytics dashboard at /analytics showing:
  - Current positions (net vs individual)
  - Trading statistics (win rate, P&L, profit factor)
  - Time period selector (7/30/90/365 days)
  - Position netting explanation
- Beautiful gradient UI matching settings page style
- Real-time data from database via API endpoints
- Auto-excludes test trades from statistics
- Shows net positions matching Drift UI behavior
2025-10-27 09:41:54 +01:00