<?php
namespace Forcast;

function run_detectors(array $bars,int $i): array {
  // einfache, erklärbare Muster
  $c=array_column($bars,'c'); $v=array_column($bars,'v');
  $sma50=sma($c,50); $sma200=sma($c,200);
  $vol_sma50=sma($v,50);

  $signals=[];
  // Breakout 52W + Volumen
  $s=max(0,$i-251); $mx=max(array_slice($c,$s,$i-$s+1));
  $is_breakout = $c[$i] >= $mx && ($vol_sma50[$i]>0 ? $v[$i]/$vol_sma50[$i] >= 1.5 : false);
  if($is_breakout) $signals[]=['id'=>'breakout_52w','confidence'=>0.7];

  // Mean Reversion im Aufwärtstrend
  $pull = ($c[$i] < $sma50[$i]*0.97) && ($c[$i] > $sma200[$i]);
  if($pull) $signals[]=['id'=>'mean_rev_uptrend','confidence'=>0.55];

  // Trend-Continuation (MA-Stacked)
  $stack = $sma50[$i] > $sma200[$i] && $c[$i] > $sma50[$i];
  if($stack) $signals[]=['id'=>'trend_continue','confidence'=>0.6];

  return $signals;
}