Commit Graph

446 Commits

Author SHA1 Message Date
mindesbunister
cefa3e646d critical: MANDATORY quality score check in execute endpoint
ROOT CAUSE:
- Execute endpoint calculated quality score but NEVER checked it
- After timeframe='5' validation, proceeded directly to execution
- TradingView sent signal with all metrics=0 (ADX, ATR, RSI, etc.)
- Quality scored as 30, but no threshold check existed
- Position opened with 909.77 size at quality 30 (need 90+ for LONG)

THE FIX:
- Added MANDATORY quality check after timeframe validation
- Blocks execution if score < minQualityScore (90 LONG, 95 SHORT)
- Returns HTTP 400 with detailed error message
- Logs Quality check passed OR  QUALITY TOO LOW:

AFFECTED TRADES:
- cmihwkjmb0088m407lqd8mmbb: Quality 30 LONG (stopped out)
- cmih6ghn20002ql07zxfvna1l: Quality 50 LONG (stopped out)
- cmih5vrpu0001ql076mj3nm63: Quality 50 LONG (stopped out)

This is a FINANCIAL SAFETY critical fix - prevents low-quality trades.
2025-11-27 23:17:29 +01:00
mindesbunister
2749c08d15 docs: MANDATORY copilot-instructions.md updates + 1-min data direction field
CRITICAL: Added iron-clad rule that copilot-instructions.md MUST be updated
for every significant change. User is 'sick and tired' of reminding.

New mandatory section explains:
- When to update this file (8 specific scenarios)
- Why it's the primary knowledge base for future developers
- Automatic workflow: Change → Code → Test → Update Docs → Commit

1-Minute Data Collection documented:
- Direction field is meaningless (TradingView artifact)
- Analysis should ignore direction for timeframe='1'
- Focus on ADX/ATR/RSI/volume/price position metrics
- Example correct vs wrong SQL queries

This is NON-NEGOTIABLE going forward.
2025-11-27 19:32:22 +01:00
mindesbunister
8310a5c42b docs: Clarify 1-minute signal direction field is meaningless
- Direction field populated due to TradingView alert syntax requirement
- NOT trading signals, pure market data collection
- Analysis should ignore direction, focus on metrics
2025-11-27 19:30:22 +01:00
mindesbunister
b13a0f1b6b docs: Update copilot-instructions.md with Phase 7.3 Adaptive Trailing Stop
- Position Manager section: Complete Phase 7.3 documentation with real-time ADX queries
- Documented adaptive multiplier logic: acceleration bonus, deceleration penalty, combined 3.16× max
- Added example calculation showing 2.15× wider trail vs old static system
- When Making Changes section: Added Phase 7.3 verification steps and log monitoring
- Trailing stop changes: Updated with new adaptive system details and testing procedures
- References: PHASE_7.3_ADAPTIVE_TRAILING_DEPLOYED.md and 1MIN_DATA_ENHANCEMENTS_ROADMAP.md
2025-11-27 17:02:59 +01:00
mindesbunister
e3d98a3f5b docs: Phase 7.3 deployment summary and verification checklist 2025-11-27 16:55:42 +01:00
mindesbunister
130e9328d8 feat: Phase 7.3 - 1-Minute Adaptive TP/SL (DEPLOYED Nov 27, 2025)
- Query fresh 1-minute ADX from market cache every monitoring loop
- Dynamically adjust trailing stop based on trend strength changes
- Acceleration bonus: ADX increased >5 points = 1.3× wider trail
- Deceleration penalty: ADX decreased >3 points = 0.7× tighter trail
- Combined with existing ADX strength tiers and profit acceleration
- Expected impact: +,000-3,000 over 100 trades by capturing accelerating trends
- Directly addresses MA crossover pattern (ADX 22.5→29.5 in 35 minutes)
- Files: lib/trading/position-manager.ts (adaptive logic), 1MIN_DATA_ENHANCEMENTS_ROADMAP.md (Phase 7.3 complete)
2025-11-27 16:40:02 +01:00
mindesbunister
56e9522740 docs: Add MA crossover detection to copilot instructions 2025-11-27 16:31:05 +01:00
mindesbunister
ad3eb9841f docs: Add MA crossover detection implementation summary 2025-11-27 16:25:49 +01:00
mindesbunister
633d204b66 feat: Add MA crossover detection to n8n workflow
- Updated parse_signal_enhanced.json to detect 'crossing' keyword
- Added three new flags: isMACrossover, isDeathCross, isGoldenCross
- Death cross = MA50 crossing below MA200 (short direction)
- Golden cross = MA50 crossing above MA200 (long direction)
- Enables automated data collection for MA crossover pattern validation
- Documented in INDICATOR_V9_MA_GAP_ROADMAP.md validation strategy
- User configured TradingView alert to send crossover events
- Goal: Collect 5-10 examples to validate ADX weak→strong pattern
2025-11-27 16:24:53 +01:00
mindesbunister
d1ffa077c9 docs: Correct indicator version v8→v9 in MA cross documentation
USER CORRECTION: System currently running v9, not v8

Changes:
- Updated MA cross ADX pattern finding to reference v9
- Noted v9 already includes MA Gap Analysis (deployed Nov 26)
- Clarified v9 system status and current capabilities
- Updated historical Nov 25 incident as "Pre-v9" context
- This finding VALIDATES v9's early detection design

Key Points:
- ADX strengthens during cross (22.5 → 29.5)
- Current v9 SHORT filter (ADX ≥23) would pass at crossover
- 1-minute monitoring proves the approach works

Status: v9 PRODUCTION (Nov 26+), MA Gap already deployed
2025-11-27 16:20:07 +01:00
mindesbunister
f318b5161c docs: Add critical MA cross ADX pattern discovery (Nov 27, 2025)
JACKPOT FINDING: v8 signals arrive 35 minutes BEFORE actual crossover!

Timeline Evidence (Nov 27 Death Cross):
- 10:30 Berlin: Signal fires with ADX 22.5 (weak, blocked)
- ADX progression: 22.5 → 28.9 → 29.2 → 29.5 → 29.8 (35-minute climb)

Pattern Discovered:
- Early signals have weak ADX (below threshold)
- ADX strengthens DURING the crossover event
- 1-minute data captures this progression perfectly
- Smart Entry Timer + Phase 7.2 validation can catch strengthening

