o
    ìÜj¦  ã                   @   s4   d Z dddddddddd	d
œ
Zdd„ Zddd„ZdS )aç  
r1e_setup.py -- [2026-10-23] The user's setup R1E "SELLING EXHAUSTION AT THE LOW" (from RKT 2/28/2025, sample chart #14: gapped
up 10% to 14.11, then BLED lower -- no flush: 10 bars on light volume (0.4-0.9x the day's median) while the 15-min buy share ROSE
33% -> 47%; 9:46 made the day's low 13.36 (-5.3%, 1.2x the daily ATR, far above the previous day's low 12.77 / close 12.83) and
closed off it; the user's buy = right there; 9:47 sold 2x volume at 18% buyers and could NOT make a new low; 14.08 by 10:02).
Not a spring (R1D: the low bar had 14% buyers, no reclaim, no volume) and not a turn bar (R1C) -- the sellers just run out.
  1 NEW LOW    the trigger bar makes the day's new low and closes off it (close position in its range >= close_pos 0.4)
  2 USED UP    the open -> low drop >= drop_atr (1.0) x the daily ATR
  3 BLEED      no flush: every one of the last bleed_n (10) bars < bleed_x (1.5) x the day's median minute volume (the busy
               opening minutes lift the median: RKT 9:38 = 1.31x; CERT's 9:42 flush = 3.25x)
  4 DIVERGENCE the price fell over those bars (close < the close bleed_n bars before) while the 15-min buy share ROSE by
               >= div_up (8 points) to >= bs15_min (45%, the N3 level)
  5 SUPPORT    the low is above the previous day's low (a QBTS-type breakdown under it is out)
  safety       >= min_spm shares/min over 5 bars; 9:40-14:30; one trigger per low (cool-down)
STOP = under the low (info "support"). Untested on 2 years. Pure function, no orders.
gš™™™™™Ù?g      ð?é
   g      ø?g{®Gáz´?gÍÌÌÌÌÌÜ?iÐ  i,  é   )
Ú	close_posÚdrop_atrÚbleed_nÚbleed_xÚdiv_upÚbs15_minÚ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   Úzoneinfor   Ú
isinstanceÚfromtimestampÚutcÚ
astimezoneÚhourÚminute)Útr   r   r   © r   úr1e_setup.pyÚ_minute   s   
r   Nc                    s  i t ¥|pi ¥}|pi }t| ƒ|d }}||d k s,||d ks,||d k s,| d¡s0di fS | d }|d td	d
„ | d d… D ƒƒkrKdddifS |d |d krc|d |d  |d |d   nd}||d k rvddd|d›d�ifS | d d |d  }	|	|d |d  k r™ddd|	|d  d›d�ifS | d¡r±|d |d kr±ddd|d › �ifS tdd
„ | d d… D ƒƒ}
|
t|
ƒd  }tdd
„ | | d … D ƒƒ}|rÞ||d | kròddd|› d|rê|| ndd›d�ifS |d  |d! ‰ ‰‡ ‡fd"d#„}| d|  }||ƒ|t|d$ ƒƒ}}|d |d k �r.|| |d% k�r.||d& k�sFddd'|d › d(|d › d)|d*›d(|d*›�ifS td+d
„ | d,d … D ƒƒd- |d. k �r`ddd/ifS d0|d |t|	|d  dƒt|| dƒt|d1ƒt|d1ƒt|dƒd2œfS )3Nr   r
   r   é   Úatr14FéÿÿÿÿÚlc                 s   ó   � | ]}|d  V  qdS )r"   Nr   ©Ú.0Úxr   r   r   Ú	<genexpr>&   ó   € zcheck.<locals>.<genexpr>Úwhy_notz1 no new lowÚhÚcr   r   z1 closed at the low (position z.2fú)Úor   z2 drop zx ATRÚprev_lowz5 under the previous day's low c                 s   r#   ©ÚvNr   r$   r   r   r   r'   3   r(   c                 s   r#   r/   r   r$   r   r   r   r'   4   r(   r   z3 a heavy bar in the last z (z!x median) -- a flush, not a bleedÚbuyÚsellc                    sT   t ˆ td| d ƒ| d … ƒ}t ˆtd| d ƒ| d … ƒ}|| r(|||  S dS )Nr   é   é   g      à?)ÚsumÚmax)ÚmmÚBÚS©ÚfbÚfsr   r   Úbs159   s   Tzcheck.<locals>.bs15r   r   r   z4 no divergence: price z -> z, 15-min buyers z.0%c                 s   r#   r/   r   r$   r   r   r   r'   ?   r(   éûÿÿÿé   r	   ÚthinTé   )ÚsupportÚ	support_mr   Úbleed_max_xÚ	bs15_thenr=   r   )	ÚDEFAULTSÚlenÚgetÚminÚsortedr6   r   r5   Úround)ÚdoneÚflowÚrefÚmr+   ÚnÚkÚbÚposÚdropÚvsÚmedÚbigr=   ÚaÚs_nowÚs_thenr   r:   r   Úcheck   s>   ."4*(20(&ÿr[   )N)Ú__doc__rF   r   r[   r   r   r   r   Ú<module>   s    ÿ	