return True
def detect_elliott_waves(self, prices: np.ndarray) -> Dict: """ Main function: returns detected wave structure and validation. """ swings_df = self.find_swing_points(prices) waves = self.label_swing_waves(swings_df) elliott wave python code
A, B, C = waves[:3] # Typical rule: B retraces 0.382 to 0.886 of A retrace_ratio = B['magnitude'] / A['magnitude'] if A['magnitude'] != 0 else 0 if 0.382 <= retrace_ratio <= 0.886: # C often equals A in length (1.0 or 1.618) c_ratio = C['magnitude'] / A['magnitude'] if 0.618 <= c_ratio <= 1.618: return True return False return True def detect_elliott_waves(self, prices: np
# Annotate wave numbers (first 5 waves if exist) waves = result['waves'] for i, wave in enumerate(waves[:5]): mid_idx = (wave['start_idx'] + wave['end_idx']) // 2 mid_price = (wave['start_price'] + wave['end_price']) / 2 plt.text(mid_idx, mid_price, str(i+1), fontsize=12, fontweight='bold', bbox=dict(facecolor='yellow', alpha=0.7)) return True def detect_elliott_waves(self
if impulse_ok: pattern_type = 'impulse_5wave' elif corrective_ok: pattern_type = 'corrective_abc' else: pattern_type = 'unclear'
# Rule 2: Wave 3 not shortest if w3['magnitude'] <= w1['magnitude'] or w3['magnitude'] <= w5['magnitude']: if w3['magnitude'] < w1['magnitude'] and w3['magnitude'] < w5['magnitude']: return False
impulse_ok = self.check_impulse_rules(waves) corrective_ok = self.check_corrective_rules(waves)