o
    BsÛj¾  ã                   @   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“dd“d d!d"œ¥Zd#d$„ Zd(d&d'„Zd%S ))a`  
r1b_setup.py -- [2026-10-23] The user's setup R1B "UNDERCUT AND RECLAIM AFTER A FLUSH (deep V / spring)" (from PEPG 10/1/2025:
10:02 flush to 4.67 on 4.4x volume with 28% buyers, bounce to ~4.79, a second push 10:06-10:09 that UNDERCUT the flush low to
4.63 (10:08: 5% buyers), then the reclaim -- 10:09 85% buyers, 10:10 +2.4% in one bar with 68% buyers -- and a quiet hold
4.75-4.80 (10:11-10:16). The user's entry ~10:15 at ~4.775; the trade lives on the V LOW (4.63): its stop belongs under it
(~3% here), so the 10:40 dip to 4.695 does not shake it out, and it reached 4.918 (+3%) at 11:14.
A version of R1A (fast double bottom) for a retest that BREAKS the flush low a little and snaps back.
  1 FLUSH      a bar within flush_window (20) bars: >= flush_vol_x (3x) normal volume, >= flush_sell (60%) sellers, a new day low
  2 BOUNCE     after the flush low a bounce >= max(bounce_pct 1%, bounce_atr 0.15 x daily ATR %)
  3 UNDERCUT   a second push below the flush low by no more than max(under_pct 1.5%, under_atr 0.25 x ATR %) -- the V low
  4 RECLAIM    within reclaim_max (4) bars of the V low: a bar closing back ABOVE the flush low, gaining >= max(rec_pct 1.5%,
               rec_atr 0.15 x ATR %) from its open, with buyers >= rec_bs (60%)
  5 HOLD       hold_min..hold_max (2..6) bars after the reclaim bar staying within hold_pct (1.2%) of the reclaim high and never
               back under the flush low, on volume <= the reclaim bar's -> buy on the bar that completes the hold
  6 ROOM       VWAP or the open >= room_pct (2%) above
  STOP         under the V low (info "stop" = V low x 0.998) -- not a fixed %
  safety       >= min_spm shares/min; 9:45-14:30; one trigger per V (cool-down)
When R1B is true these v2 rules do NOT apply: RVOL, 15-min buy share / steady trend, price >= VWAP, below the open.
NOT run yet (the user: build only). Pure function, no orders.
Úflush_windowé   Úflush_vol_xg      @Ú
flush_sellg333333ã?Ú
bounce_pctg      ð?Ú
bounce_atrg333333Ã?Ú	under_pctg      ø?Ú	under_atrg      Ð?Úreclaim_maxé   Úrec_pctÚrec_atrÚrec_bsÚhold_miné   Úhold_maxé   Úhold_pctg333333ó?Úroom_pctg       @Úmin_spmiÐ  Úfirst_mé   i,  é   )Úlast_mÚcooldownc                 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(   úr1b_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¡r8| d¡r8|d |d  d nd }|s@di fS |d |d	 ‰‰| d
¡pOg }dd„ ˆD ƒ‰‡‡‡fdd„}tt|ƒ‡fdd„d�}	ˆ|	 d }
|d |	 ˆd ˆd  ksƒ|	dk r‰dddifS d }ttd|	ˆd  ƒ|	ƒD ]?}ˆ| }|t|ƒk rÖ|| rÖˆ| d ˆd ||  krÖd||ƒ ˆd krÖˆ| d tdd„ ˆd |… D ƒƒd krÖ|}q—|d u rádddifS t‡fd d„t|t|d! |	ƒƒD ƒƒ‰ ˆ |
 d d }|d"k�s|tˆd# ˆd$ | ƒk�r'ddd%|d&›d'tˆd# ˆd$ | ƒd&›d(�ifS t|d |	ƒ}|�rNt‡fd)d„|D ƒƒˆ  d d tˆd* ˆd+ | ƒk �rTddd,ifS d ‰t|	t|	ˆd  d |ƒƒD ]3}ˆ| }|d- ˆ k�r–|d- |d.  d d tˆd/ ˆd0 | ƒk�r–||ƒˆd1 k�r–|‰ n�qdˆd u �r£ddd2ifS ttˆd |ƒƒ}ˆd3 t|ƒ  k�r¾ˆd k�sËn ddd4t|ƒ› d5�ifS t‡fd6d„tˆ|ƒD ƒƒ‰t‡ ‡fd7d„|D ƒƒ�st‡‡‡fd8d„|D ƒƒ�st‡‡fd9d„|D ƒƒ�rddd:ifS ˆd; d- }td<d„ ˆD ƒƒ}td=d„ ˆD ƒƒ}|�r&|| n|}t|ˆd" d. ƒ| d d }|ˆd> k �rIddd?|d@›dA�ifS tdBd„ ˆdCd … D ƒƒdD ˆdE k �rcdddFifS dG|
