// worker.js const history = new Map(); // Clé: SYMBOL_TF const states = new Map(); // Clé: SYMBOL_TF (Phase, Score, Barrière) self.onmessage = function(e) { const { type, data } = e.data; if (type === 'KLINE') { processKline(data); } }; function processKline(k) { const id = `${k.s}_${k.i}`; let candles = history.get(id) || []; // Mise à jour de la bougie en cours ou ajout if (candles.length > 0 && candles[candles.length - 1].t === k.t) { candles[candles.length - 1] = k; } else { candles.push(k); if (candles.length > 100) candles.shift(); } history.set(id, candles); const result = analyze(id, candles); self.postMessage({ type: 'UPDATE', id, ...result }); } function analyze(id, candles) { if (candles.length < 5) return { phase: 0, score: 0 }; const last = candles[candles.length - 1]; const prev = candles[candles.length - 2]; const currentState = states.get(id) || { phase: 0, score: 0, barrier: null, count: 0 }; const body = Math.abs(last.o - last.c); const range = last.h - last.l; const bodyPct = (body / range) * 100; // --- PHASE 3: VERIFICATION BARRIÈRE (Priorité Haute) --- if (currentState.phase === 3) { if ((currentState.direction === 'UP' && last.h > currentState.barrier) || (currentState.direction === 'DOWN' && last.l < currentState.barrier)) { currentState.phase = 0; // Déclassement } } // --- LOGIQUE DES PHASES --- // Phase 1 : Impulsion if (bodyPct > 60 && currentState.phase <= 1) { currentState.phase = 1; currentState.direction = last.c > last.o ? 'UP' : 'DOWN'; currentState.score = 25; } // Phase 2 : Épuisement else if (currentState.phase === 1) { const wickUpper = last.h - Math.max(last.o, last.c); const wickLower = Math.min(last.o, last.c) - last.l; const targetWick = currentState.direction === 'UP' ? (wickUpper / range) * 100 : (wickLower / range) * 100; if (targetWick >= 45 && targetWick <= 60) { currentState.phase = 2; currentState.barrier = currentState.direction === 'UP' ? last.h : last.l; currentState.score = 50; } } // Phase 3 & 4 (Simplifié pour l'exemple) // Ici vous ajouteriez le compteur de bougies et la détection du signal inverse. states.set(id, currentState); return currentState; }