o
    ¯ÎÚ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“Zd d!„ Zd%d#d$„Zd"S )&a  
r1a_setup.py -- [2026-10-22] The user's setup R1A "FAST DOUBLE BOTTOM AFTER A FLUSH" -- a version of R1 for the quick retest
(from the HELP 7/3/2025 practice chart: gap +7.7%, ATR 9.5%; 9:48-9:49 flush on 14.4x / 12.6x volume to 7.55, bounce to
7.69-7.73, sellers back, retest of 7.55 at 9:53-9:54 on far less volume, then the recovery to 7.90 by 10:10; "+2% before
-1%" zone 9:53-10:07). R1 missed it: its support must be 10+ bars old and its bounce >= 1/4 ATR.
  1 FLUSH      a bar in the last flush_window (15) bars with >= flush_vol_x (3x) normal volume, sellers >= flush_sell
               (60%), that made the day's low so far (the flush low)
  2 BOUNCE     after the flush low, a bounce >= max(bounce_pct 1%, bounce_atr 0.15 x daily ATR %)
  3 RETEST     within retest_max (10) bars of the flush, a low back within near_pct (0.4%) of the flush low, not broken by
               more than break_pct (0.3%)
  4 WEAKER     volume of the retest bars <= retest_vol (0.5) x the flush bar's volume (the sellers are spent)
  5 TURN       the trigger bar (the retest bar or a bar after it) closes above the bar before with buyers >= turn_bs (55%)
  6 ROOM       the higher of VWAP and the open >= room_pct (2%) above the close
  safety       >= min_spm shares/min over 5 bars; <= max_under_vwap (4%) under VWAP (a flush pushes the price under it);
               9:40-14:30; one trigger per flush
When R1A is true these v2 rules do NOT apply: RVOL, 15-min buy share / steady trend, price >= VWAP, below the open.
Untested on 2 years. Pure function, no orders.
Úflush_windowé   Úflush_vol_xg      @Ú
flush_sellg333333ã?Ú
bounce_pctg      ð?Ú
bounce_atrg333333Ã?Ú
retest_maxé
   Únear_pctgš™™™™™Ù?Ú	break_pctg333333Ó?Ú
retest_volg      à?Úturn_bsgš™™™™™á?Úroom_pctg       @Úmin_spmiÐ  Úmax_under_vwapg      @Ú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 )z¸minutes since 9:30 ET of a bar time (datetime or epoch seconds) -- [2026-10-22] flow is looked up by the bar's own
    minute, not its position (thin stocks have minutes without a bar)é    )ÚdatetimeÚtimezone)ÚZoneInfozAmerica/New_Yorké	   é<   é   )
r   r   Úzoneinfor   Ú
isinstanceÚfromtimestampÚutcÚ
astimezoneÚhourÚminute)Útr   r   r   © r#   úr1a_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 |d }}| d¡p3g ‰||d  }‡fd	d
„}	| d¡rT| d¡rT|d |d  d nd}
d }ttd|d |d  ƒ|d ƒD ]E}ˆ | }t|d ƒ}|| ||  }|	|ƒr­|d |d |	|ƒ kr­|r­|| | |d kr­|d tdd„ ˆ d |… D ƒƒd kr­|}qh|d u r¸dddifS tt|t|d |d ƒƒ‡ fdd
„d�}ˆ | d }ˆ |d d … }t|ƒdk rædddifS tt|d |ƒƒ}|s÷dddifS t|‡ fdd
„d�}tt|d |ƒƒ}|�sddd ifS t|‡ fd!d
„d�}ˆ | d" | d d }t|d# |d$ |
 ƒ}||k �rHddd%|d&›d'|d&›d(�ifS ˆ | d | d d }||d) k�sc||d*  k �rnddd+|d,›d-�ifS || |d. k�r}ddd/ifS t‡ fd0d„t||ƒD ƒƒ}||d1 ˆ | d  k�r¯ddd2|d3›d4|d1 › d5ˆ | d d3›�ifS || ||  }ˆ d6 d7 ˆ d8 d7 k�rÒ|�rÒ|| | |d9 k�sØddd:ifS ˆ d6 d7 }td;d„ ˆ D ƒƒ}td<d„ ˆ D ƒƒ}|�r÷|| n|}t|ˆ d= d> ƒ| d d }||d? k �rddd@|d&›d(�ifS tdAd„ ˆ dBd … D ƒƒdC |dD k �r4dddEifS || d d |dF  k �rHdddGifS dH|tˆ | d ƒtˆ | d ƒˆ | d t	|dƒt	|dƒt	|dƒt	|dIƒdJœfS )KNr   r   é   FÚbuyÚsellÚvol_per_miné   c                    s$   ˆ rˆ t t| dƒtˆ ƒd ƒ S dS )Nr   r*   )ÚminÚmaxÚlen)Úk)Úvpmr#   r$   Ú<lambda>,   s   $ zcheck.<locals>.<lambda>Úatr14Ú
prev_closeéd   g        r   r"   Úvr   r   Úlc                 s   ó   � | ]}|d  V  qdS )r5   Nr#   ©Ú.0Úxr#   r#   r$   Ú	<genexpr>3   ó   € zcheck.<locals>.<genexpr>g5^ºIð?Úwhy_notz
1 no flushé   c                    ó   ˆ |  d S ©Nr5   r#   ©Új©Údoner#   r$   r0   8   ó    )Úkeyz2 no bounce yetz3 no retest yetc                    r>   r?   r#   r@   rB   r#   r$   r0   A   rD   z2 no bounce between the lowsc                    r>   )NÚhr#   r@   rB   r#   r$   r0   E   rD   rF   r   r   z	2 bounce z.1fz% < ú%r	   r
   z	3 retest z+.2fz% from the flush lowr   z 3 retest too late (R1 territory)c                 3   s   � | ]	}ˆ | d  V  qdS ©r4   Nr#   )r8   rA   rB   r#   r$   r:   P   s   € r   z4 retest volume z.0fz not < z	 x flush éÿÿÿÿÚcéþÿÿÿr   z5 no turn barc                 s   s4   � | ]}|d  |d  |d  d |d  V  qdS )rF   r5   rJ   é   r4   Nr#   r7   r#   r#   r$   r:   X   s   €2 c                 s   r6   rH   r#   r7   r#   r#   r$   r:   X   r;   r   Úor   z6 room c                 s   r6   rH   r#   r7   r#   r#   r$   r:   ]   r;   éûÿÿÿé   r   Úthinr   ztoo far under VWAPTé   )ÚsupportÚ	support_mÚflush_mÚ	flush_volÚbounceÚretest_nearÚroomÚvwap)
ÚDEFAULTSr-   ÚgetÚranger,   r%   r+   ÚlistÚsumÚround) rC   ÚflowÚrefÚmrJ   ÚnÚfbÚfsÚm0ÚnormÚatrpÚfjrA   Úbr.   Út_ÚljÚLÚafterÚcandÚrjÚmidÚhjrV   ÚneedÚnearÚrvÚPÚpvÚcvrY   rX   r#   )rC   r/   r$   Úcheck#   sx    ,$$8&€(
.6$(2ÿry   )N)Ú__doc__rZ   r%   ry   r#   r#   r#   r$   Ú<module>   s4     ÿÿÿÿÿÿþþþþþ