I made a stratgy and i used fyerss api but i am getting a issue when i am keeping 5 points sl some times it is hitting 10 points too much slippage and is any error in my code or what i dont understant please can any one tell
# ---------- EXIT LOGIC ----------
if S.in_pos:
sl = S.entry - SL_POINTS
target = S.entry + TP_POINTS
exit_reason = None
if current_hm >= TRADING_CLOSE_TIME: exit_reason = "TIME_EXIT"
elif current_ltp >= target: exit_reason = "WIN"
elif current_ltp <= sl: exit_reason = "LOSS"
if exit_reason:
print(f" EXIT {S.label} | Reason: {exit_reason} | LTP: {current_ltp}")
# ACCURACY FIX: Get actual exit price from Fyers
fyers_exit_p = order(S.symbol, "SELL")
trade_exit_p = fyers_exit_p if fyers_exit_p else current_ltp
pnl_pts = trade_exit_p - S.entry
pnl_rs = pnl_pts * (QTY_LOTS * LOT_SIZE)
# CLEAR EVERYTHING
S.in_pos = False
S.entry = None
S.last_exit_minute = current_hm
OPEN_POSITIONS[S.label] = None
S.total_trades += 1
if exit_reason == "WIN":
S.tp_hit = True
S.tp_trades += 1
elif exit_reason == "LOSS":
S.sl_trades += 1
if S.limits_reached():
S.stopped = True
continue