feat(v9): Complete MA gap backend integration
Integrated MA gap analysis into signal quality evaluation pipeline: BACKEND SCORING (lib/trading/signal-quality.ts): - Added maGap?: number parameter to scoreSignalQuality interface - Implemented convergence/divergence scoring logic: * LONG: +15pts tight bullish (0-2%), +12pts converging (-2-0%), +8pts early momentum (-5--2%) * SHORT: +15pts tight bearish (-2-0%), +12pts converging (0-2%), +8pts early momentum (2-5%) * Penalties: -5pts for misaligned MA structure (>5% wrong direction) N8N PARSER (workflows/trading/parse_signal_enhanced.json): - Added MAGAP:([-\d.]+) regex pattern for negative number support - Extracts maGap from TradingView v9 alert messages - Returns maGap in parsed output (backward compatible with v8) - Updated comment to show v9 format API ENDPOINTS: - app/api/trading/check-risk/route.ts: Pass maGap to scoreSignalQuality (2 calls) - app/api/trading/execute/route.ts: Pass maGap to scoreSignalQuality (2 calls) FULL PIPELINE NOW COMPLETE: 1. TradingView v9 → Generates signal with MAGAP field 2. n8n webhook → Extracts maGap from alert message 3. Backend scoring → Evaluates MA gap convergence (+8 to +15 pts) 4. Quality threshold → Borderline signals (75-85) can reach 91+ 5. Execute decision → Only signals scoring ≥91 are executed MOTIVATION: Helps borderline quality signals reach execution threshold without overriding safety rules. Addresses Nov 25 missed opportunity where good signal had MA convergence but borderline quality score. TESTING REQUIRED: - Verify n8n parses MAGAP correctly from v9 alerts - Confirm backend receives maGap parameter - Validate MA gap scoring applied to quality calculation - Monitor first 10-20 v9 signals for scoring accuracy
This commit is contained in:
@@ -94,6 +94,7 @@ async function shouldAllowScaling(
|
||||
rsi: newSignal.rsi || 50,
|
||||
volumeRatio: newSignal.volumeRatio || 1,
|
||||
pricePosition: newSignal.pricePosition,
|
||||
maGap: newSignal.maGap, // V9: MA gap convergence scoring
|
||||
direction: newSignal.direction,
|
||||
symbol: newSignal.symbol,
|
||||
currentPrice: newSignal.currentPrice,
|
||||
@@ -373,6 +374,7 @@ export async function POST(request: NextRequest): Promise<NextResponse<RiskCheck
|
||||
rsi: body.rsi || 0,
|
||||
volumeRatio: body.volumeRatio || 0,
|
||||
pricePosition: body.pricePosition || 0,
|
||||
maGap: body.maGap, // V9: MA gap convergence scoring
|
||||
direction: body.direction,
|
||||
symbol: body.symbol,
|
||||
currentPrice: currentPrice,
|
||||
|
||||
Reference in New Issue
Block a user