#!/bin/bash
# [2026-09-30] X1 volume-climax exit test: smooth only vs smooth + X1, on v2's fixed entries (23 days) + 9/30 live buys
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 --entry-v2 --exit-v2 --xv2-set trail=false"
END=$(date -d "tomorrow 09:15" +%s); [ $(date +%H) -lt 9 ] && END=$(date -d "today 09:15" +%s)
for d in $(ls $T/cands/ | sed 's/.json//' | awk '$1>="2026-08-27" && $1<="2026-09-29"' | sort) 2026-09-30; do
  if [ $d = 2026-09-30 ]; then F=$S/live_2026-09-30_fixed.json; C=/tmp/claude-0/-var-www-screener-trade/5844eef7-c648-46de-a03c-fe0b1434b640/scratchpad/cands_0930_live.json
  else F=$S/${d}_sim_maxpos99_gr_r25_es0p_rs45_reabove_entry_v2_cf.json; C=$T/cands/$d.json; fi
  G=""; [ $d = 2026-09-22 ] && G="--synthetic-grid"
  for v in smooth x1; do
    X=""; [ $v = x1 ] && X="--xv2-set climax_exit=true"
    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 $X $G --fixed-entries $F --candidates-file $C > $T/out/x1test_${v}_$d.out 2>&1
    echo "$v $d $(grep 'total:' $T/out/x1test_${v}_$d.out)"
  done
done
echo X1_DONE
