Files
trading_bot_v4/scripts/test-recent-signals.sh
mindesbunister d2fbd125a0 fix: Make minSignalQualityScore configurable via settings + anti-chop improvements
CRITICAL BUG FIX:
- Settings page saved MIN_SIGNAL_QUALITY_SCORE to .env but check-risk had hardcoded value
- Now reads from config.minSignalQualityScore (defaults to 65, editable via /settings)
- Prevents settings changes from being ignored after restart

ANTI-CHOP FILTER FIXES:
- Fixed volume breakout bonus conflicting with anti-chop filter
- Volume breakout now requires ADX > 18 (trending market)
- Prevents high volume + low ADX from getting rewarded instead of penalized
- Anti-chop filter now properly blocks whipsaw traps at score 60

TESTING INFRASTRUCTURE:
- Added backtest script showing +17.1% P&L improvement (saved $242 in losses)
- Added test-signals.sh for comprehensive signal quality validation
- Added test-recent-signals.sh for analyzing actual trading session signals
- All tests passing: timeframe awareness, anti-chop, score thresholds

CHANGES:
- config/trading.ts: Added minSignalQualityScore to interface and defaults
- app/api/trading/check-risk/route.ts: Use config value instead of hardcoded 65
- lib/trading/signal-quality.ts: Fixed volume breakout bonus logic
- .env: Added MIN_SIGNAL_QUALITY_SCORE=65
- scripts/: Added comprehensive testing tools

BACKTEST RESULTS (Last 30 trades):
- Old system (score ≥60): $1,412.79 P&L
- New system (score ≥65 + anti-chop): $1,654.79 P&L
- Improvement: +$242.00 (+17.1%)
- Blocked 5 losing trades, missed 0 winners
2025-11-10 11:22:52 +01:00

99 lines
3.2 KiB
Bash
Executable File

#!/bin/bash
# Test the 4 most recent signals from the chart
API_URL="http://localhost:3001/api/trading/check-risk"
API_KEY="2a344f0149442c857fb56c038c0c7d1b113883b830bec792c76f1e0efa15d6bb"
echo "=========================================="
echo "TESTING LAST 4 SIGNALS FROM CHART"
echo "=========================================="
echo ""
# Signal 1: 10:10:01 - LONG
echo "1. 10:10:01 LONG - ADX:16.1, VOL:1.45"
echo " SOL buy .P 5 | ATR:0.27 | ADX:16.1 | RSI:47.7 | VOL:1.45 | POS:42"
curl -s -X POST "$API_URL" \
-H "Authorization: Bearer $API_KEY" \
-H "Content-Type: application/json" \
-d '{
"symbol": "SOL-PERP",
"direction": "long",
"timeframe": "5",
"atr": 0.27,
"adx": 16.1,
"rsi": 47.7,
"volumeRatio": 1.45,
"pricePosition": 42
}' | jq -r 'if .allowed then " ✅ PASS - Score: \(.qualityScore)/100" else " ❌ BLOCK - Score: \(.qualityScore)/100" end'
echo " Market went UP - LONG would have WON ✓"
echo ""
# Signal 2: 10:05:00 - SHORT (you canceled this)
echo "2. 10:05:00 SHORT - ADX:16.9, VOL:1.37"
echo " SOL sell .P 5 | ATR:0.26 | ADX:16.9 | RSI:41.6 | VOL:1.37 | POS:24.3"
curl -s -X POST "$API_URL" \
-H "Authorization: Bearer $API_KEY" \
-H "Content-Type: application/json" \
-d '{
"symbol": "SOL-PERP",
"direction": "short",
"timeframe": "5",
"atr": 0.26,
"adx": 16.9,
"rsi": 41.6,
"volumeRatio": 1.37,
"pricePosition": 24.3
}' | jq -r 'if .allowed then " ✅ PASS - Score: \(.qualityScore)/100" else " ❌ BLOCK - Score: \(.qualityScore)/100" end'
echo " Market went UP - SHORT would have LOST ✗"
echo ""
# Signal 3: 09:35:01 - SHORT
echo "3. 09:35:01 SHORT - ADX:12.8, VOL:1.52"
echo " SOL sell .P 5 | ATR:0.27 | ADX:12.8 | RSI:39.4 | VOL:1.52 | POS:9.8"
curl -s -X POST "$API_URL" \
-H "Authorization: Bearer $API_KEY" \
-H "Content-Type: application/json" \
-d '{
"symbol": "SOL-PERP",
"direction": "short",
"timeframe": "5",
"atr": 0.27,
"adx": 12.8,
"rsi": 39.4,
"volumeRatio": 1.52,
"pricePosition": 9.8
}' | jq -r 'if .allowed then " ✅ PASS - Score: \(.qualityScore)/100" else " ❌ BLOCK - Score: \(.qualityScore)/100" end'
echo " Market went UP - SHORT would have LOST ✗"
echo ""
# Signal 4: 09:25:00 - LONG
echo "4. 09:25:00 LONG - ADX:16.3, VOL:0.95"
echo " SOL buy .P 5 | ATR:0.26 | ADX:16.3 | RSI:44.1 | VOL:0.95 | POS:28.6"
curl -s -X POST "$API_URL" \
-H "Authorization: Bearer $API_KEY" \
-H "Content-Type: application/json" \
-d '{
"symbol": "SOL-PERP",
"direction": "long",
"timeframe": "5",
"atr": 0.26,
"adx": 16.3,
"rsi": 44.1,
"volumeRatio": 0.95,
"pricePosition": 28.6
}' | jq -r 'if .allowed then " ✅ PASS - Score: \(.qualityScore)/100" else " ❌ BLOCK - Score: \(.qualityScore)/100" end'
echo " Market went UP - LONG would have WON ✓"
echo ""
echo "=========================================="
echo "SUMMARY"
echo "=========================================="
echo ""
echo "Market Direction: UP (166.85 → 168.22)"
echo ""
echo "Ideal Results:"
echo " • LONG signals should PASS (correct direction)"
echo " • SHORT signals should BLOCK (wrong direction)"
echo ""