o
    çÚj2  ã                   @   s~   d Z i dd“dd“dd“dd“d	d
“dd“dd“dd“dd“dd“dd“dd“dd“dd“dd“dd“Zdd „ Zd$d"d#„Zd!S )%a1  
r9_setup.py -- [2026-10-23, v2 the user: "buy after the reversal around 10:00", not at the stop] R9 "REVERSAL AFTER A SELLING CLIMAX" (from the SOUN 3/27/2026 practice chart,
ATR 7.8%: a drift up to 6.07 (9:48), then a sharp sell-off 6.07 -> 5.86 with four heavy selling bars 9:52-9:57 (1.6-4.0x
volume, 26-38% buyers); the fall stopped (lows 5.88 / 5.87 / 5.86 / 5.86), 9:58 traded a third of the biggest climax bar with
buyers back to 50% -> buy 9:59 open ~5.88, +2% around 10:51; the user's entry "9:55-9:58"). The EARLIEST entry of all the
setups: no base, no bounce, no retest -- so it needs the climax AND the stop.
  1 SELL-OFF   from the high of the last high_bars (20) bars down >= max(drop_pct 2%, drop_atr 0.3 x ATR %)
  2 CLIMAX     >= climax_n (3) of the last climax_bars (6) bars with >= climax_vol_x (1.5x) normal volume and <= climax_bs
               (40%) buyers
  3 STOPPED    the day's low of the sell-off was made within rev_max (8) bars before the trigger and no bar since went under it
  4 REVERSAL   the trigger bar closes above the highs of the rev_bars (3) bars before it, with buyers >= turn_bs (55%) and
               volume <= fade (50%) of the biggest climax bar (no new selling wave)
  5 ROOM       the sell-off's high >= room_pct (2%) above the close
  safety       >= min_spm shares/min; 9:45-14:30; cool-down 30 min
When R9 is true these v2 rules do NOT apply: RVOL, 15-min buy share / steady trend, price >= VWAP, below the open.
Our earlier V-turn tests (10/10) lost on average -- R9 is the riskiest setup; the 2-year test decides. Pure function.
Ú	high_barsé   Údrop_pctg       @Údrop_atrg333333Ó?Úclimax_né   Úclimax_barsé   Úclimax_vol_xg      ø?Ú	climax_bsgš™™™™™Ù?Úrev_maxé   Úrev_barsÚfadeg      à?Úturn_bsgš™™™™™á?Úroom_pctÚmin_spmiÐ  Úfirst_mé   Úlast_mi,  Úcooldowné   c                 C   sZ   ddl m }m} ddlm} t| |ƒs| | |j¡} |  |dƒ¡} | jd d | j	 d S )Né    )ÚdatetimeÚtimezone)ÚZoneInfozAmerica/New_Yorké	   é<   r   )
r   r   Úzoneinfor   Ú
isinstanceÚfromtimestampÚutcÚ
astimezoneÚhourÚminute)Útr   r   r   © r%   úr9_setup.pyÚ_minute   s   
r'   Nc              
      sŒ  i t ¥|pi ¥}|pi }tˆ ƒ}||d k s"||d ks"||d k r&di fS | d¡r:| d¡r:|d |d  d nd }|sBdi fS |d |d	 }}| d
¡pQg }	dd„ ˆ D ƒ}
tdd„ ˆ |d  d … D ƒƒ}ˆ d d }tdd„ ˆ |d  d … D ƒƒ}|| d d }|t|d |d | ƒk rŸddd|d›d�ifS tt||d  |ƒ‡ fdd„d�}|d | |d ksÀ||d krÆdddifS g }ttd||d  d ƒ|d ƒD ]<}|
| }|| ||  }|t|	ƒk �r|	| �rˆ | d  |d! |	|  k�r|�r|| | |d" k�r| |¡ qØt|ƒ|d# k �r*ddd$t|ƒ› d%�ifS || ||  }t‡ fd&d„|D ƒƒ}|td'd„ ˆ d|d(  d… D ƒƒk�rWddd)ifS |�rr|| | |d* k �srˆ d d  |d+ | k�rxddd,ifS || d d }||d- k �r’ddd.|d›d/�ifS td0d„ ˆ d1d … D ƒƒd2 |d3 k �r¬ddd4ifS d5||
| |t|d6ƒt|ƒ|d | t|d6ƒd7œfS )8Nr   r   r   FÚatr14Ú
prev_closeéd   ÚbuyÚsellÚvol_per_minc                 S   s   g | ]}t |d  ƒ‘qS )r$   )r'   )Ú.0Úbr%   r%   r&   Ú
<listcomp>+   s    zcheck.<locals>.<listcomp>c                 s   ó   � | ]}|d  V  qdS ©ÚhNr%   ©r.   Úxr%   r%   r&   Ú	<genexpr>,   ó   € zcheck.<locals>.<genexpr>éÿÿÿÿÚcc                 s   r1   )ÚlNr%   r4   r%   r%   r&   r6   .   r7   é   r   r   Úwhy_notz1 sell-off z.1fz% too smallc                    s   ˆ |  d S )Nr:   r%   )Új©Údoner%   r&   Ú<lambda>3   s    zcheck.<locals>.<lambda>)Úkeyr   z'3 the low is not recent / still fallingr   r   Úvr	   r
   r   z2 only z climax barsc                 3   s   � | ]	}ˆ | d  V  qdS ©rB   Nr%   )r.   r=   r>   r%   r&   r6   @   s   € c                 s   r1   r2   r%   r4   r%   r%   r&   r6   A   r7   r   z4 no reversal closer   r   z,4 reversal without buyers / new selling waver   z5 room ú%c                 s   r1   rC   r%   r4   r%   r%   r&   r6   H   r7   éûÿÿÿé   r   ÚthinTé   )ÚsupportÚ	support_mÚhighÚdropr   Úbars_after_lowÚroom)	ÚDEFAULTSÚlenÚgetÚmaxÚminÚrangeÚappendÚsumÚround)r?   ÚflowÚrefÚmr9   ÚnÚatrpÚfbÚfsÚvpmÚminsÚHÚPÚlowestrL   ÚjlÚclr=   ÚkÚt_ÚbigrN   r%   r>   r&   Úcheck    sT   $,  " $R
€(6(
"ÿri   )N)Ú__doc__rO   r'   ri   r%   r%   r%   r&   Ú<module>   s0    &ÿÿÿÿÿÿÿþþþ	