feat: implement AI-driven DCA (Dollar Cost Averaging) system

AI-powered DCA manager with sophisticated reversal detection
 Multi-factor analysis: price movements, RSI, support/resistance, 24h trends
 Real example: SOL position analysis shows 5.2:1 risk/reward improvement

 lib/ai-dca-manager.ts - Complete DCA analysis engine with risk management
 Intelligent scaling: adds to positions when AI detects 50%+ reversal confidence
 Account-aware: uses up to 50% available balance with conservative 3x leverage
 Dynamic SL/TP: adjusts stop loss and take profit for new average position

 lib/automation-service-simple.ts - DCA monitoring in main trading cycle
 prisma/schema.prisma - DCARecord model for comprehensive tracking
 Checks DCA opportunities before new trade analysis (priority system)

 test-ai-dca-simple.js - Real SOL position test from screenshot data
 Entry: 85.98, Current: 83.87 (-1.13% underwater)
 AI recommendation: 1.08 SOL DCA → 4.91 profit potential
 Risk level: LOW with 407% liquidation safety margin

 LOGIC
 Price movement analysis: 1-10% against position optimal for DCA
 Market sentiment: 24h trends must align with DCA direction
 Technical indicators: RSI oversold (<35) for longs, overbought (>65) for shorts
 Support/resistance: proximity to key levels increases confidence
 Risk management: respects leverage limits and liquidation distances

 Complete error handling and fallback mechanisms
 Database persistence for DCA tracking and performance analysis
 Seamless integration with existing AI leverage calculator
 Real-time market data integration for accurate decision making
This commit is contained in:
mindesbunister
2025-07-24 12:42:56 +02:00
parent 221baf3baa
commit 29d0516a07
8 changed files with 1674 additions and 7 deletions

View File

@@ -15,11 +15,35 @@ This is a Next.js 15 App Router application with TypeScript, Tailwind CSS, and A
- TradingView automation with session persistence in `lib/tradingview-automation.ts`
- Session data stored in `.tradingview-session/` volume mount to avoid captchas
### AI Analysis Pipeline
- OpenAI GPT-4o mini for cost-effective chart analysis (~$0.006 per analysis)
- Multi-layout comparison and consensus detection in `lib/ai-analysis.ts`
- Professional trading setups with exact entry/exit levels and risk management
- Layout-specific indicator analysis (RSI vs Stochastic RSI, MACD vs OBV)
### AI-Driven Dynamic Leverage System ✅
**Complete AI leverage calculator with intelligent position sizing:**
- `lib/ai-leverage-calculator.ts` - Core AI leverage calculation engine with risk management
- Account-based strategies: <$1k uses 100% balance (aggressive), >$1k uses 50% balance (conservative)
- Safety mechanisms: 10% buffer between liquidation price and stop loss
- Platform integration: Drift Protocol with maximum 20x leverage constraints
- **Integration**: Enhanced `lib/automation-service-simple.ts` uses AI-calculated leverage for all positions
### AI-Driven DCA (Dollar Cost Averaging) System ✅
**Revolutionary position scaling that maximizes profits while managing risk:**
- `lib/ai-dca-manager.ts` - AI-powered DCA analysis engine with reversal detection
- **Multi-factor Analysis**: Price movements, 24h trends, RSI levels, support/resistance
- **Smart Scaling**: Adds to positions when AI detects reversal potential (50%+ confidence threshold)
- **Risk Management**: Respects leverage limits, adjusts stop loss/take profit for new average price
- **Account Integration**: Uses available balance strategically (up to 50% for DCA operations)
- **Real Example**: SOL position at $185.98 entry, $183.87 current → AI recommends 1.08 SOL DCA for 5.2:1 R/R improvement
**DCA Decision Factors:**
- Price movement against position (1-10% optimal range)
- 24h market sentiment alignment with DCA direction
- Technical indicators (RSI oversold/overbought zones)
- Proximity to support/resistance levels
- Available balance and current leverage headroom
- Liquidation distance and safety buffers
**Integration Points:**
- `lib/automation-service-simple.ts` - Automated DCA monitoring in main trading cycle
- `prisma/schema.prisma` - DCARecord model for tracking all scaling operations
- Database tracking of DCA count, total amount, and performance metrics
### Trading Integration
- **Drift Protocol**: Perpetual futures trading via `@drift-labs/sdk`