o
    ŽI´j±  ã                   @   s,   d Z dddœZdedededefdd	„Zd
S )av  
reentry.py

[2026-09-23] Entry selectivity after a losing trade in the same symbol.
Backtest finding (09-18..09-23, 144 baseline trades): re-entries into a
symbol right after a LOSING trade won 21% of the time for -$262, while
re-entries after a winner won 59% for +$173 and brand-new symbols were
net positive. The user's read: slot-refill losses are an entry-selection
problem, not an exit problem.

Modes (trading.reentry_after_loss.mode):
  "off"          no restriction (previous behavior)
  "block"        after a losing trade, no new entry in that symbol today
  "above_entry"  after a losing trade, re-entry only once price trades
                 above that losing trade's entry price + buffer (the stock
                 has recovered past where it beat us)
Only the symbol's MOST RECENT closed trade is checked, so a later
winning trade in the symbol lifts the restriction.
Úoffg      ð?)ÚmodeÚbuffer_centsÚsymbolÚpriceÚ
last_tradeÚcfgc                 C   s¤   i t ¥|pi ¥}|d dks|r| dd¡dkrdS |d dkr-dd| › d	|d d
›�fS |d |d d  }||kr=dS dd|d d
›d|d
›d|d d
›d�fS )z„last_trade: the symbol's most recent CLOSED trade today (dict with
    entry_price, pl_dollars), or None. Returns (allowed, reason).r   r   Ú
pl_dollarsé    )TÚ ÚblockFzre-entry blocked: last z trade lost $z.2fÚentry_pricer   g      Y@zre-entry after a $z loss needs price > z (last entry ú))ÚDEFAULTÚget)r   r   r   r   Úneed© r   ú"/var/www/screener/trade/reentry.pyÚcheck   s    ÿ
ÿr   N)Ú__doc__r   ÚstrÚfloatÚdictr   r   r   r   r   Ú<module>   s    