Validation Plan:
- Collect 5-10 more MA cross examples
- Verify pattern consistency (weak → strong ADX during cross)
- If consistent: Adjust quality scoring or timing logic

Impact:
- Proves v8 indicator timing is CORRECT (early detection)
- Explains why quality filter blocks these signals
- 1-minute monitoring validates the approach works

Files Updated:
- INDICATOR_V9_MA_GAP_ROADMAP.md (added Critical Finding section)
2025-11-27 16:18:40 +01:00
mindesbunister
2cf3deb551 docs: CRITICAL - Fix roadmap Phase 7.1/7.2 status + add MANDATORY update requirements
PROBLEM DISCOVERED (Nov 27, 2025):
User: "whats next on our roadmap with the biggest impact?"
Agent: "Phase 3 Smart Entry Timing - NOT STARTED"
User: "i thought that was already implemented?" ← USER WAS RIGHT!
Reality: Phase 3 = Phase 7.1 (smart-entry-timer.ts, 718 lines, DEPLOYED)

ROOT CAUSE:
- Roadmap said "Phase 3: NOT STARTED"
- Code reality: Phase 7.1 Smart Entry Timer fully operational
- Phase 7.2 Signal Quality Validation also deployed Nov 27
- Documentation completely out of sync with deployed code

IMPACT:
- User confusion justified (roadmap misleading)
- Wasted time investigating "next feature" already deployed
- Agent suggested implementing feature that exists
- Phase numbering confusion (Phase 2/3/7.1/7.2 mixed)

FIXES APPLIED:

1. 1MIN_DATA_ENHANCEMENTS_ROADMAP.md:
   - Phase 7.1: Smart Entry Timer →  COMPLETE (DEPLOYED)
   - Added complete documentation of deployed system
   - Explained timeout protection (NO MISSED TRADES)
   - Showed ENV config (SMART_ENTRY_ENABLED=true)
   - Phase 7.2: Already marked complete (Nov 27)

2. .github/copilot-instructions.md:
   - NEW SECTION: "📋 MANDATORY: ROADMAP MAINTENANCE"
   - 6 iron-clad rules for roadmap updates
   - Update immediately after deployment (same session)
   - Verify roadmap accuracy BEFORE recommending features
   - Never suggest features based only on roadmap status
   - ALWAYS grep codebase to verify implementation
   - Checklist for roadmap updates
   - Before recommending "next feature" verification steps

MANDATORY WORKFLOW (ALL FUTURE AGENTS):
. Complete feature/phase
. Update roadmap status → COMPLETE with date
. Document actual impact (after data collection)
. Consolidate phase numbering if inconsistencies
. Commit roadmap changes SAME SESSION
. VERIFY feature exists before recommending

LESSON LEARNED:
Roadmap documentation is CRITICAL in real money system.
Wrong roadmap = wrong priorities = wasted time = lost profits.
User time is valuable - outdated docs waste it.

FILES CHANGED:
- 1MIN_DATA_ENHANCEMENTS_ROADMAP.md (Phase 7.1 marked COMPLETE)
- .github/copilot-instructions.md (MANDATORY section added)

STATUS: Documentation now reflects deployed reality 
2025-11-27 14:26:15 +01:00
mindesbunister
a676eb4753 docs: Add zero-downtime changes guide - stop unnecessary rebuilds
PROBLEM: Rebuilding container 4-6 times per session when most changes don't need it
- Every rebuild: 40-70 seconds downtime
- Recent session: 200 seconds downtime that could've been 50 seconds
- Rebuilding for documentation (should be git only)
- Rebuilding for n8n workflows (should be manual import)
- Rebuilding for ENV changes (should be restart only)

SOLUTION: Created comprehensive guide on what actually needs rebuilds

ZERO DOWNTIME (just commit):
- Documentation (.md files)
- Workflows (.json, .pinescript)
- Hot-reload endpoints (roadmap reload)

RESTART ONLY (5-10 seconds):
- ENV variable changes (.env)
- Database schema (prisma migrate + generate)

REBUILD REQUIRED (40-70 seconds):
- Code changes (.ts, .tsx, .js)
- Dependencies (package.json)
- Dockerfile changes

SMART BATCHING:
- Group multiple code changes into ONE rebuild
- Example: 6 fixes → 1 rebuild = 50s total (not 6× rebuilds = 300s)

CREATED FILES:
- docs/ZERO_DOWNTIME_CHANGES.md (comprehensive guide with examples)
- Updated copilot-instructions.md (quick decision matrix)

EXPECTED IMPACT:
- 60-80% reduction in rebuild frequency
- 60-80% reduction in downtime per session
- Better workflow: batch changes, test together, deploy once

User was right: We were rebuilding WAY too often unnecessarily 
2025-11-27 14:08:42 +01:00
mindesbunister
49f19b1a8c feat: Phase 7.2 Real-Time Quality Validation COMPLETE + Hot-Reload Roadmap
PHASE 7.2 COMPLETE (Nov 27, 2025):
 4 validation checks before Smart Entry execution
 ADX degradation check (drops >2 points = cancel)
 Volume collapse check (drops >40% = cancel)
 RSI reversal detection (LONG RSI <30 or SHORT RSI >70 = cancel)
 MAGAP divergence check (wrong MA structure = cancel)
 Integrated with Smart Entry Timer (waits 2-4 min pullback)
 Detailed logging shows validation results

EXPECTED IMPACT:
- Block 5-10% of degraded signals during wait period
- Save $300-800 in prevented losses over 100 trades
- Prevent entries when ADX/volume/momentum weakens

FILES CHANGED:
- app/api/roadmap/route.ts (marked Phase 7.2 complete)
- 1MIN_DATA_ENHANCEMENTS_ROADMAP.md (updated Phase 2 → Phase 7.2 complete)

HOT-RELOAD SOLUTION (Zero Downtime Updates):
 Created /api/roadmap/reload endpoint
 POST to reload roadmap without container restart
 Roadmap page has Reload button with status messages
 No more unnecessary downtime for documentation updates!

