Implement AI-powered optimal risk management system

Features:
- AI analyzes market conditions to suggest optimal SL/TP percentages
- Considers volatility, technical levels, timeframe, and risk/reward ratios
- Falls back to config defaults when AI optimization unavailable
- Enforces minimum safety constraints (3% SL, 1% TP)
- Enhanced status API with AI risk management info
- Comprehensive logging of decision sources

Benefits:
- Dynamic adaptation to market conditions
- Improved risk/reward optimization
- Reduced need for manual tuning
- Safety-first approach with fallbacks

Technical Implementation:
- Enhanced AnalysisResult interface with optimalRiskManagement
- Modified AI analysis prompt for risk management calculation
- Updated makeTradeDecision to use AI recommendations
- Enhanced executeLiveTrade with AI-optimized parameters
- Added lastAIRiskManagement tracking and status reporting
- Comprehensive documentation and examples
This commit is contained in:
mindesbunister
2025-07-23 15:39:41 +02:00
parent 0828647e80
commit ea89103ead
2 changed files with 214 additions and 0 deletions

View File

@@ -45,6 +45,15 @@ export interface AnalysisResult {
}
riskToReward?: string
confirmationTrigger?: string
// AI-optimized risk management
optimalRiskManagement?: {
stopLossPercent: number // AI-recommended stop loss percentage
takeProfitPercent: number // AI-recommended take profit percentage
riskRewardRatio: number // Expected risk/reward ratio
reasoning: string // Why these percentages are optimal
marketVolatility: 'LOW' | 'MEDIUM' | 'HIGH' // Current volatility assessment
timeHorizon: 'SCALP' | 'INTRADAY' | 'SWING' // Expected trade duration
}
indicatorAnalysis?: {
rsi?: string
vwap?: string
@@ -217,6 +226,14 @@ Before analyzing, understand these core indicator principles:
6. **CONFIRMATION TRIGGERS**: Specific signals to wait for before entry
7. **OPTIMAL RISK MANAGEMENT**: Calculate ideal stop loss and take profit percentages:
- **MINIMUM CONSTRAINTS**: Stop Loss ≥ 3%, Take Profit ≥ 1% (system enforced)
- **VOLATILITY ASSESSMENT**: Analyze current market volatility (LOW/MEDIUM/HIGH)
- **TIMEFRAME RISK**: Consider timeframe for position sizing and duration
- **KEY LEVEL DISTANCE**: Use support/resistance levels to determine optimal SL/TP
- **RISK/REWARD OPTIMIZATION**: Target minimum 1:2 risk/reward ratio
- **MARKET CONDITIONS**: Factor in current trend strength and momentum
**ANALYZE THE CHART AND PROVIDE:**
- Current price action and trend direction
- Key support and resistance levels visible on the chart
@@ -276,6 +293,14 @@ Provide your analysis in this exact JSON format:
},
"riskToReward": "1:2.5",
"confirmationTrigger": "Specific signal to wait for before entry",
"optimalRiskManagement": {
"stopLossPercent": 4.5,
"takeProfitPercent": 12.0,
"riskRewardRatio": 2.7,
"reasoning": "Based on current volatility, key levels, and timeframe analysis. Accounts for minimum 3% SL and 1% TP constraints.",
"marketVolatility": "MEDIUM",
"timeHorizon": "INTRADAY"
},
"timeframeRisk": {
"assessment": "Risk level based on timeframe",
"positionSize": "Position sizing recommendation",