o
    ¹Üjw  ã                
   @   s2   d Z dddddddddd	œ	Zd
d„ Zddd„ZdS )aÆ  
exit_climax.py -- [2026-10-23] The user's CLIMAX SELL (from PRTA 12/19/2024, sample chart #11: R1B buy 9:55 at 12.74, ran to
17.66 at 11:17 = +38%; the user's sell = 11:15). At 11:15 the price was +12.8% over VWAP (~1.5x the daily ATR above it), the
volume had been 2.8-3.8x normal for 7 bars, and 11:15 was the run's first big SELLER bar (86,525 shares, 41% buyers; the 5-min
buy share 77% -> 53%); the 1-min range had tripled (0.10 -> 0.26). Then 11:16-11:17 blow-off wicks to 17.66 and back to 16.49.
Meant to sit ON TOP of another exit (GB2 / X1) to keep a runner's profit at the climax. Sell at a FINISHED bar's close when ALL:
  PROFIT     the close >= min_gain (3%) over the buy
  STRETCHED  the close >= vwap_pct (8%) over the session VWAP, OR >= atr_k (1.0) x the daily ATR over it (when ref is given)
  HEAVY      a SUSTAINED climax: >= heavy_min (5) of the last heavy_n (6) bars each with >= heavy_x (2.0) x the MEDIAN minute volume
             of the day before them (a long climax would lift a 15-bar baseline) (PRTA 10:39 had only 3 heavy bars after quiet ones and was a pause, not the top)
  WIDER      the mean 1-min range of the last 15 bars >= range_x (1.5) x the same 30 bars earlier (the bars blow out:
             PRTA 11:15 0.26 vs 0.15)
  SELLERS    the current bar: 1-min buy share < seller_bs (45%) on volume >= seller_vol_x (2.0) x that same median
Decided at a bar close only, sold at the next price. Untested on 2 years. Pure function, no orders.
g      @g       @g      ð?é   é   g       @g      ø?gÍÌÌÌÌÌÜ?)	Úmin_gainÚvwap_pctÚatr_kÚheavy_nÚ	heavy_minÚheavy_xÚrange_xÚ	seller_bsÚseller_vol_xc                 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   úexit_climax.pyÚ_minute   s   
r   Nc                    sž  i t ¥ˆpi ¥‰ˆd }t| ƒt|d dƒk rdS | d }|d |dˆd d	   k r-dS td
d„ | D ƒƒ}tdd„ | D ƒƒ}|rE|| n|d }	|d |	 d d	 }
|pVi  d¡}|
ˆd kpm|om|d |	 ˆd | k}|srdS tdd„ | d| … D ƒƒ}|rŠ|t|ƒd  nd‰ t‡ ‡fdd„| | d… D ƒƒ}ˆ r¥|ˆd k r§dS dd„ }|| dd… ƒ|| dd… ƒ}}|rÆ|ˆd | k rÈdS t|d ƒ}|d | |d | }}|| rå|||  nd}|ˆd  k r÷|d! ˆd" ˆ  ksùdS d#d$|d d%›d&|d | d d	 d'›d(|
d'›d)|	d%›�|�r%d*|d |	 | d'›d+�nd, d-|› d.|› d/ˆd0 d1›d2|d3›d4|d3›d5� d6|d7›d8|d! ˆ  d'›d9� fS ):zbdone: the day's finished regular-session bars; flow: {"buy": [390], "sell": [390]} -> (sell?, why)r   é   é.   )FÚ éÿÿÿÿÚcé   r   éd   c                 s   s4   � | ]}|d  |d  |d  d |d  V  qdS )ÚhÚlr"   é   ÚvNr   ©Ú.0Úxr   r   r   Ú	<genexpr>&   s   €2 zcheck.<locals>.<genexpr>c                 s   ó   � | ]}|d  V  qdS ©r(   Nr   r)   r   r   r   r,   &   ó   € Úatr14r   r   c                 s   r-   r.   r   r)   r   r   r   r,   -   r/   Né   r   c                 3   s,   � | ]}ˆ r|d  ˆd ˆ  krdV  qdS )r(   r   r#   Nr   r)   ©Úbaser"   r   r   r,   /   s   €* r   c                 S   s   t dd„ | D ƒƒt| ƒ S )Nc                 s   s    � | ]}|d  |d  V  qdS )r%   r&   Nr   r)   r   r   r   r,   2   s   € z*check.<locals>.<lambda>.<locals>.<genexpr>)ÚsumÚlen)Úwr   r   r   Ú<lambda>2   s    zcheck.<locals>.<lambda>iñÿÿÿiÓÿÿÿiâÿÿÿr	   r   ÚbuyÚsellg      à?r
   r(   r   TzCLIMAX sell: close z.4gz +z.1fz% over the buy, z% over VWAP z (zx ATR)r    z; z of the last z	 bars >= r   Úgzx normal volume; 1-min range z.3gz vs z 30 bars beforez; seller bar z.0%z buyers on zx volume)ÚDEFAULTSr5   Úmaxr4   ÚgetÚsortedr   )ÚdoneÚflowÚentryÚrefr"   ÚnÚbÚpvÚcvÚvwÚoverÚatrÚ	stretchedÚpreÚnhÚrngÚr_nowÚr_thenÚmÚBÚSÚbs1r   r2   r   Úcheck   sD   $(""& 8"ÿ,þýrT   )NN)Ú__doc__r;   r   rT   r   r   r   r   Ú<module>   s    ÿ	