// This Pine Script™ code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/ // © ProofNexa Quant & Execution Lab (https://rotenkus-dot.github.io | https://quant-b2b-risk-gate-api.vercel.app) //@version=5 indicator("ProofNexa FX/Gold Spread Bleed, 0% Stop-Out & Half-Kelly HUD", shorttitle="PN Execution & Kelly HUD", overlay=true) // === User Inputs === grp_acct = "1. Account & Execution Profile" inp_balance = input.float(3000.0, "Account Equity (USD)", minval=50.0, step=100.0, group=grp_acct) inp_lot = input.float(0.50, "Target Lot Size (Lots)", minval=0.01, step=0.05, group=grp_acct) inp_monthly_trd = input.int(100, "Monthly Trades Count", minval=1, step=10, group=grp_acct) inp_cur_spread = input.float(2.2, "Current Broker Spread (pips)", minval=0.0, step=0.1, group=grp_acct) inp_raw_spread = input.float(0.5, "Pro / Raw Benchmark Spread (pips)", minval=0.0, step=0.1, group=grp_acct) inp_cb_rebate = input.float(0.8, "External Cashback Rebate (pips, if any)", minval=0.0, step=0.1, group=grp_acct) grp_kelly = "2. Half-Kelly & Risk Gate" inp_win_rate = input.float(56.0, "Strategy Win Rate (%)", minval=5.0, maxval=95.0, step=1.0, group=grp_kelly) inp_rr_ratio = input.float(1.45, "Reward-to-Risk Ratio (R:R)", minval=0.2, step=0.05, group=grp_kelly) inp_max_daily_dd = input.float(3.5, "Daily Drawdown Circuit Breaker (%)", minval=0.5, maxval=20.0, step=0.5, group=grp_kelly) // === Core Calculations === pip_val_per_lot = str.contains(syminfo.ticker, "XAU") or str.contains(syminfo.ticker, "GOLD") ? 10.0 : str.contains(syminfo.ticker, "BTC") ? 1.0 : 10.0 net_cur_spread = math.max(0.0, inp_cur_spread - inp_cb_rebate) annual_cur_cost = inp_cur_spread * pip_val_per_lot * inp_lot * inp_monthly_trd * 12.0 annual_cb_cost = net_cur_spread * pip_val_per_lot * inp_lot * inp_monthly_trd * 12.0 annual_pro_cost = inp_raw_spread * pip_val_per_lot * inp_lot * inp_monthly_trd * 12.0 annual_saved_vs_std = math.max(0.0, annual_cur_cost - annual_pro_cost) annual_saved_vs_cb = annual_cb_cost - annual_pro_cost // 0% Stop-Out Endurance vs 20% Standard Stop-Out (Assuming 1:2000 vs 1:500 effective margin) notional_margin_500 = (inp_lot * 100000.0) / 500.0 stopout_20_floor = notional_margin_500 * 0.20 pips_endurance_0pct = inp_balance / math.max(0.01, inp_lot * pip_val_per_lot) pips_endurance_20pct = math.max(0.0, inp_balance - stopout_20_floor) / math.max(0.01, inp_lot * pip_val_per_lot) extra_buffer_pips = math.max(0.0, pips_endurance_0pct - pips_endurance_20pct) // Half-Kelly Criterion Formula: f* = 0.5 * (p - (1 - p) / b) p = inp_win_rate / 100.0 q = 1.0 - p b = math.max(0.1, inp_rr_ratio) full_kelly_pct = math.max(0.0, (p - (q / b)) * 100.0) half_kelly_pct = full_kelly_pct * 0.5 // ATR Stop-Loss & Optimal Lot Sizing atr_14 = ta.atr(14) sl_risk_usd = inp_balance * (math.min(half_kelly_pct, inp_max_daily_dd) / 100.0) // Wednesday 3x Triple-Swap Day Alert is_wednesday = dayofweek == dayofweek.wednesday // === Render On-Chart Institutional HUD === var table hud = table.new(position.top_right, 2, 9, bgcolor=color.new(#070b14, 10), border_color=color.new(#38bdf8, 50), border_width=1) if barstate.islast table.cell(hud, 0, 0, "ProofNexa Execution & Kelly Lab", text_color=color.white, bgcolor=color.new(#0284c7, 15), text_size=size.small) table.cell(hud, 1, 0, syminfo.ticker + " (" + timeframe.period + ")", text_color=#fde047, bgcolor=color.new(#0284c7, 15), text_size=size.small) table.cell(hud, 0, 1, "Annual Spread Drag (Std)", text_color=#94a3b8, text_size=size.small) table.cell(hud, 1, 1, "-$" + str.tostring(math.round(annual_cur_cost)) + " / yr", text_color=#f87171, text_size=size.small) table.cell(hud, 0, 2, "Saved on Pro/Raw (vs Std)", text_color=#94a3b8, text_size=size.small) table.cell(hud, 1, 2, "+$" + str.tostring(math.round(annual_saved_vs_std)) + " / yr", text_color=#34d399, text_size=size.small) table.cell(hud, 0, 3, "Net Edge vs Cashback Site", text_color=#94a3b8, text_size=size.small) table.cell(hud, 1, 3, (annual_saved_vs_cb >= 0 ? "+$" : "-$") + str.tostring(math.round(math.abs(annual_saved_vs_cb))) + " / yr", text_color=annual_saved_vs_cb >= 0 ? #fbbf24 : #94a3b8, text_size=size.small) table.cell(hud, 0, 4, "0% Stop-Out Endurance", text_color=#94a3b8, text_size=size.small) table.cell(hud, 1, 4, str.tostring(pips_endurance_0pct, "#.#") + " pips (+" + str.tostring(extra_buffer_pips, "#.#") + "p)", text_color=#38bdf8, text_size=size.small) table.cell(hud, 0, 5, "Half-Kelly Risk / Trade", text_color=#94a3b8, text_size=size.small) table.cell(hud, 1, 5, str.tostring(half_kelly_pct, "#.##") + "% ($" + str.tostring(math.round(sl_risk_usd)) + ")", text_color=#a78bfa, text_size=size.small) table.cell(hud, 0, 6, "Triple-Swap (Wed) Status", text_color=#94a3b8, text_size=size.small) table.cell(hud, 1, 6, is_wednesday ? "WED 3x SWAP WARNING (Use $0 Swap-Free)" : "Normal Session ($0 Swap-Free Eligible)", text_color=is_wednesday ? #fbbf24 : #34d399, text_size=size.small) table.cell(hud, 0, 7, "ATR(14) 2.0x Hard SL Dist", text_color=#94a3b8, text_size=size.small) table.cell(hud, 1, 7, str.tostring(atr_14 * 2.0, "#.####"), text_color=#e2e8f0, text_size=size.small) table.cell(hud, 0, 8, "Full Simulator & MT5 .mq5", text_color=#94a3b8, text_size=size.small) table.cell(hud, 1, 8, "rotenkus-dot.github.io", text_color=#38bdf8, text_size=size.small)