From 4b11186d16ab0449af9bcf1f8cf23bf858436a70 Mon Sep 17 00:00:00 2001 From: mindesbunister Date: Mon, 10 Nov 2025 07:34:21 +0100 Subject: [PATCH] Fix: Add timeframe-aware signal quality scoring for 5min charts PROBLEM: - Long signal (ADX 15.7, ATR 0.35%) blocked with score 45/100 - Missed major +3% runup, lost -2 on short that didn't flip - Scoring logic treated all timeframes identically (daily chart thresholds) ROOT CAUSE: - ADX < 18 always scored -15 points regardless of timeframe - 5min charts naturally have lower ADX (12-22 healthy range) - copilot-instructions mentioned timeframe awareness but wasn't implemented FIX: - Add timeframe parameter to RiskCheckRequest interface - Update scoreSignalQuality() with timeframe-aware ADX thresholds: * 5min/15min: ADX 12-22 healthy (+5), <12 weak (-15), >22 strong (+15) * Higher TF: ADX 18-25 healthy (+5), <18 weak (-15), >25 strong (+15) - Pass timeframe from n8n workflow through check-risk and execute - Update both Check Risk nodes in Money Machine workflow IMPACT: Your blocked signal (ADX 15.7 on 5min) now scores: - Was: 50 + 5 - 15 + 0 + 0 + 5 = 45 (BLOCKED) - Now: 50 + 5 + 5 + 0 + 0 + 5 = 65 (PASSES) This 20-point improvement from timeframe awareness would have caught the runup. --- app/api/trading/check-risk/route.ts | 2 ++ app/api/trading/execute/route.ts | 2 ++ lib/trading/signal-quality.ts | 45 ++++++++++++++++++++++------ workflows/trading/Money_Machine.json | 2 +- 4 files changed, 41 insertions(+), 10 deletions(-) diff --git a/app/api/trading/check-risk/route.ts b/app/api/trading/check-risk/route.ts index 879d38a..8a5b591 100644 --- a/app/api/trading/check-risk/route.ts +++ b/app/api/trading/check-risk/route.ts @@ -15,6 +15,7 @@ import { scoreSignalQuality, SignalQualityResult } from '@/lib/trading/signal-qu export interface RiskCheckRequest { symbol: string direction: 'long' | 'short' + timeframe?: string // e.g., "5" for 5min, "60" for 1H, "D" for daily // Optional context metrics from TradingView atr?: number adx?: number @@ -270,6 +271,7 @@ export async function POST(request: NextRequest): Promise 0) { if (params.atr < 0.15) { @@ -55,17 +65,34 @@ export function scoreSignalQuality(params: { } } - // ADX check (trend strength: want >18) + // ADX check - TIMEFRAME AWARE (trend strength) + // 5min/15min: 12-22 is healthy (trends develop slower) + // 1H+: 18+ is healthy (stronger trends expected) if (params.adx > 0) { - if (params.adx > 25) { - score += 15 - reasons.push(`Strong trend (ADX ${params.adx.toFixed(1)})`) - } else if (params.adx < 18) { - score -= 15 - reasons.push(`Weak trend (ADX ${params.adx.toFixed(1)})`) + if (isShortTimeframe) { + // 5min/15min thresholds + if (params.adx > 22) { + score += 15 + reasons.push(`Strong trend for ${params.timeframe}min (ADX ${params.adx.toFixed(1)})`) + } else if (params.adx < 12) { + score -= 15 + reasons.push(`Weak trend for ${params.timeframe}min (ADX ${params.adx.toFixed(1)})`) + } else { + score += 5 + reasons.push(`Moderate trend for ${params.timeframe}min (ADX ${params.adx.toFixed(1)})`) + } } else { - score += 5 - reasons.push(`Moderate trend (ADX ${params.adx.toFixed(1)})`) + // Higher timeframe thresholds (1H, 4H, D) + if (params.adx > 25) { + score += 15 + reasons.push(`Strong trend (ADX ${params.adx.toFixed(1)})`) + } else if (params.adx < 18) { + score -= 15 + reasons.push(`Weak trend (ADX ${params.adx.toFixed(1)})`) + } else { + score += 5 + reasons.push(`Moderate trend (ADX ${params.adx.toFixed(1)})`) + } } } diff --git a/workflows/trading/Money_Machine.json b/workflows/trading/Money_Machine.json index 625c34a..ca64bf1 100644 --- a/workflows/trading/Money_Machine.json +++ b/workflows/trading/Money_Machine.json @@ -463,7 +463,7 @@ }, "sendBody": true, "specifyBody": "json", - "jsonBody": "={\n \"symbol\": \"{{ $json.symbol }}\",\n \"direction\": \"{{ $json.direction }}\",\n \"atr\": {{ $json.atr || 0 }},\n \"adx\": {{ $json.adx || 0 }},\n \"rsi\": {{ $json.rsi || 0 }},\n \"volumeRatio\": {{ $json.volumeRatio || 0 }},\n \"pricePosition\": {{ $json.pricePosition || 0 }}\n}", + "jsonBody": "={\n \"symbol\": \"{{ $json.symbol }}\",\n \"direction\": \"{{ $json.direction }}\",\n \"timeframe\": \"{{ $json.timeframe }}\",\n \"atr\": {{ $json.atr || 0 }},\n \"adx\": {{ $json.adx || 0 }},\n \"rsi\": {{ $json.rsi || 0 }},\n \"volumeRatio\": {{ $json.volumeRatio || 0 }},\n \"pricePosition\": {{ $json.pricePosition || 0 }}\n}", "options": {} }, "id": "55671044-c7c8-4566-b271-9369a1c43158",