o
    ÁÌÚj8  ã                   @   s0   d Z ddddddddd	dd
ddœZddd„ZdS )aÐ  
r3_setup.py -- [2026-10-22] The user's setup R3 "OPENING PUSH -> FIRST PULLBACK HOLDS -> TURN" (from the UUUU 6/18/2025
practice chart, the user's entry 9:33-9:36: opening print 5.76 bought straight back to 5.93-5.95 in 2 minutes, first
pullback to 5.81 held above the opening low with buyers still 50-57%, 9:34 turned up with 65% buyers -> buy 9:35 open
5.87, +2% at 9:37). Works on the first bars of the day, when the 15-bar indicators do not exist yet.
  1 PUSH       within the first push_bars (3) bars, a rise of >= max(push_pct 1%, push_atr 0.15 x daily ATR %) off the
               opening low, with buyers >= push_bs (50%) on the push bars (the bars AFTER the low bar -- the opening print is
               not counted)
  2 HOLDS      the pullback after the push high retraces <= max_retrace (75%) of the push and stays ABOVE the opening low
  3 NO DUMP    buyers on the pullback bars >= pb_bs (45%) -- profit-taking, not selling
  4 TURN       the trigger bar closes above the bar before with buyers >= turn_bs (55%) and is still under the push high
               (buying the turn, not the breakout) -> buy the next open
  5 MOVER      daily ATR % >= min_atr (5%) -- the stock usually moves enough for +2%
  safety       >= min_spm shares/min; trigger only from bar first_m to last_m (9:33-9:42); one trigger per day
When R3 is true these v2 rules do NOT apply: the 15-bar wait, RVOL, 15-min buy share / steady trend, VWAP band.
Untested on 2 years. Pure function, no orders.
é   g      ð?g333333Ã?g      à?g      è?gÍÌÌÌÌÌÜ?gš™™™™™á?g      @iÐ  é   iç  )Ú	push_barsÚpush_pctÚpush_atrÚpush_bsÚmax_retraceÚpb_bsÚturn_bsÚmin_atrÚmin_spmÚfirst_mÚlast_mÚcooldownNc                    s  i t ¥|pi ¥}|pi }tˆ ƒ}||d k s*||d ks*||d ks*||d d k r.di fS | d¡rB| d¡rB|d |d  d	 nd }|d u sN||d
 k rTdddifS |d |d ‰‰‡‡fdd„}|d }tt|ƒ‡ fdd„d�}	ˆ |	 d }
tt|	|ƒ‡ fdd„d�}ˆ | d }||
 d d	 }t|d |d | ƒ}||k r³ddd|d›d|d›d�ifS |||	kr¼|	d n|	|ƒ|d k rÊdddifS ||d krÖdddifS tdd „ ˆ |d d … D ƒƒ}|| ||
  }||
ksø||d! k�rddd"|d#›d$�ifS |d |k�r||d |d ƒ|d% k �rddd&ifS ˆ| ˆ|  }ˆ d' d( ˆ d) d( k�rJ|�rJˆ| | |d* k�rJˆ d' d( |k �sPddd+ifS td,d „ ˆ D ƒƒ| |d- k �rfddd.ifS d/|
|	|t|dƒ|t|dƒt|ˆ d' d(  d d	 dƒt|dƒd0œfS )1Nr   r   é   r   é   FÚatr14Ú
prev_closeéd   r
   Úwhy_notz5 not a mover (ATR)ÚbuyÚsellc                    sB   t ˆ | |d … ƒtt ˆ | |d … ƒt ˆ| |d … ƒ dƒ S )Nr   g•Ö&è.>)ÚsumÚmax)ÚaÚb)ÚfbÚfs© úr3_setup.pyÚ<lambda>    s   B zcheck.<locals>.<lambda>c                    ó   ˆ |  d S )NÚlr   ©Úi©Údoner   r   r   #   ó    )Úkeyr!   c                    r    )NÚhr   r"   r$   r   r   r   %   r&   r(   r   r   z1 push z.1fz% < ú%r   z1 push without buyersz2 no pullback yetc                 s   ó   � | ]}|d  V  qdS )r!   Nr   ©Ú.0Úxr   r   r   Ú	<genexpr>0   ó   € zcheck.<locals>.<genexpr>r   z2 pullback too deep (z.0%z of the push)r   z 3 sellers dumped on the pullbackéÿÿÿÿÚcéþÿÿÿr	   z4 no turn barc                 s   r*   )ÚvNr   r+   r   r   r   r.   ;   r/   r   ÚthinT)ÚsupportÚ	support_mÚ	push_highr   Úpullback_lowÚretraceÚroomÚatr)ÚDEFAULTSÚlenÚgetÚminÚranger   r   Úround)r%   ÚflowÚrefÚmr1   ÚnÚatrpÚbsÚpbÚi_lowÚL0Úi_hiÚHÚpushÚneedÚpblÚretrÚt_r   )r%   r   r   r   Úcheck   sJ   4,"*H ,ÿrR   )N)Ú__doc__r<   rR   r   r   r   r   Ú<module>   s
    ÿ