diff --git a/lib/automation-service-simple.ts b/lib/automation-service-simple.ts index a6bc305..7c46269 100644 --- a/lib/automation-service-simple.ts +++ b/lib/automation-service-simple.ts @@ -736,64 +736,48 @@ ${validResults.map(r => `• ${r.timeframe}: ${r.analysis?.recommendation} (${r. private calculateStopLoss(analysis: any): number { // ✅ AI-FIRST: Use AI analysis stopLoss if available if (analysis.stopLoss?.price) { - return analysis.stopLoss.price + const currentPrice = analysis.entry?.price || 189 + const stopLossPrice = analysis.stopLoss.price + + // Convert absolute price to percentage + if (analysis.recommendation === 'BUY') { + return ((currentPrice - stopLossPrice) / currentPrice) * 100 + } else if (analysis.recommendation === 'SELL') { + return ((stopLossPrice - currentPrice) / currentPrice) * 100 + } } // If AI provides explicit stop loss percentage, use it if (analysis.stopLossPercent) { - const currentPrice = analysis.entry?.price || 189 - const stopLossPercent = analysis.stopLossPercent / 100 - - if (analysis.recommendation === 'BUY') { - return currentPrice * (1 - stopLossPercent) - } else if (analysis.recommendation === 'SELL') { - return currentPrice * (1 + stopLossPercent) - } + return analysis.stopLossPercent } // Fallback: Dynamic stop loss based on market volatility (AI-calculated) - const currentPrice = analysis.entry?.price || 189 // AI determines volatility-based stop loss (0.5% to 2% range) - const aiStopLossPercent = this.calculateAIStopLoss(analysis) / 100 - - if (analysis.recommendation === 'BUY') { - return currentPrice * (1 - aiStopLossPercent) - } else if (analysis.recommendation === 'SELL') { - return currentPrice * (1 + aiStopLossPercent) - } else { - return currentPrice * (1 - aiStopLossPercent) - } + return this.calculateAIStopLoss(analysis) } private calculateTakeProfit(analysis: any): number { // ✅ AI-FIRST: Use AI analysis takeProfit if available if (analysis.takeProfits?.tp1?.price) { - return analysis.takeProfits.tp1.price + const currentPrice = analysis.entry?.price || 150 + const takeProfitPrice = analysis.takeProfits.tp1.price + + // Convert absolute price to percentage + if (analysis.recommendation === 'BUY') { + return ((takeProfitPrice - currentPrice) / currentPrice) * 100 + } else if (analysis.recommendation === 'SELL') { + return ((currentPrice - takeProfitPrice) / currentPrice) * 100 + } } // If AI provides explicit take profit percentage, use it if (analysis.takeProfitPercent) { - const currentPrice = analysis.entry?.price || 150 - const takeProfitPercent = analysis.takeProfitPercent / 100 - - if (analysis.recommendation === 'BUY') { - return currentPrice * (1 + takeProfitPercent) - } else if (analysis.recommendation === 'SELL') { - return currentPrice * (1 - takeProfitPercent) - } + return analysis.takeProfitPercent } // Fallback: Dynamic take profit based on AI risk/reward optimization - const currentPrice = analysis.entry?.price || 150 - const aiTakeProfitPercent = this.calculateAITakeProfit(analysis) / 100 - - if (analysis.recommendation === 'BUY') { - return currentPrice * (1 + aiTakeProfitPercent) - } else if (analysis.recommendation === 'SELL') { - return currentPrice * (1 - aiTakeProfitPercent) - } else { - return currentPrice * (1 + aiTakeProfitPercent) - } + return this.calculateAITakeProfit(analysis) } // AI-calculated dynamic stop loss based on volatility and market conditions diff --git a/prisma/prisma/dev.db b/prisma/prisma/dev.db index b3738bc..aa077a5 100644 Binary files a/prisma/prisma/dev.db and b/prisma/prisma/dev.db differ