Execution Logic
_compute_exit_fill
Gap-aware exit logic distinguishes between overnight gaps and intrabar touches, producing more realistic fill behavior than naive stop-loss simulation.
def _compute_exit_fill(self, pos: Dict[str, Any], bar: Dict[str, Any]) -> Tuple[Optional[float], Optional[str]]: """ If OPEN gaps through level → fill at OPEN (worst side). Else if intrabar touch → fill at the level. Stop has precedence over TP. """ side = pos["side"] stop = pos.get("stop_loss") tp = pos.get("take_profit") o = float(bar["open"]) h = float(bar["high"]) l = float(bar["low"]) if side == "long": if stop is not None and not pd.isna(stop): stop = float(stop) if o <= stop:
