o
    öçÛjú  ã                   @   s6   d Z dddddddddd	d
dœZdd„ Zddd„ZdS )aª  
r1c_setup.py -- [2026-10-23] The user's setup R1C "FIRST REVERSAL AFTER A FLUSH" (from QUBT 5/20/2025: opened 12.71, sold off
to 11.33 at 9:49 = -10.4% from the open, ~1.5x the daily ATR, just above the previous day's low 11.20, no climax bar; 9:50 turn
bar 72% buyers on 1.28x volume closing 11.54; the user's buy = right there, the retest at 9:56 held 11.35; ran to 12.10).
Unlike R1A it does NOT wait for the retest -- it buys the first strong turn bar off the flush low.
  1 DROP       the open -> flush low drop >= drop_atr (1.0) x the daily ATR (the day's selling is used up)
  2 FRESH LOW  the flush low (the lowest low of the day so far) is at most low_age (2) bars before the trigger bar
  3 SUPPORT    the flush low is above the previous day's low (QBTS-type breakdowns under it are N2 no-trades)
  4 NO CLIMAX  no bar in the last 15 with >= climax_x (5x) the day's 15-bar average volume (climax = A9, don't catch it)
  5 SELLERS    15-min buy share >= min_bs15 (45%) -- sellers not in control of the bigger window (N3)
  6 TURN BAR   the trigger bar closes above the bar before, buyers >= turn_bs (60%), volume >= turn_vol (1.0) x the 15-bar
               average, close in the upper half of its range
  safety       >= min_spm shares/min over 5 bars; 9:40-14:30; one trigger per flush (cool-down)
STOP = under the flush low (info "support"). Exit to pair with it: exit_x1.py (stall exit).
Untested on 2 years. Pure function, no orders.
g      ð?é   g      @gÍÌÌÌÌÌÜ?g333333ã?ç      à?iÐ  é
   i,  é   )Údrop_atrÚlow_ageÚclimax_xÚmin_bs15Úturn_bsÚturn_volÚturn_posÚ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   úr1c_setup.pyÚ_minute   s   
r!   Nc                    sÞ  i t ¥|pi ¥}|pi }tˆ ƒ}||d k s%||d ks%|dk s%| d¡s)di fS |d |d }}ˆ d d	 }tt|ƒ‡ fd
d„d�}	ˆ |	 d }
d|d |	   krZ|d ksan dddifS ||
 }||d |d  k r„ddd|d›d|d › d|d d›�ifS | d¡r�|
|d kr�ddd|
› d|d › �ifS ttd|d ƒ|ƒD ]7}ˆ td|d ƒ|… }|rÞˆ | d |d tdd„ |D ƒƒ t|ƒ krÞdddtˆ | d  ƒ› �if  S q§t|td|d! ƒ|d … ƒ}t|td|d! ƒ|d … ƒ}|| �r|||  nd"}||d# k �rddd$|d%›�ifS ˆ d& ˆ d' }}|| ||  }|�r5|| | nd}td(d„ ˆ d)d&… D ƒƒd }|d* |d k�r_|d+ |d  |d* |d   nd"}|d+ |d+ k�rƒ||d, k�rƒ|d |d- | k�rƒ||d. k�s¨ddd/|d+ |d+ k› d0|d%›d1|�rœ|d | ndd2›d3|d2›d4�	ifS td5d„ ˆ d6d … D ƒƒd7 |d8 k �rÂddd9ifS d:|
tˆ |	 d  ƒt||d  d;ƒt|d<ƒt|d<ƒ|�rêt|d | d;ƒd=œfS d d=œfS )>Nr   r   é   Úatr14FÚbuyÚsellr   Úoc                    s   ˆ |  d S )NÚlr   )Új©Údoner   r    Ú<lambda>&   s    zcheck.<locals>.<lambda>)Úkeyr'   é   r   Úwhy_notz#2 the day's low is not 1-2 bars oldr   z1 drop z.3gz < z x ATR Úprev_lowz3 flush low z under the previous day's low é   Úvr   c                 s   ó   � | ]}|d  V  qdS ©r1   Nr   ©Ú.0Úxr   r   r    Ú	<genexpr>4   ó   € zcheck.<locals>.<genexpr>z4 climax bar at r   é   r   r   z5 15-min buy share z.0%éÿÿÿÿéþÿÿÿc                 s   r2   r3   r   r4   r   r   r    r7   >   r8   iðÿÿÿÚhÚcr	   r
   r   z6 no turn bar (up z	, buyers z, vol z.2fzx, pos ú)c                 s   r2   r3   r   r4   r   r   r    r7   B   r8   éûÿÿÿé   r   ÚthinTr   é   )ÚsupportÚ	support_mr   Úbs15r	   Ú
turn_vol_x)	ÚDEFAULTSÚlenÚgetÚminÚrangeÚmaxÚsumr!   Úround)r*   ÚflowÚrefÚmr=   ÚnÚfbÚfsÚOÚljÚLÚdropr(   ÚwÚBÚSrE   ÚbÚpÚt_Úbs1ÚavÚposr   r)   r    Úcheck   sJ   *$"*2"€<&6DJ("&ÿÿrb   )N)Ú__doc__rG   r!   rb   r   r   r   r    Ú<module>   s    
ÿ	