INNER CODE UNIT · Python
stop
shashankvemuri/Finance · src/finance/backtesting/engine.py:177
stop = entries[j] * (1 - side * stop_loss) if stop_loss else None
if trailing_fraction:
trail = extremes[j] * (1 - side * trailing_fraction)
stop = (
trail
if stop is None
else (max(stop, trail) if side > 0 else min(stop, trail))
)
profit = entries[j] * (1 + side * take_profit) if take_profit else None
stop_hit = stop is not None and (low[j] <= stop if side > 0 else high[j] >= stop)
profit_hit = profit is not None and (
high[j] >= profit if side > 0 else low[j] <= profit
)
profit_gap = profit is not None and (
price[j] >= profit if side > 0 else price[j] <= profit
)
if stop_hit or profit_hit:
if profit_gap: