#!/bin/bash
# [2026-09-29] overnight tests for the 9/30 setup. Every signal (--max-positions 99). Stops 9:15 ET.
cd /var/www/screener/trade
T=/var/www/screener/trade/reports/open_window/tick20
S=/var/www/screener/trade/data/simulations
BASE="--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)
run() {  # tag, extra args, day
  local tag=$1 extra=$2 d=$3 G=""; [ $d = 2026-09-22 ] && G="--synthetic-grid"
  local left=$(( END - $(date +%s) )); [ $left -lt 60 ] && { echo "stopped at 9:15"; exit 0; }
  timeout $left nice -n 5 python3 simulate.py --date $d $BASE $G --candidates-file $T/cands/$d.json $extra > $T/out/${tag}_$d.out 2>&1
  echo "$tag $d $(grep 'total:' $T/out/${tag}_$d.out)"
}
DAYS=$(ls $T/cands/ | sed 's/.json//' | awk '$1>="2026-08-27"' | sort)
# B: exit_v2 on the v2 baseline's fixed entries (baseline J exits = run_v2.log + v2 2026-09-29)
for d in $DAYS; do run xv2fixed "--exit-v2 --fixed-entries $S/${d}_sim_maxpos99_gr_r25_es0p_rs45_reabove_entry_v2_cf.json" $d; done
# C: entries -- v2 + playbook + 3% rule (config), J exits
for d in $DAYS; do run v2pbext "--playbook" $d; done
# A: tomorrow's full setup -- v2 + playbook + 3% rule + exit_v2
for d in $DAYS; do run live0930 "--playbook --exit-v2" $d; done
# D: exit_v2 parts on the fixed entries
for d in $DAYS; do run xsmooth "--exit-v2 --xv2-set trail=false --fixed-entries $S/${d}_sim_maxpos99_gr_r25_es0p_rs45_reabove_entry_v2_cf.json" $d; done
for d in $DAYS; do run xtrail "--exit-v2 --xv2-set smooth=false --fixed-entries $S/${d}_sim_maxpos99_gr_r25_es0p_rs45_reabove_entry_v2_cf.json" $d; done
echo OVERNIGHT_DONE
