o
    MâÚj(  ã                   @   s>   d Z 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<  
r8_setup.py -- [2026-10-23] The user's setup R8 "FIRST PULLBACK AFTER A REVERSAL OFF THE LOW" (from the RCAT 10/20/2025
practice chart, ATR 15.2%, gap +6%: a quiet bleed 12.52 -> 11.59 (10:19), reversal with buyers 65-73% to 11.84 (10:30), a
QUIET pullback (0.2-0.5x volume, buyers ~50%) to 11.66 = a higher low, 10:40 turn bar with 78% buyers -> buy 10:41 open
11.705, +2% at 10:54; the user's mark "~11.70 after the reversal on the small pullback").
  1 SELL-OFF   the day low L is >= max(drop_pct 3%, drop_atr 0.25 x ATR %) under the day high before it
  2 REVERSAL   within leg_max (20) bars after L a high RH >= max(leg_pct 1%, leg_atr 0.1 x ATR %) above L, buyers >= leg_bs
               (55%) on the reversal bars
  3 PULLBACK   from RH a pullback to PL above L (higher low), retracing <= pb_max (80%) of the reversal; QUIET: mean volume of
               the pullback bars <= the reversal bars' and buyers >= pb_bs (40%)
  4 TURN       the trigger bar closes above the bar before, buyers >= turn_bs (60%), gain >= turn_gain (0.15%) from its open
  5 ROOM       VWAP >= room_pct (1.5%) above the close
  safety       >= min_spm shares/min; 9:45-13:00; cool-down 30 min
When R8 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.
g      @g      Ð?é   g      ð?gš™™™™™¹?gš™™™™™á?gš™™™™™é?gš™™™™™Ù?g333333ã?g333333Ã?g      ø?iÐ  é   éÒ   é   )Údrop_pctÚdrop_atrÚleg_maxÚleg_pctÚleg_atrÚleg_bsÚpb_maxÚpb_bsÚturn_bsÚ	turn_gainÚroom_pctÚmin_spmÚfirst_mÚ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"   úr8_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
d„ ˆ D ƒ‰‡‡‡fdd„}tt|d ƒ‡ fdd„d�}ˆ | d }	|dk rvdddifS tdd„ ˆ d |d … D ƒƒ}
|
|	 d d }|t|d |d | ƒk r¥ddd|d›d�ifS dd„ t|d t|d |d  |d ƒƒD ƒ}t|ƒdk rÈdddifS t|‡ fd d„d�}ˆ | d! }||	 d d t|d" |d# | ƒk rüddd$||	 d d d›d�ifS tt|d |d ƒƒ}||ƒ|d% k �rddd&||ƒd'›d(�ifS tt|d |d ƒƒ}|�s1ddd)ifS tt‡ fd*d„|D ƒƒˆ d+ d ƒ}||	k�sU|| |d, ||	  k�rfddd-|| ||	  d'›d(�ifS t‡ fd.d„|D ƒƒt|ƒ t‡ fd.d„|D ƒƒt|ƒ k�r‹ddd/ifS ||ƒ|d0 k �r¡ddd1||ƒd'›d(�ifS ˆ d+ d2 }ˆ| ˆ|  }|ˆ d3 d2 k�s×|�r×ˆ| | |d4 k �s×|ˆ d+ d5  d d |d6 k �rÝddd7ifS td8d„ ˆ D ƒƒ}td9d„ ˆ D ƒƒ}|�rö|| n|}|| d d }||d: k �rddd;|d›d<�ifS td=d„ ˆ d>d … D ƒƒd? |d@ k �r,dddAifS dB|ˆ| |	|t|dƒt|| ||	  dƒt|dƒdCœfS )DNr   r   r   FÚatr14Ú
prev_closeéd   ÚbuyÚsellc                 S   s   g | ]}t |d  ƒ‘qS )r!   )r$   )Ú.0Úbr"   r"   r#   Ú
<listcomp>)   s    zcheck.<locals>.<listcomp>c                    s@   | rt ‡ ‡fdd„| D ƒƒtt ‡ ‡‡fdd„| D ƒƒdƒ S dS )Nc                 3   s   � | ]	}ˆ ˆ|  V  qd S ©Nr"   ©r*   Új)ÚfbÚminsr"   r#   Ú	<genexpr>*   ó   € z*check.<locals>.<lambda>.<locals>.<genexpr>c                 3   s(   � | ]}ˆ ˆ|  ˆˆ|   V  qd S r-   r"   r.   ©r0   Úfsr1   r"   r#   r2   *   s   €& g•Ö&è.>g        )ÚsumÚmax)Újsr4   r"   r#   Ú<lambda>*   s   @ zcheck.<locals>.<lambda>é   c                    ó   ˆ |  d S )NÚlr"   ©r/   ©Údoner"   r#   r9   +   ó    )Úkeyr<   é   Úwhy_notz1 low at the openc                 s   ó   � | ]}|d  V  qdS )ÚhNr"   ©r*   Úxr"   r"   r#   r2   /   ó   € zcheck.<locals>.<genexpr>r   r   z1 sell-off z.1fz% too smallc                 S   s   g | ]}|‘qS r"   r"   r.   r"   r"   r#   r,   3   s    r   é   z2 no reversal yetc                    r;   )NrE   r"   r=   r>   r"   r#   r9   6   r@   rE   r   r	   z2 reversal r
   z2 reversal without buyers (z.0%ú)z3 no pullback yetc                 3   ó   � | ]	}ˆ | d  V  qdS )r<   Nr"   r.   r>   r"   r#   r2   @   r3   éÿÿÿÿr   z3 pullback too deep (c                 3   rK   ©ÚvNr"   r.   r>   r"   r#   r2   C   r3   z3 pullback not quietr   z3 sellers on the pullback (Úcéþÿÿÿr   Úor   z4 no turn barc                 s   s4   � | ]}|d  |d  |d  d |d  V  qdS )rE   r<   rO   rB   rN   Nr"   rF   r"   r"   r#   r2   J   s   €2 c                 s   rD   rM   r"   rF   r"   r"   r#   r2   J   rH   r   z5 room to VWAP ú%c                 s   rD   rM   r"   rF   r"   r"   r#   r2   O   rH   éûÿÿÿé   r   ÚthinT)ÚsupportÚ	support_mÚday_lowÚreversal_highÚdropÚretraceÚroom)	ÚDEFAULTSÚlenÚgetÚminÚranger7   Úlistr6   Úround)r?   ÚflowÚrefÚmrO   ÚnÚatrpÚbsjÚjlÚLÚHdrZ   ÚlegÚjrÚRHÚupÚpbÚPLÚPÚt_ÚpvÚcvÚvwapr\   r"   )r?   r0   r5   r1   r#   Úcheck   sh    ,.&"$$">P$(ÿrx   r-   )Ú__doc__r]   r$   rx   r"   r"   r"   r#   Ú<module>   s    þ	