#!/bin/bash
# [2026-10-06] user: trade bot's 1% stop too tight (CTVA, RDW stopped on dips that recovered).
# exit_v2 min_stop_pct 1.5 / 2 / 3 on v2's fixed entries, 24 days; baseline = tests_1002 'arm07' (live exits, 1%)
cd /var/www/screener/trade
L=reports/stop_width_1006.log
T=reports/open_window/tick20
S=data/simulations
END=$(date -d "tomorrow 09:10" +%s)
BASE="--max-positions 99 --entry-v2 --exit-v2 --xv2-set trail=false --xv2-set climax_exit=true --xv2-set smooth_arm=0.7"
for v in 2.0 3.0 1.5; do
  for d in $(ls $T/cands/ | sed 's/.json//' | awk '$1>="2026-08-27" && $1<="2026-09-30"' | sort); do
    [ $(( END - $(date +%s) )) -lt 600 ] && { echo "STOPPED before market hours" >> $L; exit 0; }
    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"
    timeout $(( END - $(date +%s) )) nice -n 5 python3 simulate.py --date $d $BASE --xv2-set min_stop_pct=$v $G --fixed-entries $F --candidates-file $C > $T/out/stop1006_${v}_$d.out 2>&1
    echo "stop$v $d $(grep 'total:' $T/out/stop1006_${v}_$d.out)" >> $L
  done
done
echo STOP_DONE >> $L
