#!/bin/bash
# [2026-09-28] entry rules v2 (entry_v2.py), every signal taken (--max-positions 99), J exits as live.
cd /var/www/screener/trade
T=/var/www/screener/trade/reports/open_window/tick20
J="--max-positions 99 --giveback-room-exit --giveback-room-min-cents 15 --giveback-room-ratio 0.25 --entry-slope-bars 0 --resistance-stall-exit --reentry-after-loss above_entry --entry-v2"
END=$(date -d "tomorrow 09:15" +%s); [ $(date +%H) -lt 9 ] && END=$(date -d "today 09:15" +%s)
for f in $T/cands/*.json; do
  d=$(basename $f .json); G=""; [ $d = 2026-09-22 ] && G="--synthetic-grid"
  left=$(( END - $(date +%s) )); [ $left -lt 60 ] && { echo "stopped at 9:15"; break; }
  timeout $left nice -n 5 python3 simulate.py --date $d $J $G --candidates-file $f > $T/out/v2_$d.out 2>&1
  echo "v2 $d $(grep 'total:' $T/out/v2_$d.out)"
done
echo V2_DONE
