Ringkasan
Dokumen ini merancang integrasi antara subsistem MarketLens (analisis teknikal komprehensif) dengan Optimal Entry Screener (implementasi sistem momentum Adam Khoo).
Tujuan utama adalah menciptakan single source of truth untuk indikator teknikal dengan membuat subsistem baru yang mandiri tanpa mengganggu MarketLens yang sudah online.
Latar Belakang
Arsitektur Saat Ini
- Duplikasi Kode: optimal_entry_screener.php memiliki implementasi sendiri untuk SMA, EMA, RS calculation
- Inkonsistensi Potensial: Dua implementasi berbeda untuk indikator yang sama
- Maintenance Overhead: Perubahan pada indikator harus dilakukan di dua tempat
Arsitektur Target (Isolated Subsystem)
- Zero Risk: MarketLens existing tidak tersentuh sama sekali
- Isolated Development: Subsistem baru bisa dikembangkan dan ditest secara independen
- Shared Database: Menggunakan tabel yang sama (stock_summary, optimal_entry_signals)
- Single Source of Truth: Indikator terpusat di MomentumAnalysis.php
- Easy Rollback: Jika ada masalah, tinggal hapus file baru
- Gradual Migration: Bisa migrasi bertahap dari optimal_entry_screener.php
Prinsip Desain
Pendekatan ini mengikuti prinsip:
- Tidak mengubah file existing MarketLens (TechnicalAnalysis.php, TechnicalAnalysis_helper.php, dll)
- Membuat folder baru MarketLens_v2/ untuk subsistem momentum
- Menggunakan database tables yang sama untuk konsistensi data
- API endpoint baru yang bisa berjalan parallel dengan yang lama
- Frontend baru yang independen dari MarketLens existing
Subsistem lama (optimal_entry_screener.php) tetap berfungsi normal. Setelah subsistem baru terbukti stabil, bisa dilakukan migrasi bertahap atau redirect.
Proposed Changes
Struktur File Baru (Isolated Subsystem)
autoportofolio/ ├── MarketLens/ # TIDAK DIUBAH - Existing subsystem │ ├── TechnicalAnalysis.php │ ├── config.php │ └── ... │ ├── MarketLens_v2/ # BARU - Momentum subsystem │ ├── MomentumAnalysis.php # Core engine untuk momentum analysis │ ├── MomentumAnalysis_helper.php # Helper functions untuk pattern detection │ └── config.php # Config khusus momentum │ ├── public/ │ ├── api/ │ │ ├── optimal_entry_screener.php # TIDAK DIUBAH - Old API │ │ └── momentum_screener_v2.php # BARU - New API endpoint │ │ │ └── tools/ │ ├── optimal_entry_screener.php # TIDAK DIUBAH - Old frontend │ ├── momentum_screener_v2.php # BARU - New frontend │ └── js/ │ ├── optimal_entry_screener.js # TIDAK DIUBAH │ └── momentum_screener_v2.js # BARU - New frontend JS │ ├── cron_jobs/ │ ├── cron_optimal_entry_detector.php # TIDAK DIUBAH - Old cron │ ├── cron_momentum_detector_v2.php # BARU - New cron detector │ └── cron_momentum_outcome_tracker_v2.php # BARU - New cron tracker │ └── config/ └── optimal_entry.php # TIDAK DIUBAH - Shared config
Fase Implementasi
NEW Fase 1: Core Engine - MomentumAnalysis.php
Purpose: Core class untuk analisis momentum trading dengan indikator Adam Khoo
Key Features:
- Single source of truth untuk semua indikator momentum
- Menggunakan database stock_summary yang sama dengan MarketLens
- Independen dari TechnicalAnalysis.php (tidak ada dependency)
- Optimized untuk momentum pattern detection
NEW Fase 2: Helper Functions
File: MomentumAnalysis_helper.php
Functions: Moving averages, pattern detection, candlestick patterns, support/resistance, volatility analysis, volume analysis, risk/reward calculations
NEW Fase 3: API Endpoint
File: momentum_screener_v2.php
Modes:
- Auto Screener - Scan semua saham yang lolos prerequisites
- Single Stock - Analisis detail untuk satu saham
- Historical Signals - Query historical patterns dari database
NEW Fase 4: Frontend Interface
Features: Modern UI dengan Bootstrap 5, real-time data refresh, interactive candlestick charts, pattern visualization, historical performance tracking
NEW Fase 5: Cron Jobs
Files:
- cron_momentum_detector_v2.php - Daily pattern detection (18:00)
- cron_momentum_outcome_tracker_v2.php - Track outcomes (19:00)
Verification Plan
Automated Tests
Unit Tests
Test helper functions: SMA/EMA, pattern detection, swing detection
Integration Tests
Test MomentumAnalysis class: MA calculations, RS ranking, pattern detection
Parallel Testing
Compare old vs new: MA values, RS scores, pattern detection
Success Criteria
- All automated tests pass
- New subsystem works independently
- Old subsystem still functions normally
- No interference between old and new
- Shared database tables work correctly
- Documentation complete
Migration Strategy
Phase 1: Development & Testing (Week 1-2)
- Develop MarketLens_v2/ subsystem
- Create new API endpoint
- Build new frontend
- Write automated tests
- Verify functionality
Phase 2: Parallel Running (Week 3-4)
- Deploy new subsystem to production
- Run both old and new cron jobs
- Monitor for issues
- Compare results
- Gather user feedback
Phase 3: Gradual Migration (Week 5-6)
- Add redirect option in old frontend to new frontend
- Update documentation to recommend new subsystem
- Monitor adoption
Phase 4: Deprecation (Optional, Month 3+)
- If new subsystem proven stable
- Deprecate old subsystem
- Keep old files for reference
- Update all links to point to new subsystem
Timeline Estimasi
| Fase | Durasi | Deliverables |
|---|---|---|
| Fase 1: Core Engine | 3-4 hari | MomentumAnalysis.php |
| Fase 2: Helper Functions | 2-3 hari | MomentumAnalysis_helper.php |
| Fase 3: API Endpoint | 2 hari | momentum_screener_v2.php (API) |
| Fase 4: Frontend | 3-4 hari | Frontend interface + JS |
| Fase 5: Cron Jobs | 2 hari | Detector + Tracker crons |
| Testing & Documentation | 3-4 hari | Test suite + docs |
| TOTAL | 15-19 hari kerja | Complete subsystem |
Rollback Plan
- Hapus file baru - Tidak ada impact ke existing system
- Stop new cron jobs - Old cron masih berjalan
- Revert database (jika ada corruption) - Restore dari backup
- No downtime - Old system tidak terpengaruh sama sekali
Keuntungan Pendekatan Isolated Subsystem
Zero Risk
MarketLens existing tidak tersentuh
Independent Development
Bisa develop dan test tanpa worry
Easy Rollback
Tinggal hapus file baru
Parallel Running
Bisa compare old vs new
Gradual Migration
User bisa pilih mana yang dipakai
Future Proof
Template untuk subsystem lain