utkarshpathak48 commited on
Commit
e8f1e83
·
1 Parent(s): 3e4e49f

Fix double-leverage bug: Loss@SL was showing risk_usd x leverage, not real loss

Browse files

_suggest_leverage() computed loss_at_user_lev from sizing['notional'], which
is already risk_pct-scaled — multiplying that by leverage again silently
doubled leverage into the shown loss. Example: $10 account, 10% risk, 6x
leverage showed Loss@SL ~$6 (60% of account) right next to a $1 Risk figure
that was supposed to be the same money.

Fix: loss_at_user_lev now uses account x leverage (full all-in notional,
matching Utkarsh's real ALL-IN trading style per G-6) instead of the
risk-scaled notional. This also fixes lev_safety_ratio, which previously
always equalled exactly 1/leverage regardless of the trade (a dead giveaway
it wasn't varying correctly) -- it now genuinely reflects how a given trade's
stop-distance and chosen leverage compare to the stated risk_pct target.

margin_to_post (the alternative, smaller, precisely-risk-capped position
size) is unaffected -- still correctly risk_pct-scaled as before.

Verified numerically: $10/10%/6x across 1%/2%/3.5% stops now correctly
shows $0.60/$1.20/$2.10 loss (was a constant $6 regardless of stop dist).

Files changed (1) hide show
  1. scorer.py +18 -6
scorer.py CHANGED
@@ -401,15 +401,26 @@ def _suggest_leverage(account: float, risk_pct: float,
401
  needed_lev = target_profit_usd / (notional × move_pct_to_tp1)
402
 
403
  User diagnostics (non-circular, independent of sizing formula):
404
- loss_at_user_lev = notional × user_leverage × stop_dist_pct
405
- → actual dollar loss if stop is hit at user's chosen leverage
 
 
 
 
 
 
 
406
  lev_safety_ratio = risk_usd / loss_at_user_lev
407
- → 1.0 = perfect fit, <1.0 = over-risked at this leverage
 
 
408
  liq_dist_pct = (1/user_leverage - 0.005) × 100
409
  → how far price must move to trigger BingX liquidation (with 0.5% MMR)
410
 
411
  margin_to_post = notional / user_leverage
412
- → the USDT amount to enter in BingX's "By Cost" order mode
 
 
413
  """
414
  notes = []
415
  lev = max(user_leverage, 1.0)
@@ -446,8 +457,9 @@ def _suggest_leverage(account: float, risk_pct: float,
446
  f"({tp1_move_pct*100:.2f}% move)"
447
  )
448
 
449
- # ── User-leverage diagnostics (non-circular) ───────────────────────────
450
- loss_at_user_lev = notional * lev * stop_dist_pct
 
451
  lev_safety_ratio = risk_usd / loss_at_user_lev if loss_at_user_lev > 0 else 0.0
452
  # Liquidation distance: 1/leverage minus MMR (0.5% for BingX BTC; higher for alts)
453
  liq_dist_pct = round((1 / lev - 0.005) * 100, 2)
 
401
  needed_lev = target_profit_usd / (notional × move_pct_to_tp1)
402
 
403
  User diagnostics (non-circular, independent of sizing formula):
404
+ loss_at_user_lev = (account × user_leverage) × stop_dist_pct
405
+ → actual dollar loss if you post your FULL account as margin at this
406
+ leverage and the stop is hit (i.e. Utkarsh's real all-in style).
407
+ Deliberately uses account×leverage, NOT sizing["notional"] — the
408
+ latter is already risk_pct-scaled, so reusing it here would apply
409
+ leverage twice and silently multiply the shown loss by `lev` on
410
+ top of the real number (found + fixed 2026-07-12: was showing
411
+ risk_usd×lev, e.g. ~$6 "Loss@SL" next to a $1 "Risk" figure on a
412
+ $10 account at 10% risk / 6x — six times the intended risk).
413
  lev_safety_ratio = risk_usd / loss_at_user_lev
414
+ → 1.0 = your all-in loss at this leverage exactly matches your risk_pct
415
+ target · <1.0 = going all-in at this leverage loses MORE than your
416
+ risk_pct target if stopped out · >1.0 = loses less (room to spare)
417
  liq_dist_pct = (1/user_leverage - 0.005) × 100
418
  → how far price must move to trigger BingX liquidation (with 0.5% MMR)
419
 
420
  margin_to_post = notional / user_leverage
421
+ → the USDT amount to post if you instead want to precisely cap risk
422
+ at risk_usd via a smaller-than-all-in position (the alternative to
423
+ going all-in — this stays risk_pct-scaled, unlike loss_at_user_lev above)
424
  """
425
  notes = []
426
  lev = max(user_leverage, 1.0)
 
457
  f"({tp1_move_pct*100:.2f}% move)"
458
  )
459
 
460
+ # ── User-leverage diagnostics (non-circular, all-in framing — see docstring) ──
461
+ full_notional = account * lev
462
+ loss_at_user_lev = full_notional * stop_dist_pct
463
  lev_safety_ratio = risk_usd / loss_at_user_lev if loss_at_user_lev > 0 else 0.0
464
  # Liquidation distance: 1/leverage minus MMR (0.5% for BingX BTC; higher for alts)
465
  liq_dist_pct = round((1 / lev - 0.005) * 100, 2)