Enhance AI analysis with professional trading assistant approach

- Updated AI prompts to behave like professional proprietary desk trader
- Enhanced take profit display with RSI/OBV expectations and detailed descriptions
- Added timeframe risk assessment with leverage recommendations
- Implemented comprehensive indicator analysis (RSI, VWAP, OBV, MACD)
- Added alternatives section with tighter stops and scaled entry options
- Enhanced test script output for better trade setup visualization
- Improved confirmation triggers with specific technical signals
- Added cross-layout consensus analysis for multi-screenshot comparison
- Cost-effective analysis using gpt-4o mini (~/usr/bin/bash.006 per analysis)
This commit is contained in:
mindesbunister
2025-07-13 17:53:35 +02:00
parent 4965a3d0af
commit 94ed58f781
2 changed files with 278 additions and 56 deletions

View File

@@ -29,8 +29,18 @@ export interface AnalysisResult {
rationale: string
}
takeProfits?: {
tp1?: { price: number; description: string }
tp2?: { price: number; description: string }
tp1?: {
price: number
description: string
rsiExpectation?: string
obvExpectation?: string
}
tp2?: {
price: number
description: string
rsiExpectation?: string
obvExpectation?: string
}
}
riskToReward?: string
confirmationTrigger?: string
@@ -38,6 +48,24 @@ export interface AnalysisResult {
rsi?: string
vwap?: string
obv?: string
macd?: string
crossLayoutConsensus?: string
}
layoutComparison?: {
aiLayout?: string
diyLayout?: string
consensus?: string
divergences?: string
}
timeframeRisk?: {
assessment?: string
positionSize?: string
leverageRecommendation?: string
}
alternatives?: {
tigherStopOption?: string
scaledEntry?: string
invalidationScenario?: string
}
}
@@ -50,9 +78,35 @@ export class AIAnalysisService {
const imageBuffer = await fs.readFile(imagePath)
const base64Image = imageBuffer.toString('base64')
const prompt = `You are a technical chart analysis expert. Please analyze this TradingView chart image and provide objective technical analysis data.
const prompt = `You are now a professional trading assistant. You behave with the precision and decisiveness of a top proprietary desk trader. No vagueness, no fluff.
**Important**: This is for educational and research purposes only. Please analyze the technical indicators, price levels, and chart patterns visible in the image.
**TRADING ANALYSIS REQUIREMENTS:**
1. **TIMEFRAME RISK ASSESSMENT**: Based on the timeframe shown in the screenshot, adjust risk accordingly:
- Lower timeframes (1m-15m): Higher risk, use at least 10x leverage for scalps, smaller position sizes
- Higher timeframes (4H+): Lower risk, larger position sizes, swing trades
- 5-minute scalps require at least 10x leverage
2. **BE 100% SPECIFIC** - Provide exact levels with clear rationale:
**ENTRY**: Exact price level (with ± buffer if needed)
- Rationale: e.g., "Rejection from 15 EMA + VWAP confluence near intraday supply"
**STOP-LOSS**: Exact level (not arbitrary)
- Explain WHY it's there: "Above VWAP + failed breakout zone"
**TAKE PROFITS**:
- TP1: Immediate structure (previous low/high, key level)
- TP2: Extended target if momentum continues
- Mention expected RSI/OBV behavior at each TP zone
3. **RISK-TO-REWARD**: Show R:R ratio with dollar amounts if possible
4. **CONFIRMATION TRIGGERS**: Exact signals to wait for:
- Specific candle patterns, indicator crosses, volume confirmations
- RSI behavior: "If RSI crosses above 70 while price is under resistance → wait"
- VWAP: "If price retakes VWAP with bullish momentum → consider invalidation"
- OBV: "If OBV starts climbing while price stays flat → early exit or reconsider bias"
Examine the chart and identify:
- Current price action and trend direction
@@ -64,7 +118,7 @@ Examine the chart and identify:
Provide your analysis in this exact JSON format (replace values with your analysis):
{
"summary": "Objective description of what you observe in the chart",
"summary": "Objective technical analysis with timeframe risk assessment and specific trading setup",
"marketSentiment": "BULLISH|BEARISH|NEUTRAL",
"keyLevels": {
"support": [list of visible support price levels as numbers],
@@ -72,26 +126,47 @@ Provide your analysis in this exact JSON format (replace values with your analys
},
"recommendation": "BUY|SELL|HOLD",
"confidence": 75,
"reasoning": "Technical analysis reasoning based on indicators and price action",
"reasoning": "Specific technical analysis reasoning with exact rationale for each level",
"entry": {
"price": 150.50,
"buffer": "±0.25",
"rationale": "Technical reasoning for entry level"
"rationale": "Specific technical reasoning: rejection from 15 EMA + VWAP confluence near intraday supply"
},
"stopLoss": {
"price": 148.00,
"rationale": "Technical reasoning for stop level"
"rationale": "Exact reasoning: Above VWAP + failed breakout zone"
},
"takeProfits": {
"tp1": { "price": 152.00, "description": "First target reasoning" },
"tp2": { "price": 154.00, "description": "Second target reasoning" }
"tp1": {
"price": 152.00,
"description": "Immediate structure target with indicator expectations",
"rsiExpectation": "RSI should reach 60-65 zone",
"obvExpectation": "OBV confirming momentum"
},
"tp2": {
"price": 154.00,
"description": "Extended target if momentum continues",
"rsiExpectation": "RSI approaching 70+ overbought",
"obvExpectation": "OBV making new highs with price"
}
},
"riskToReward": "1:2",
"confirmationTrigger": "Technical signal to watch for",
"confirmationTrigger": "Specific signal: Bearish engulfing candle on rejection from VWAP zone with RSI under 50",
"indicatorAnalysis": {
"rsi": "RSI level and interpretation",
"vwap": "VWAP relationship to price",
"obv": "Volume analysis if visible"
"rsi": "Specific RSI level and precise interpretation with action triggers",
"vwap": "VWAP relationship to price with exact invalidation levels",
"obv": "Volume analysis with specific behavioral expectations",
"macd": "MACD signal line crosses and momentum analysis"
},
"timeframeRisk": {
"assessment": "Risk level based on detected timeframe",
"positionSize": "Suggested position sizing based on timeframe",
"leverageRecommendation": "Specific leverage suggestion for the timeframe"
},
"alternatives": {
"tigherStopOption": "Alternative setup with tighter stop if original SL is too far",
"scaledEntry": "Scaled entry approach if better levels become available",
"invalidationScenario": "What price action would invalidate this setup completely"
}
}
@@ -196,35 +271,49 @@ Return only the JSON object with your technical analysis.`
return 'Unknown Layout'
}).join(' and ')
const prompt = `You are a professional technical chart analysis expert. I'm providing you with ${filenames.length} TradingView chart screenshots from different layouts: ${layoutInfo}.
const prompt = `You are now a professional trading assistant. You behave with the precision and decisiveness of a top proprietary desk trader. No vagueness, no fluff.
**IMPORTANT**: Please analyze ALL screenshots together to provide comprehensive trading advice. Compare the different layouts and use ALL available information to make the most informed recommendation.
I'm providing you with ${filenames.length} TradingView chart screenshots from different layouts: ${layoutInfo}.
**Analysis Requirements:**
1. Examine ALL charts for:
- Current price action and trend direction across all timeframes/layouts
- Key support and resistance levels visible in any chart
- Technical indicator readings (RSI, moving averages, volume, etc.)
- Chart patterns or formations
- Market structure elements
- Any divergences or confirmations between the layouts
**TRADING ANALYSIS REQUIREMENTS:**
2. **Cross-Layout Analysis**:
- Compare insights from different chart layouts
- Look for confirmations or contradictions between views
- Identify which layout provides the clearest signals
1. **TIMEFRAME RISK ASSESSMENT**: Based on the timeframe shown in the screenshots, adjust risk accordingly:
- Lower timeframes (1m-15m): Higher risk, use at least 10x leverage for scalps, smaller position sizes
- Higher timeframes (4H+): Lower risk, larger position sizes, swing trades
- 5-minute scalps require at least 10x leverage
2. **BE 100% SPECIFIC** - Provide exact levels with clear rationale:
**ENTRY**: Exact price level (with ± buffer if needed)
- Rationale: e.g., "Rejection from 15 EMA + VWAP confluence near intraday supply"
**STOP-LOSS**: Exact level (not arbitrary)
- Explain WHY it's there: "Above VWAP + failed breakout zone"
**TAKE PROFITS**:
- TP1: Immediate structure (previous low/high, key level)
- TP2: Extended target if momentum continues
- Mention expected RSI/OBV behavior at each TP zone
3. **RISK-TO-REWARD**: Show R:R ratio with dollar amounts if possible
4. **CONFIRMATION TRIGGERS**: Exact signals to wait for:
- Specific candle patterns, indicator crosses, volume confirmations
- RSI behavior: "If RSI crosses above 70 while price is under resistance → wait"
- VWAP: "If price retakes VWAP with bullish momentum → consider invalidation"
- OBV: "If OBV starts climbing while price stays flat → early exit or reconsider bias"
5. **CROSS-LAYOUT ANALYSIS**:
- Compare insights from different chart layouts for confirmations/contradictions
- Use multiple perspectives to increase confidence
- Note which layout provides clearest signals
3. **Comprehensive Trading Setup**:
- Provide entry, stop loss, and take profit levels
- Include risk-to-reward analysis
- Suggest confirmation triggers
- Rate your confidence based on multi-layout consensus
6. **ALTERNATIVES**: If SL is far, offer tighter alternatives or scaled entries
**Response Format** (return only valid JSON):
{
"summary": "Comprehensive analysis of all charts including cross-layout insights and consensus",
"summary": "Comprehensive multi-layout analysis with timeframe risk assessment and cross-layout insights",
"marketSentiment": "BULLISH|BEARISH|NEUTRAL",
"keyLevels": {
"support": [array of support levels from all charts],
@@ -232,33 +321,54 @@ Return only the JSON object with your technical analysis.`
},
"recommendation": "BUY|SELL|HOLD",
"confidence": 85,
"reasoning": "Multi-layout technical analysis reasoning explaining how different charts confirm or contradict each other",
"reasoning": "Multi-layout technical analysis with specific rationale for each level and timeframe-adjusted risk assessment",
"entry": {
"price": 150.50,
"buffer": "±0.25",
"rationale": "Entry reasoning based on multiple chart analysis"
"rationale": "Specific technical reasoning: rejection from 15 EMA + VWAP confluence near intraday supply"
},
"stopLoss": {
"price": 148.00,
"rationale": "Stop loss reasoning considering all layouts"
"rationale": "Exact reasoning: Above VWAP + failed breakout zone"
},
"takeProfits": {
"tp1": { "price": 152.00, "description": "First target based on multi-chart analysis" },
"tp2": { "price": 154.00, "description": "Second target with cross-layout confirmation" }
"tp1": {
"price": 152.00,
"description": "Immediate structure target with RSI/OBV expectations",
"rsiExpectation": "RSI should reach 60-65 zone",
"obvExpectation": "OBV confirming momentum"
},
"tp2": {
"price": 154.00,
"description": "Extended target if momentum continues",
"rsiExpectation": "RSI approaching 70+ overbought",
"obvExpectation": "OBV making new highs with price"
}
},
"riskToReward": "1:2.5",
"confirmationTrigger": "Multi-layout signal confirmation to watch for",
"confirmationTrigger": "Specific signal: Bearish engulfing candle on rejection from VWAP zone with RSI under 50",
"indicatorAnalysis": {
"rsi": "RSI analysis across layouts",
"vwap": "VWAP analysis from multiple views",
"obv": "Volume analysis synthesis",
"crossLayoutConsensus": "How well different layouts agree on the signals"
"rsi": "Specific RSI level and precise interpretation with action triggers",
"vwap": "VWAP relationship to price with exact invalidation levels",
"obv": "Volume analysis with specific behavioral expectations",
"macd": "MACD signal line crosses and momentum analysis",
"crossLayoutConsensus": "Detailed comparison of how different layouts confirm or contradict signals"
},
"layoutComparison": {
"aiLayout": "Insights specific to AI layout",
"diyLayout": "Insights specific to DIY module layout",
"consensus": "Areas where both layouts agree",
"divergences": "Areas where layouts show different signals"
"aiLayout": "Specific insights and edge from AI layout analysis",
"diyLayout": "Specific insights and edge from DIY module layout analysis",
"consensus": "Exact areas where both layouts strongly agree with confidence boost",
"divergences": "Specific contradictions between layouts and how to resolve them"
},
"timeframeRisk": {
"assessment": "Risk level based on detected timeframe",
"positionSize": "Suggested position sizing based on timeframe",
"leverageRecommendation": "Specific leverage suggestion for the timeframe"
},
"alternatives": {
"tigherStopOption": "Alternative setup with tighter stop if original SL is too far",
"scaledEntry": "Scaled entry approach if better levels become available",
"invalidationScenario": "What price action would invalidate this setup completely"
}
}