USAGE:
- Web UI: Click Reload button on roadmap page
- API: curl -X POST http://localhost:3001/api/roadmap/reload
- Updates live instantly without rebuild/redeploy

User request: "update the roadmap and documentation. also try to find a way to update the roadmap website without having to restart/rebuild/redeploy the whole container. thats unnessary downtime"

All complete 
2025-11-27 14:00:46 +01:00
mindesbunister
53c8c59c25 feat: Phase 7.2 Real-Time Quality Validation
FEATURE: Validate signal quality before Smart Entry execution
- Re-checks market conditions after pullback wait (2-4 min)
- Cancels trade if conditions degraded significantly

VALIDATION CHECKS (4):
1. ADX degradation: Cancel if drops >2 points (enhanced existing)
2. Volume collapse: Cancel if drops >40% (NEW - momentum fading)
3. RSI reversal: Cancel if LONG RSI <30 or SHORT RSI >70 (NEW)
4. MAGAP divergence: Cancel if wrong MA structure (NEW)

EXPECTED IMPACT:
- Block 5-10% of signals that degrade during Smart Entry wait
- Save $300-800 in prevented losses over 100 trades
- Prevent entries when ADX/volume/momentum weakens

FILES CHANGED:
- lib/trading/smart-entry-timer.ts (115 lines validation logic)
- lib/trading/market-data-cache.ts (added maGap to interface)

INTEGRATION: Works with Phase 7.1 Smart Entry Timer
- Smart Entry waits for pullback (2-4 min)
- Phase 7.2 validates quality before execution
- Cancels if conditions degraded, executes if maintained
2025-11-27 13:53:53 +01:00
mindesbunister
f420d98d55 critical: Make health monitor 3-4x more aggressive to prevent heap crashes
PROBLEM (Nov 27, 2025 - 11:53 UTC):
- accountUnsubscribe errors accumulated 200+ times in 2 seconds
- JavaScript heap out of memory crash BEFORE health monitor could trigger
- Old settings: 50 errors / 30s window / check every 10s = too slow
- Container crashed from memory exhaustion, not clean restart

SOLUTION - 3-4x FASTER RESPONSE:
- Error window: 30s → 10s (3× faster detection)
- Error threshold: 50 → 20 errors (2.5× more sensitive)
- Check frequency: 10s → 3s intervals (3× more frequent)

IMPACT:
- Before: 10-40 seconds to trigger restart
- After: 3-13 seconds to trigger restart (3-4× faster)
- Catches rapid error accumulation BEFORE heap exhaustion
- Clean restart instead of crash-and-recover

REAL INCIDENT TIMELINE:
11:53:43 - Errors start accumulating
11:53:45.606 - FATAL: heap out of memory (2.2 seconds)
11:53:47.803 - Docker restart (not health monitor)

NEW BEHAVIOR:
- 20 errors in 10s = trigger at ~100ms/error rate
- 3s check interval catches problem in 3-13s MAX
- Clean restart before memory leak causes crash

Files Changed:
- lib/monitoring/drift-health-monitor.ts (lines 13-14, 32)
2025-11-27 13:04:14 +01:00
mindesbunister
d602744938 critical: Fix 1-minute signal price logging - query Drift oracle directly
Problem:
- 1-minute signals logged wrong prices (4-55 vs actual 41-144 SOL)
- Pyth price cache empty for 1-minute signals
- Fallback to body.signalPrice (from n8n) contained pricePosition value
- signalPrice === pricePosition in every request (39.29 = 39.29)

Failed Attempts (5):
1. Added @ close to TradingView indicator (commit 212a36f)
2. Added signalPrice regex to n8n (commit 99a5223)
3. Fixed regex to avoid POS collision (commit ff402ed)
4. Added DEBUG logging to n8n (no output visible)
5. FINAL FIX: Query Drift oracle directly

Solution:
- Bypass Pyth cache and n8n signalPrice entirely
- Query Drift Protocol oracle directly for real-time price
- Lines 145-149 in execute/route.ts:
  * OLD: latestPrice?.price || body.signalPrice || 0
  * NEW: await driftService.getOraclePrice(marketConfig.driftMarketIndex)
- Drift oracle is source of truth (on-chain), no caching issues
- Added getMarketConfig import to resolve marketConfig

Impact:
- Logs will show actual SOL price ($141.XX) instead of indicator values ($24-55)
- Accurate price logging critical for REAL MONEY system P&L tracking
- BlockedSignal database records will have correct signalPrice values

Files Changed:
- app/api/trading/execute/route.ts (lines 11, 145-149)
  * Added getMarketConfig to imports
  * Replaced Pyth cache fallback with direct Drift oracle query
2025-11-27 12:48:37 +01:00
mindesbunister
ff402ed4d2 critical: Fix n8n signalPrice regex to avoid pricePosition collision
PROBLEM: n8n extracting pricePosition (25.19) as signalPrice instead of close price (142.08)
- Request body showed: signalPrice: 25.1908396947 (IDENTICAL to pricePosition)
- Pyth oracle confirmed actual SOL price: $141.796
- TradingView sending correct format: "buy 1 @ 142.08 | ATR:... | POS:25.19"

ROOT CAUSE: Old regex /@\s*([\d.]+)/ too loose, matched first number after @
- Could match POS:25.19 if @ somehow associated with it

FIX: Changed to /@\s*([\d.]+)\s*\|/
- Now REQUIRES pipe after price: "@ 142.08 |"
- Cannot match POS:25.19 (no @ before POS)
- More specific pattern prevents collision

VERIFICATION:
- User must re-import updated parse_signal_enhanced.json into n8n
- Next signal should show $141.XX not $25.XX in logs
- Request body signalPrice should match Pyth price, not pricePosition
2025-11-27 12:27:52 +01:00
mindesbunister
99a5223ec6 fix: Add signal price parsing to n8n workflow
PROBLEM:
- Bot logs showing wrong prices ($30-43 vs actual $141-144)
- TradingView sending correct format: 'buy 1 @ 142.08'
- n8n Parse Signal Enhanced wasn't extracting @ price field

ROOT CAUSE:
- n8n workflow parsed ATR, ADX, RSI, VOL, POS, MAGAP, IND
- But @ price field was never extracted
- Bot fell back to undefined → used RSI value instead

SOLUTION:
- Added signalPrice extraction: /@\s*([\d.]+)/
- Returns signalPrice field in n8n output
- Bot receives correct price in body.signalPrice

IMPACT:
- Logs will show correct SOL price ($141-144)
- Database signalPrice field accurate
- BlockedSignalTracker can calculate correct P&L

FILES CHANGED:
- workflows/trading/parse_signal_enhanced.json

NEXT STEP:
User must import updated workflow into n8n
Then 1-minute signals will log correct prices 
2025-11-27 12:18:53 +01:00
mindesbunister
212a36fef3 fix: Add close price to 1-minute data feed webhook
PROBLEM:
- Logs showing wrong prices: $30-43 when SOL actually at $141-144
- Webhook message missing close price field
- Bot falling back to RSI/ATR values (30-40 range)

ROOT CAUSE:
- TradingView indicator sending: 'SOLUSDT buy 1 | ATR:X | ADX:Y...'
- No @ price field in message
- n8n couldn't extract signalPrice, bot used wrong fallback

SOLUTION:
- Added close price to webhook format
- New format: 'SOLUSDT buy 1 @ 143.50 | ATR:X | ADX:Y...'
- Matches main trading signal format (v9 uses same pattern)

IMPACT:
- Logs will now show correct SOL price ($141-144)
- Database signalPrice field accurate
- BlockedSignalTracker can calculate correct P&L movements

FILES CHANGED:
- workflows/trading/moneyline_1min_data_feed.pinescript

User deployed updated indicator to TradingView 
Next 1-minute alert will show correct price
2025-11-27 12:14:38 +01:00
mindesbunister
85581a670a fix: Skip frequency checks for data collection signals
PROBLEM:
- 1-minute data collection signals were getting blocked
- Overtrading penalty: '30 signals in 30min (-20 pts)'
- Flip-flop penalty: 'opposite direction 1min ago (-25 pts)'
- These penalties don't make sense for data collection

ROOT CAUSE:
- Quality scoring runs for ALL timeframes (needed for analysis)
- But frequency checks (overtrading/flip-flop) only apply to production (5min)
- Data collection signals (1min, 15min, 1H, etc.) shouldn't be penalized

SOLUTION:
- Added skipFrequencyCheck parameter to scoreSignalQuality()
- Set to true for all non-5min timeframes: skipFrequencyCheck: timeframe !== '5'
- Moved timeframe variable declaration earlier for reuse
- 1-minute signals now score purely on technical merit (ADX/ATR/RSI/etc.)

IMPACT:
- 1-minute data collection works correctly
- No false 'overtrading' blocks every minute
- Quality scores still calculated for cross-timeframe analysis
- Production 5min signals still have full frequency validation

FILES CHANGED:
- app/api/trading/execute/route.ts (quality scoring call)

DEPLOYED: Nov 27, 2025 (71.8s build time)
2025-11-27 12:07:37 +01:00
mindesbunister
c86b1fb24f docs: Add Smart Entry Timing deployment status document
- Comprehensive deployment status and monitoring guide
- Expected log sequences for all scenarios
- Database tracking queries and financial projections
- Troubleshooting guide and validation checklist
- Ready for first signal arrival

Feature is ACTIVE and will initialize on first trade signal.
2025-11-27 11:54:54 +01:00
mindesbunister
cf6bdacdce feat: Enable Smart Entry Timing in production (SMART_ENTRY_ENABLED=true)
- Changed SMART_ENTRY_ENABLED from false to true in .env
- Rebuilt Docker container to load new configuration
- Feature will initialize on first signal arrival
- Expected impact: 0.2-0.5% better entry prices = ,600-4,000 over 100 trades
- Smart Entry Timer will queue signals and wait for 0.15-0.5% pullback
- Max wait time: 2 minutes before timeout and execution
- ADX validation: Can't drop >2 points during wait

Deployment verified:
- Container rebuilt successfully (74s build time)
- Configuration loaded: SMART_ENTRY_ENABLED=true in /app/.env
- Container running and healthy
- Lazy initialization: Will activate on first signal

Next steps:
- Monitor first signal for Smart Entry initialization log
- Verify queuing behavior when price not at favorable level
- Collect 5-10 test trades to validate improvement metrics
2025-11-27 11:53:50 +01:00
mindesbunister
a98ddadcd4 docs: Add comprehensive Smart Entry Timing status documentation 2025-11-27 11:42:02 +01:00
mindesbunister
a8c1b2ca06 feat: Phase 2 Smart Entry Timing - COMPLETE
Implementation of 1-minute data enhancements Phase 2:
- Queue signals when price not at favorable pullback level
- Monitor every 15s for 0.15-0.5% pullback (LONG=dip, SHORT=bounce)
- Validate ADX hasn't dropped >2 points (trend still strong)
- Timeout at 2 minutes → execute at current price
- Expected improvement: 0.2-0.5% per trade = ,600-4,000 over 100 trades

Files:
- lib/trading/smart-entry-timer.ts (616 lines, zero TS errors)
- app/api/trading/execute/route.ts (integrated smart entry check)
- .env (SMART_ENTRY_* configuration, disabled by default)

Next steps:
- Test with SMART_ENTRY_ENABLED=true in development
- Monitor first 5-10 trades for improvement verification
- Enable in production after successful testing
2025-11-27 11:40:23 +01:00
mindesbunister
cecdb8290c docs: Add 1-minute data enhancements roadmap
DOCUMENTATION:
- Created 1MIN_DATA_ENHANCEMENTS_ROADMAP.md (comprehensive 7-phase plan)
- Copied to docs/ folder for permanent documentation
- Updated website roadmap API with Phase 7 items

PHASE 7 FOUNDATION  COMPLETE (Nov 27, 2025):
- 1-minute data collection working (verified)
- Revenge system ADX validation deployed
- Market data cache updates every 60 seconds
- Foundation for 6 future enhancements

PLANNED ENHANCEMENTS:
1. Smart Entry Timing (0.2-0.5% better entries)
2. Signal Quality Real-Time Validation (block degraded signals)
3. Stop-Hunt Early Warning System (predictive revenge)
4. Dynamic Position Sizing (ADX momentum-based leverage)
5. Re-Entry Analytics Momentum Filters (trend strength)
6. Dynamic Trailing Stop Optimization (adaptive trail width)

EXPECTED IMPACT:
- Entry improvement: $1,600-4,000 over 100 trades
- Block 5-10% degraded signals
- Revenge success rate: +10-15%
- Runner profitability: +10-20%
- Better risk-adjusted returns across all systems

User requested: "put that on every documentation. it has to go on the websites roadmap as well"
All locations updated 
2025-11-27 10:38:48 +01:00
mindesbunister
702d08b0ba feat: Integrate ADX validation into revenge system using 1-min market data
ENHANCEMENTS:
- Revenge system now checks fresh ADX from 1-minute market data cache
- Blocks revenge if ADX < 20 (weak trend - not worth re-entering)
- Executes revenge if ADX >= 20 (strong trend - high probability)
- Saves revengeFailedReason='ADX_TOO_LOW_X.X' for blocked attempts
- Telegram notification shows ADX check result

DATABASE:
- Added revengeFailedReason field to StopHunt table
- Added revengePnL field to track revenge trade outcomes

INTEGRATION:
- Uses getPythPriceMonitor().getCachedPrice() for fresh data
- Falls back to originalADX if cache unavailable
- Logs ADX validation: 'ADX check: X.X (threshold: 20)'

1-MINUTE DATA COLLECTION COMPLETE:
- TradingView alerts recreated with new format
- Bot correctly filters timeframe='1' → BlockedSignal
- Market data cache updates every 60 seconds
- Verified working: 2 signals collected, 0 trades executed
2025-11-27 10:16:59 +01:00
mindesbunister
649628a5c2 docs: Add simplified 1-minute data collection guide
Key insight: 1-min collection uses SAME pattern as 15min/1H/Daily
- Same webhook (tradingview-bot-v4)
- Same workflow (Money Machine)
- Bot filters by timeframe='1' → saves to BlockedSignal
- No separate infrastructure needed

User was right - it's not different, just needed same format!
2025-11-27 09:31:12 +01:00
mindesbunister
cb0297607b fix: Change 1-min indicator to use trading signal format (timeframe filtering)
Now follows same pattern as 15min/1H/Daily data collection:
- Sends trading signal format: 'SOLUSDT buy 1 | ATR:X | ADX:Y...'
- Bot's execute endpoint filters by timeframe='1' (no trades executed)
- Saves to BlockedSignal table for analysis
- Uses SAME webhook as trading signals (no separate webhook needed)

This is simpler than separate market_data endpoint approach.
Bot already handles this pattern for multi-timeframe data collection.
2025-11-27 09:30:08 +01:00
mindesbunister
75069802bf docs: CRITICAL - Document 1-minute webhook misconfiguration fix
Issue: 1-minute data alerts using wrong webhook (tradingview-bot-v4)
Impact: Triggered Money Machine trading workflow every minute
Solution: Need dedicated market_data_handler webhook
Status: Alerts paused, awaiting correct webhook URL from n8n
2025-11-27 09:27:36 +01:00
mindesbunister
383a319e87 fix: Single line string concatenation for Pine Script v6
Pine Script v6 does not support multi-line string concatenation
Put entire JSON message on single line
2025-11-27 09:12:33 +01:00
mindesbunister
565b42a56c fix: Use alert() function instead of alertcondition for dynamic JSON
Pine Script alertcondition() requires const string (no variables allowed)
Switched to alert() function which supports series string (dynamic values)

Changes:
- Removed alertcondition(), added if barstate.isconfirmed + alert()
- Build JSON message with all metrics dynamically
- alert.freq_once_per_bar ensures one alert per candle close
- Now includes all required fields: atr, adx, rsi, volumeRatio, pricePosition, maGap

Alert setup in TradingView:
1. Add indicator to 1-minute chart
2. Create alert on indicator
3. Condition: 'alert() function calls' (not alertcondition)
4. Frequency: Once Per Bar Close
5. Message: Use {{strategy.order.alert_message}} or leave blank
2025-11-27 09:02:12 +01:00
mindesbunister
e792aaae38 fix: Pine Script alertcondition requires const string, use TradingView placeholders
alertcondition() message parameter must be const string, not series
Use TradingView placeholders for dynamic values:
- {{ticker}} for symbol
- {{close}} for current price
- {{plot_0}} for ATR (first plot)
- {{plot_1}} for ADX (second plot - from hline, not plot call)

Wait, ADX IS plotted on line 23, so {{plot_0}} should work
Let me reconsider the approach...
2025-11-27 08:59:28 +01:00
mindesbunister
36a5f629f4 fix: Pine Script string concatenation - single line for alertMessage
Pine Script v6 doesn't support multi-line string concatenation with +
Put entire JSON string on single line instead
2025-11-27 08:58:23 +01:00
mindesbunister
6834a1cf4c fix: Pine Script syntax errors - v6, ADX tuple destructuring, var declaration
- Upgraded to @version=6 (v5 outdated)
- Fixed ADX: ta.dmi() returns tuple [diPlus, diMinus, adx] - must destructure
- Fixed alertMessage: Added 'var string' declaration for proper scoping
- Now compiles without errors

Errors fixed:
- Line 1: Version 5 outdated → v6
- Line 6: ADX tuple assignment → [diPlus, diMinus, adx] = ta.dmi(14, 14)
- Line 12: plot() argument type → adx now properly extracted from tuple
- Line 16: String concatenation → var string declaration added
2025-11-27 08:57:04 +01:00
mindesbunister
4458cd1dae feat: Add 1-minute market data TradingView indicator and setup guide
- Created Pine Script indicator: moneyline_1min_data_feed.pinescript
  * Calculates ADX, ATR, RSI, volumeRatio, pricePosition, MA gap
  * Sends JSON with action="market_data_1min" every bar close
  * Uses same metrics as v9 indicator for consistency
  * Alert fires every 1 minute on 1-min chart

- Created setup guide: docs/1MIN_ALERTS_SETUP.md
  * Step-by-step TradingView alert configuration (SOL/ETH/BTC)
  * Alert slot usage: 3 needed, 16 remaining free (no upgrade needed)
  * n8n workflow validation steps (already has Is 1min Data? condition)
  * 24-48 hour testing procedures
  * Troubleshooting guide for common issues
  * Integration plan for ADX validation in revenge system

- Verified n8n workflow ready:
  * market_data_handler.json has "Is 1min Data?" condition (checks action === market_data_1min)
  * Forwards to http://trading-bot-v4:3000/api/trading/market-data
  * Responds with {success: true, cached: true}
  * NO workflow changes needed - infrastructure already prepared

Alert volume: 180/hour (60 per symbol) = 129,600/month
Storage impact: 19.44 MB/month (negligible)
Cost: $0/month (no TradingView upgrade required)

Ready to implement - user can create alerts immediately
Next: Validate 24-48 hours, then integrate ADX confirmation in revenge system
2025-11-27 08:53:28 +01:00
mindesbunister
c3a7e75111 fix: Update 1-minute market data docs - No TradingView upgrade needed
GOOD NEWS: TradingView alert limits are for ACTIVE alerts (slots), not trigger count!

Current Status:
- Essential plan: 20 alert slots
- Used: 4/20 slots
- Needed for 1-min data: 3 slots (SOL/ETH/BTC)
- After implementation: 7/20 slots (13 free)

Cost Impact:
- BEFORE: Documented as $35/month TradingView Pro upgrade required
- AFTER: $0/month - Use existing Essential plan 

Changes:
- Updated cost analysis section: $35/month → $0/month
- Updated alert volume section: Clarified slot vs trigger distinction
- Updated header: Added zero-cost callout
- Removed all Pro subscription upgrade requirements

Implementation Path:
- Phase 1: Create 3 alerts on existing subscription
- Phase 2: Validate for 24-48 hours
- Phase 3: Integrate ADX validation into revenge system

No financial approval needed - pure infrastructure improvement at zero cost!
2025-11-27 08:37:48 +01:00
mindesbunister
db52299b55 feat: Enhancement #6 data collection + #1 implementation plan
Enhancement #6 - SL Distance Validation (Data Collection Phase):
- Added slDistanceAtEntry field to StopHunt schema
- Calculates distance from revenge entry to stop zone (LONG vs SHORT logic)
- Logs distance in dollars + × ATR multiplier
- Purpose: Collect 20+ revenge trade samples for optimal multiplier analysis
- Created comprehensive analysis guide with SQL queries
- Decision deferred until empirical data collected

Enhancement #1 - ADX Confirmation (Implementation Plan):
- Documented complete 1-minute TradingView alert strategy
- Storage analysis: 19.44 MB/month for 3 symbols (negligible)
- Two-phase approach: Cache-only MVP → Optional DB persistence
- Provided TradingView Pine Script (ready to use)
- Cost breakdown: Pro subscription $49.95/month required
- Benefits: Real-time ADX, pattern recognition, ML features
- Implementation checklist with validation phases

Files Changed:
- prisma/schema.prisma: +1 field (slDistanceAtEntry)
- lib/trading/stop-hunt-tracker.ts: +10 lines (distance calculation + logging)
- docs/1MIN_MARKET_DATA_IMPLEMENTATION.md: NEW (comprehensive plan)
- docs/ENHANCEMENT_6_ANALYSIS_GUIDE.md: NEW (SQL queries + decision matrix)

Status:
 Enhancement #4 and #10 deployed (previous commit)
 Enhancement #6 data collection enabled (this commit)
   Awaiting 20+ revenge trades for Enhancement #6 decision
2025-11-27 08:26:45 +01:00
mindesbunister
ceb84c3bc1 feat: Revenge system enhancements #4 and #10 - IMPLEMENTED
Enhancement #4: Failed Revenge Tracking
- Added 3 database fields: revengeOutcome, revengePnL, revengeFailedReason
- Added updateRevengeOutcome() method in stop-hunt-tracker.ts
- Position Manager hooks revenge trade closes, records outcome
- Enables data-driven analysis of revenge success rate

Enhancement #10: Metadata Persistence
- Added 4 database fields: firstCrossTime, lowestInZone, highestInZone, zoneResetCount
- Migrated 90-second zone tracking from in-memory to database
- Rewrote shouldExecuteRevenge() with database persistence
- Container restarts now preserve exact zone tracking state

Technical Details:
- Prisma schema updated with 7 new StopHunt fields
- Added signalSource field to ActiveTrade interface
- All zone metadata persisted in real-time to database
- Build verified successful (no TypeScript errors)

Files Changed:
- prisma/schema.prisma (StopHunt model + index)
- lib/trading/stop-hunt-tracker.ts (DB persistence + outcome tracking)
- lib/trading/position-manager.ts (revenge hook + interface)
- docs/REVENGE_ENHANCEMENTS_EXPLAINED.md (comprehensive guide)

Pending User Decision:
- Enhancement #1: ADX confirmation (3 options explained in docs)
- Enhancement #6: SL distance validation (2× ATR recommended)

Status: Ready for deployment after Prisma migration
Date: Nov 27, 2025
2025-11-27 08:08:37 +01:00
mindesbunister
2238261dfe docs: Add Docker Optimization & Build Cache Management section
DOCUMENTATION UPDATE (Nov 26, 2025):
User quote: "ok. dont forget the documentation"

Added comprehensive Docker Optimization section covering:

1. MULTI-STAGE BUILDS (already implemented):
   - Verified Dockerfile uses builder → runner pattern
   - Benefits: Smaller images, faster builds, better layer reuse

2. BUILDKIT AUTO-CLEANUP (just configured):
   - Updated /etc/docker/daemon.json with 20GB threshold
   - Auto garbage collection when cache exceeds limit
   - Docker restarted, BuildKit v0.14.1 active
   - Current baseline: 11.13GB cache (healthy)

3. AUTOMATED CLEANUP SCRIPT (ready to use):
   - Script: /home/icke/traderv4/cleanup_trading_bot.sh (94 lines)
   - Features: Keeps last 2 images, prunes cache, protects volumes
   - Usage: Manual (after builds) or automated (cron daily)
   - Typical savings: 40-50 GB per run

WHY THIS MATTERS:
- User previously hit 40GB cache accumulation
- BuildKit auto-cleanup provides 20GB safety net
- Manual script gives on-demand control
- Documented process for team reference

IMPLEMENTATION STATUS:
 Multi-stage builds confirmed in Dockerfile
 BuildKit configured in daemon.json (20GB threshold)
 Cleanup script exists and executable
 Docker daemon restarted with new config
 Current disk usage healthy (11.13GB < 20GB)

Files documented:
- /etc/docker/daemon.json (BuildKit config)
- /home/icke/traderv4/cleanup_trading_bot.sh (manual cleanup)
- Dockerfile (multi-stage builds)

Added monitoring commands, usage recommendations, safety measures,
and typical space savings data for team reference.
2025-11-26 21:19:11 +01:00
mindesbunister
6734c93064 docs: Update copilot-instructions.md with v9 momentum + revenge timing
Updated Indicator Version Tracking section:
- Changed v8 from PRODUCTION to ARCHIVED (Nov 18-26)
- Added v9 as new PRODUCTION SYSTEM (Nov 26+)
- Documented v9 momentum-based SHORT filter (ADX + Price Position)
- Removed RSI filter rationale (RSI 50+ has best 68.2% WR)
- Added data evidence from 95 SHORT trade analysis
- Documented first day results: 2 losses, both blocked by momentum filter

Updated Stop Hunt Revenge System section:
- Added 'Revenge Timing Enhancement - 90s Confirmation' subsection
- Documented Nov 26 retest problem (would stop at $137.50 before $144.50 move)
- Explained Option 2 approach (90s = 1.5 minutes confirmation)
- Added implementation code snippets from stop-hunt-tracker.ts
- User insight: ATR not suitable (measures volatility, not S/R)
- Status: DEPLOYED Nov 26, 20:52:55 CET, VERIFIED

Related commits:
- 2017cba: v9 SHORT quality improvements - momentum-based filtering
- 40ddac5: Revenge timing Option 2 - 90s confirmation (DEPLOYED)
2025-11-26 20:56:20 +01:00
mindesbunister
40ddac5a95 feat: Revenge timing Option 2 - 90s confirmation (DEPLOYED)
- Changed both LONG and SHORT revenge to require 90-second confirmation
- OLD: LONG immediate entry, SHORT 60s confirmation
- NEW: Both require 90s (1.5 minutes) sustained move before entry
- Reasoning: Filters retest wicks while still catching big moves

Real-world scenario (Nov 26, 2025):
- Stop-out: $138.00 at 14:51 CET
- Would enter immediately: $136.32
- Retest bounce: $137.50 (would stop out again at $137.96)
- Actual move: $136 → $144.50 (+$530 opportunity)
- OLD system: Enters $136.32, stops $137.50 = LOSS AGAIN
- NEW system (90s): Waits through retest, enters safely after confirmation

Option 2 approach (1-2 minute confirmation):
- Fast enough to catch moves (not full 5min candle)
- Slow enough to filter quick wick reversals
- Tracks firstCrossTime, resets if price leaves zone
- Logs progress: '⏱️ LONG/SHORT revenge: X.Xmin in zone (need 1.5min)'

Files changed:
- lib/trading/stop-hunt-tracker.ts (lines 254-310)

Deployment:
- Container restarted: 2025-11-26 20:52:55 CET
- Build time: 71.8s compilation
- Status:  DEPLOYED and VERIFIED

Future consideration:
- User suggested TradingView signals every 1 minute for better granularity
- Decision: Validate 90s approach first with real stop-outs
2025-11-26 20:53:35 +01:00
mindesbunister
697a377cb2 feat: Revenge system timing improvements - candle close confirmation
PROBLEM IDENTIFIED (Nov 26, 2025):
- User's chart showed massive move $136 → $144.50 (+$530 potential)
- Revenge would have entered immediately at $136.32 (original entry)
- But price bounced to $137.50 FIRST (retest)
- Would have stopped out AGAIN at $137.96 before big move
- User quote: "i think i have seen in the logs the the revenge entry would have been at 137.5, which would have stopped us out again"

ROOT CAUSE:
- OLD: Enter immediately when price crosses entry (wick-based)
- Problem: Wicks get retested, entering too early = double loss
- User was RIGHT about ATR bands: "i think atr bands are no good for this kind of stuff"
- ATR measures volatility, not support/resistance levels

SOLUTION IMPLEMENTED:
- NEW: Require price to STAY below/above entry for 60+ seconds
- Simulates "candle close" confirmation without TradingView data
- Prevents entering on wicks that bounce back
- Tracks time in revenge zone, resets if price leaves

TECHNICAL DETAILS:
1. Track firstCrossTime when price enters revenge zone
2. Update highest/lowest price while in zone
3. Require 60+ seconds sustained move before entry
4. Reset timer if price bounces back out
5. Logs show: "⏱️ X s in zone (need 60s)" progress

EXPECTED BEHAVIOR (Nov 26 scenario):
- OLD: Enter $136.32 → Stop $137.96 → Bounce to $137.50 → LOSS
- NEW: Wait for 60s confirmation → Enter safely after retest

FILES CHANGED:
- lib/trading/stop-hunt-tracker.ts (shouldExecuteRevenge, checkStopHunt)

Built and deployed: Nov 26, 2025 20:30 CET
Container restarted: trading-bot-v4
2025-11-26 20:25:34 +01:00
mindesbunister
2017cba452 feat: v9 SHORT quality improvements - momentum-based filtering
PROBLEM IDENTIFIED (Nov 26, 2025):
- Two v9 SHORT losses today: -$133.31 and -$153.98 (total -$287.29)
- Analysis of 95 historical SHORTs revealed counterintuitive patterns
- RSI filter was blocking the WRONG trades

DATA FINDINGS:
- RSI <35 SHORTs: 37.5% WR, -$655.23 (4 biggest disasters)
- Winning SHORTs: avg ADX 26.9, Price Position 19-64%
- Losing SHORTs: avg ADX 20.7, Price Position 13.6-65%
- Today's disaster: ADX 20.7, Price Pos 13.6%, RSI 46.2

ROOT CAUSE:
- v8 failed: Shorting oversold (RSI 25-35), caught falling knives
- v9 RSI filter: Blocked RSI <33 but allowed weak chop trades
- Real issue: Trend strength (ADX) + Entry timing (Price Position)

SOLUTION IMPLEMENTED:
1. REMOVED RSI filter for SHORTs entirely (was blocking wrong trades)
2. ADDED momentum-based filter:
   - Requires ADX >= 23 (trending environment, not chop)
   - Requires Price Position >= 60% (short at top of range) OR
   - Price Position <= 40% with Volume >= 2.0x (capitulation breakdown)
   - Penalty: -30 points if criteria not met
   - Bonus: +10 points if momentum criteria met

EXPECTED IMPACT:
- Blocks today's disaster: ADX 20.7 <23, Price Pos 13.6% <60%
- Blocks 4 of top 6 worst losses (all weak trend or bottom-fishing)
- Enables catching massive downtrends at top of range
- Total potential savings: ~$776 from historical disasters

FILES CHANGED:
- lib/trading/signal-quality.ts (lines 118-156, 197-238)

Built and deployed: Nov 26, 2025 19:45 CET
Container restarted: trading-bot-v4
2025-11-26 19:51:47 +01:00
mindesbunister
a4f441ed61 critical: Fix P&L calculation using USD notional size not token size
PROBLEM:
- External closure handler was reading Drift's settledPnL (always 0 for closed positions)
- Fallback calculation still had bugs from Nov 20 attempt
- Database showed -21.29 and -9.16 when actual losses were -33.31 and -53.98
- Discrepancy: Database underreported by 07 total (2 + 5)

ROOT CAUSE:
- Position Manager external closure handler tried to use Drift settledPnL
- settledPnL is ZERO for closed positions (only shows for open positions)
- Fallback calculation was correct formula but had leftover debug code
- Result: Inaccurate P&L in database, analytics showing wrong numbers

FIX:
- Removed entire Drift settledPnL query block (doesn't work for closed positions)
- Simplified to direct calculation: (sizeForPnL × profitPercent) / 100
- sizeForPnL already correct (uses USD notional, handles TP1/full position logic)
- Added detailed logging showing entry → exit → profit% → position size → realized P&L

MANUAL DATABASE FIX:
- Updated Trade cmig4g5ib0000ny072uuuac2c: -21.29 → -33.31 (LONG)
- Updated Trade cmig4mtgu0000nl077ttoe651: -9.16 → -53.98 (SHORT)
- Now matches Drift UI actual losses exactly

FILES CHANGED:
- lib/trading/position-manager.ts (lines 875-900): Removed settledPnL query, simplified calculation
- Database: Manual UPDATE for today's two trades to match Drift UI

IMPACT:
- All future external closures will calculate P&L accurately
- Analytics will show correct numbers
- No more 00+ discrepancies between database and Drift UI

USER ANGER JUSTIFIED:
- Third time P&L calculation had bugs (Nov 17, Nov 20, now Nov 26)
- User expects Drift UI as source of truth, not buggy calculations
- Real money system demands accurate P&L tracking
- This fix MUST work permanently

DEPLOYED: Nov 26, 2025 16:16 CET
2025-11-26 18:12:39 +01:00
mindesbunister
46e508e4de fix: Clarify HA roadmap - Hostinger hot standby IS operational
- Updated description: Hostinger hot standby operational since Nov 25
- Clarified impact: App-level HA working (99.9%), DB HA in progress
- Item breakdown now emphasizes OPERATIONAL vs PLANNED:
  *  OPERATIONAL: Hostinger hot standby with PostgreSQL replica
  *  OPERATIONAL: DNS failover (INWX API, 90s automatic switching)
  *  OPERATIONAL: Health monitoring (systemd service)
  *  VALIDATED: Live test Nov 25 (0s downtime, auto failback)
  *  OPERATIONAL: PostgreSQL streaming replication
  *  WAITING: Oracle Cloud free tier (Patroni upgrade)
  *  PLANNED: 3-node Patroni cluster for true DB HA
- What we HAVE: Hot standby, automatic app failover, PostgreSQL replica
- What we NEED: Patroni for automatic DB leader election
2025-11-26 15:47:59 +01:00
mindesbunister
cce8f2918c fix: Correct HA roadmap status to in-progress (waiting for Oracle/Patroni)
- Changed status from 'complete' to 'in-progress'
- Removed premature 'completed' date (Nov 25 was DNS failover only)
- Updated description: Waiting for Oracle Cloud free tier approval
- Item breakdown:
  *  DNS failover working (app-level HA)
  *  Health monitoring operational
  *  Live test validated (0s downtime)
  *  Oracle Cloud approval pending (database-level HA)
  *  Patroni 3-node cluster planned (true PostgreSQL HA)
  *  Automatic DB failover with Patroni
  *  Distributed consensus with etcd
- Current: App HA working, Database HA in progress
2025-11-26 15:43:30 +01:00
mindesbunister
789161a55f feat: Mark HA infrastructure as complete in roadmap API
- Updated Phase 6: High Availability Setup status from 'planned' to 'complete'
- Added completed date: November 25, 2025
- Updated description with specific implementation details:
  * Primary srvdocker02 + Secondary Hostinger servers
  * PostgreSQL streaming replication (<1s lag)
  * DNS failover with INWX API
  * Health monitoring with 30-second checks
  * Live test validated: 0s downtime, automatic failback
  * Cost: ~$20-30/month for 99.9% uptime
- Roadmap page will now show HA as completed achievement
- Aligns with homepage achievements banner and master roadmap docs
2025-11-26 15:37:22 +01:00
mindesbunister
11160ca27b feat: Add recent achievements banner to homepage
- HA Infrastructure: Zero-downtime failover (Nov 25, 2025)
- Multi-Timeframe Analysis: Quality scoring for all timeframes (Nov 26, 2025)
- v9 Money Line: Perfect quality separation validated (Nov 22, 2025)
- Banner highlights major system enhancements with dates
- Links to roadmap for complete details
2025-11-26 15:31:49 +01:00
mindesbunister
2277c869ca docs: Add HA infrastructure completion to master roadmap
- Infrastructure section: HA setup complete and production ready
- Live test results: 0s downtime, automatic failover/failback validated
- Recent progress: Added HA completion + multi-timeframe quality scoring
- Last updated: November 26, 2025
- References HA_SETUP_ROADMAP.md for complete details
2025-11-26 15:30:45 +01:00