CRITICAL FIX: Convert AI absolute prices to percentages for stop loss/take profit

system was treating them as percentages (530.13%), causing ridiculous targets

 SOLUTION:
- calculateStopLoss(): Convert AI absolute stopLoss.price to percentage
- calculateTakeProfit(): Convert AI absolute takeProfits.tp1.price to percentage
- Proper calculation: ((targetPrice - currentPrice) / currentPrice) * 100

- Before: SOL @85 → TP: 530.13% = ,152 🤯
- After:  SOL @85 → TP: 2.8% = 90 

This ensures scalping trades have realistic targets instead of 500%+ gains.
This commit is contained in:
mindesbunister
2025-07-24 11:35:57 +02:00
parent 04e1610806
commit 1cbed61a46
2 changed files with 22 additions and 38 deletions

View File

@@ -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