View File

@@ -78,18 +78,129 @@ async function testDualSessionScreenshots() {
console.log(` 📊 Market Sentiment: ${result.analysis.marketSentiment}`)
console.log(` 📈 Recommendation: ${result.analysis.recommendation}`)
console.log(` 🎯 Confidence: ${result.analysis.confidence}%`)
// Trading Setup Section
if (result.analysis.entry) {
console.log(` 💰 Entry: $${result.analysis.entry.price}`)
console.log('\n💰 TRADING SETUP:')
console.log(` <20> Entry: $${result.analysis.entry.price}${result.analysis.entry.buffer ? ' ' + result.analysis.entry.buffer : ''}`)
if (result.analysis.entry.rationale) {
console.log(` 💡 ${result.analysis.entry.rationale}`)
}
}
if (result.analysis.stopLoss) {
console.log(` 🛑 Stop Loss: $${result.analysis.stopLoss.price}`)
if (result.analysis.stopLoss.rationale) {
console.log(` 💡 ${result.analysis.stopLoss.rationale}`)
}
}
// Enhanced Take Profit Display
if (result.analysis.takeProfits) {
console.log('\n🎯 TAKE PROFIT TARGETS:')
if (result.analysis.takeProfits.tp1) {
const tp1 = result.analysis.takeProfits.tp1
console.log(` 🥉 TP1: $${tp1.price}`)
console.log(` 📋 ${tp1.description}`)
if (tp1.rsiExpectation) {
console.log(` 📊 RSI: ${tp1.rsiExpectation}`)
}
if (tp1.obvExpectation) {
console.log(` 📈 OBV: ${tp1.obvExpectation}`)
}
}
if (result.analysis.takeProfits.tp2) {
const tp2 = result.analysis.takeProfits.tp2
console.log(` 🥈 TP2: $${tp2.price}`)
console.log(` 📋 ${tp2.description}`)
if (tp2.rsiExpectation) {
console.log(` 📊 RSI: ${tp2.rsiExpectation}`)
}
if (tp2.obvExpectation) {
console.log(` 📈 OBV: ${tp2.obvExpectation}`)
}
}
}
if (result.analysis.riskToReward) {
console.log(`\n⚖️ Risk/Reward: ${result.analysis.riskToReward}`)
}
if (result.analysis.confirmationTrigger) {
console.log(`\n🔔 Confirmation Trigger: ${result.analysis.confirmationTrigger}`)
}
// Timeframe Risk Assessment
if (result.analysis.timeframeRisk) {
console.log('\n⏰ TIMEFRAME RISK ASSESSMENT:')
if (result.analysis.timeframeRisk.assessment) {
console.log(` 📊 Risk Level: ${result.analysis.timeframeRisk.assessment}`)
}
if (result.analysis.timeframeRisk.positionSize) {
console.log(` <20> Position Size: ${result.analysis.timeframeRisk.positionSize}`)
}
if (result.analysis.timeframeRisk.leverageRecommendation) {
console.log(` 🎚️ Leverage: ${result.analysis.timeframeRisk.leverageRecommendation}`)
}
}
// Key Levels
if (result.analysis.keyLevels) {
console.log(` 🔴 Resistance: ${result.analysis.keyLevels.resistance?.join(', ') || 'None'}`)
console.log(` 🟢 Support: ${result.analysis.keyLevels.support?.join(', ') || 'None'}`)
console.log('\n📊 KEY LEVELS:')
if (result.analysis.keyLevels.resistance?.length > 0) {
console.log(` <20>🔴 Resistance: ${result.analysis.keyLevels.resistance.map(r => `$${r}`).join(', ')}`)
}
if (result.analysis.keyLevels.support?.length > 0) {
console.log(` 🟢 Support: ${result.analysis.keyLevels.support.map(s => `$${s}`).join(', ')}`)
}
}
// Indicator Analysis
if (result.analysis.indicatorAnalysis) {
console.log('\n📈 TECHNICAL INDICATORS:')
if (result.analysis.indicatorAnalysis.rsi) {
console.log(` 📊 RSI: ${result.analysis.indicatorAnalysis.rsi}`)
}
if (result.analysis.indicatorAnalysis.vwap) {
console.log(` 📈 VWAP: ${result.analysis.indicatorAnalysis.vwap}`)
}
if (result.analysis.indicatorAnalysis.obv) {
console.log(` 📊 OBV: ${result.analysis.indicatorAnalysis.obv}`)
}
if (result.analysis.indicatorAnalysis.macd) {
console.log(` 📉 MACD: ${result.analysis.indicatorAnalysis.macd}`)
}
}
// Layout Comparison
if (result.analysis.layoutComparison) {
console.log('\n🔄 Layout Comparison:')
console.log(` 📊 AI Layout: ${result.analysis.layoutComparison.aiLayout}`)
console.log(` 🔧 DIY Layout: ${result.analysis.layoutComparison.diyLayout}`)
console.log(` ✅ Consensus: ${result.analysis.layoutComparison.consensus}`)
console.log('\n🔄 LAYOUT COMPARISON:')
if (result.analysis.layoutComparison.aiLayout) {
console.log(` 🤖 AI Layout: ${result.analysis.layoutComparison.aiLayout}`)
}
if (result.analysis.layoutComparison.diyLayout) {
console.log(` 🔧 DIY Layout: ${result.analysis.layoutComparison.diyLayout}`)
}
if (result.analysis.layoutComparison.consensus) {
console.log(` ✅ Consensus: ${result.analysis.layoutComparison.consensus}`)
}
if (result.analysis.layoutComparison.divergences) {
console.log(` ⚠️ Divergences: ${result.analysis.layoutComparison.divergences}`)
}
}
// Alternatives
if (result.analysis.alternatives) {
console.log('\n🔄 ALTERNATIVES:')
if (result.analysis.alternatives.tigherStopOption) {
console.log(` 🎯 Tighter Stop: ${result.analysis.alternatives.tigherStopOption}`)
}
if (result.analysis.alternatives.scaledEntry) {
console.log(` 📊 Scaled Entry: ${result.analysis.alternatives.scaledEntry}`)
}
if (result.analysis.alternatives.invalidationScenario) {
console.log(` ❌ Invalidation: ${result.analysis.alternatives.invalidationScenario}`)
}
}
} else {
console.log('\n⚠ No AI analysis results received')
@@ -113,7 +224,8 @@ async function testDualSessionScreenshots() {
if (require.main === module) {
// Add fetch for Node.js environments that don't have it built-in
if (typeof fetch === 'undefined') {
global.fetch = require('node-fetch')
const { default: fetch } = require('node-fetch')
global.fetch = fetch
}
testDualSessionScreenshots()