ˆ|	 t	|
dH dIƒˆ ˆ| t	|d!ƒˆˆ t	|d!ƒdJœfS )KNr   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@   ˆ ˆ|   ˆˆ|    rˆ ˆ|   ˆ ˆ|   ˆˆ|     S dS )Ng      à?r(   ©Új)ÚfbÚfsÚminsr(   r)   Ú<lambda>0   s   @ zcheck.<locals>.<lambda>c                    s   ˆ |  d S )NÚlr(   r5   ©Údoner(   r)   r:   2   s    )Úkeyr;   é   r	   r   é   Úwhy_notz3 no recent V lowr   Úvr   r   c                 s   ó   � | ]}|d  V  qdS ©r;   Nr(   ©r2   Úxr(   r(   r)   Ú	<genexpr>:   ó   € zcheck.<locals>.<genexpr>g5^ºIð?z1 no flush before the Vc                 3   ó   � | ]	}ˆ | d  V  qdS rD   r(   ©r2   r6   r<   r(   r)   rG   >   ó   € r   r   r   r   z3 undercut z.2fz% (needs 0..z%)c                 3   rI   ©ÚhNr(   rJ   r<   r(   r)   rG   D   rK   r   r   z'2 no bounce between the flush and the VÚcÚor   r   r   z4 no reclaim barr   z5 hold z barsc                 3   rI   rL   r(   rJ   r<   r(   r)   rG   R   rK   c                 3   s    � | ]}ˆ| d  ˆ k V  qdS rD   r(   rJ   )ÚFr=   r(   r)   rG   S   s   € c                 3   s0   � | ]}ˆ ˆ| d   d d ˆd kV  qdS )rN   r?   r.   r   Nr(   rJ   )ÚRHrN   r=   r(   r)   rG   S   s   €. c                 3   s(   � | ]}ˆ | d  ˆ ˆ d  kV  qdS ©rB   Nr(   rJ   )r=   Újrr(   r)   rG   T   s   €& z5 the hold did not holdéÿÿÿÿc                 s   s4   � | ]}|d  |d  |d  d |d  V  qdS )rM   r;   rN   r@   rB   Nr(   rE   r(   r(   r)   rG   W   s   €2 c                 s   rC   rR   r(   rE   r(   r(   r)   rG   W   rH   r   z6 room z.1fú%c                 s   rC   rR   r(   rE   r(   r(   r)   rG   \   rH   éûÿÿÿé   r   ÚthinTgV-²�ïï?r
   )ÚsupportÚ	support_mÚstopÚ	flush_lowÚflush_mÚundercutÚ	reclaim_mÚroom)
ÚDEFAULTSÚlenÚgetÚminÚrangeÚmaxÚlistÚanyÚsumÚround)r=   ÚflowÚrefÚmrN   ÚnÚatrpÚvpmÚbsÚjvÚVÚjfr6   ÚkÚunderÚmidr3   ÚholdÚPÚpvÚcvÚvwapr`   r(   )rP   rQ   rN   r=   r7   r8   rS   r9   r)   Úcheck$   sv    ,$D*€&&0@ P€
&6ÿ$(ÿr}   )N)Ú__doc__ra   r*   r}   r(   r(   r(   r)   Ú<module>   s>     ÿÿÿÿÿÿþþþþþþý	