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:
@@ -736,64 +736,48 @@ ${validResults.map(r => `• ${r.timeframe}: ${r.analysis?.recommendation} (${r.
|
|||||||
private calculateStopLoss(analysis: any): number {
|
private calculateStopLoss(analysis: any): number {
|
||||||
// ✅ AI-FIRST: Use AI analysis stopLoss if available
|
// ✅ AI-FIRST: Use AI analysis stopLoss if available
|
||||||
if (analysis.stopLoss?.price) {
|
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 AI provides explicit stop loss percentage, use it
|
||||||
if (analysis.stopLossPercent) {
|
if (analysis.stopLossPercent) {
|
||||||
const currentPrice = analysis.entry?.price || 189
|
return analysis.stopLossPercent
|
||||||
const stopLossPercent = analysis.stopLossPercent / 100
|
|
||||||
|
|
||||||
if (analysis.recommendation === 'BUY') {
|
|
||||||
return currentPrice * (1 - stopLossPercent)
|
|
||||||
} else if (analysis.recommendation === 'SELL') {
|
|
||||||
return currentPrice * (1 + stopLossPercent)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Fallback: Dynamic stop loss based on market volatility (AI-calculated)
|
// 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)
|
// AI determines volatility-based stop loss (0.5% to 2% range)
|
||||||
const aiStopLossPercent = this.calculateAIStopLoss(analysis) / 100
|
return this.calculateAIStopLoss(analysis)
|
||||||
|
|
||||||
if (analysis.recommendation === 'BUY') {
|
|
||||||
return currentPrice * (1 - aiStopLossPercent)
|
|
||||||
} else if (analysis.recommendation === 'SELL') {
|
|
||||||
return currentPrice * (1 + aiStopLossPercent)
|
|
||||||
} else {
|
|
||||||
return currentPrice * (1 - aiStopLossPercent)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private calculateTakeProfit(analysis: any): number {
|
private calculateTakeProfit(analysis: any): number {
|
||||||
// ✅ AI-FIRST: Use AI analysis takeProfit if available
|
// ✅ AI-FIRST: Use AI analysis takeProfit if available
|
||||||
if (analysis.takeProfits?.tp1?.price) {
|
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 AI provides explicit take profit percentage, use it
|
||||||
if (analysis.takeProfitPercent) {
|
if (analysis.takeProfitPercent) {
|
||||||
const currentPrice = analysis.entry?.price || 150
|
return analysis.takeProfitPercent
|
||||||
const takeProfitPercent = analysis.takeProfitPercent / 100
|
|
||||||
|
|
||||||
if (analysis.recommendation === 'BUY') {
|
|
||||||
return currentPrice * (1 + takeProfitPercent)
|
|
||||||
} else if (analysis.recommendation === 'SELL') {
|
|
||||||
return currentPrice * (1 - takeProfitPercent)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Fallback: Dynamic take profit based on AI risk/reward optimization
|
// Fallback: Dynamic take profit based on AI risk/reward optimization
|
||||||
const currentPrice = analysis.entry?.price || 150
|
return this.calculateAITakeProfit(analysis)
|
||||||
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)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// AI-calculated dynamic stop loss based on volatility and market conditions
|
// AI-calculated dynamic stop loss based on volatility and market conditions
|
||||||
|
|||||||
Binary file not shown.
Reference in New Issue
Block a user