Fix P&L calculation and update Copilot instructions
- Fix P&L calculation in Position Manager to use actual entry vs exit price instead of SDK's potentially incorrect realizedPnL - Calculate actual profit percentage and apply to closed position size for accurate dollar amounts - Update database record for last trade from incorrect 6.58 to actual .66 P&L - Update .github/copilot-instructions.md to reflect TP2-as-runner system changes - Document 25% runner system (5x larger than old 5%) with ATR-based trailing - Add critical P&L calculation pattern to common pitfalls section - Mark Phase 5 complete in development roadmap
This commit is contained in:
@@ -26,7 +26,6 @@ interface TradingSettings {
|
||||
TAKE_PROFIT_1_PERCENT: number
|
||||
TAKE_PROFIT_1_SIZE_PERCENT: number
|
||||
TAKE_PROFIT_2_PERCENT: number
|
||||
TAKE_PROFIT_2_SIZE_PERCENT: number
|
||||
EMERGENCY_STOP_PERCENT: number
|
||||
BREAKEVEN_TRIGGER_PERCENT: number
|
||||
PROFIT_LOCK_TRIGGER_PERCENT: number
|
||||
@@ -165,11 +164,13 @@ export default function SettingsPage() {
|
||||
const size = baseSize ?? settings.MAX_POSITION_SIZE_USD
|
||||
const lev = leverage ?? settings.LEVERAGE
|
||||
const maxLoss = size * lev * (Math.abs(settings.STOP_LOSS_PERCENT) / 100)
|
||||
// Calculate gains/losses for risk calculator
|
||||
const tp1Gain = size * lev * (settings.TAKE_PROFIT_1_PERCENT / 100) * (settings.TAKE_PROFIT_1_SIZE_PERCENT / 100)
|
||||
const tp2Gain = size * lev * (settings.TAKE_PROFIT_2_PERCENT / 100) * (settings.TAKE_PROFIT_2_SIZE_PERCENT / 100)
|
||||
const fullWin = tp1Gain + tp2Gain
|
||||
const tp2RunnerSize = size * (1 - settings.TAKE_PROFIT_1_SIZE_PERCENT / 100) // 25% remaining after TP1
|
||||
const runnerValue = tp2RunnerSize * lev * (settings.TAKE_PROFIT_2_PERCENT / 100) // Full 25% runner value at TP2
|
||||
const fullWin = tp1Gain + runnerValue
|
||||
|
||||
return { maxLoss, tp1Gain, tp2Gain, fullWin }
|
||||
return { maxLoss, tp1Gain, runnerValue, fullWin }
|
||||
}
|
||||
|
||||
if (loading) {
|
||||
@@ -225,8 +226,8 @@ export default function SettingsPage() {
|
||||
<div className="text-white text-2xl font-bold">+${risk.tp1Gain.toFixed(2)}</div>
|
||||
</div>
|
||||
<div className="bg-green-500/10 border border-green-500/50 rounded-lg p-4">
|
||||
<div className="text-green-400 text-sm mb-1">TP2 Gain ({settings.TAKE_PROFIT_2_SIZE_PERCENT}%)</div>
|
||||
<div className="text-white text-2xl font-bold">+${risk.tp2Gain.toFixed(2)}</div>
|
||||
<div className="text-green-400 text-sm mb-1">Runner Value (25%)</div>
|
||||
<div className="text-white text-2xl font-bold">+${risk.runnerValue.toFixed(2)}</div>
|
||||
</div>
|
||||
<div className="bg-purple-500/10 border border-purple-500/50 rounded-lg p-4">
|
||||
<div className="text-purple-400 text-sm mb-1">Full Win</div>
|
||||
@@ -441,16 +442,7 @@ export default function SettingsPage() {
|
||||
min={0.1}
|
||||
max={20}
|
||||
step={0.1}
|
||||
description="Price level for second take profit exit."
|
||||
/>
|
||||
<Setting
|
||||
label="Take Profit 2 Size (%)"
|
||||
value={settings.TAKE_PROFIT_2_SIZE_PERCENT}
|
||||
onChange={(v) => updateSetting('TAKE_PROFIT_2_SIZE_PERCENT', v)}
|
||||
min={1}
|
||||
max={100}
|
||||
step={1}
|
||||
description="What % of remaining position to close at TP2. Example: 100 = close rest."
|
||||
description="Price level where runner trailing stop activates (no close operation)."
|
||||
/>
|
||||
<Setting
|
||||
label="Emergency Stop (%)"
|
||||
@@ -495,11 +487,11 @@ export default function SettingsPage() {
|
||||
</Section>
|
||||
|
||||
{/* Trailing Stop */}
|
||||
<Section title="🏃 Trailing Stop (Runner)" description="Let a small portion run with dynamic stop loss">
|
||||
<Section title="🏃 Trailing Stop (25% Runner)" description="TP2 activates trailing stop on full remaining 25%">
|
||||
<div className="mb-4 p-3 bg-blue-500/10 border border-blue-500/30 rounded-lg">
|
||||
<p className="text-sm text-blue-400">
|
||||
After TP2 closes, the remaining position (your "runner") can use a trailing stop loss that follows price.
|
||||
This lets you capture big moves while protecting profit.
|
||||
NEW SYSTEM: When TP2 price is hit, no position is closed. Instead, trailing stop activates on the full 25% remaining position for maximum runner potential.
|
||||
This gives you a 5x larger runner (25% vs 5%) to capture extended moves.
|
||||
</p>
|
||||
</div>
|
||||
<Setting
|
||||
@@ -509,7 +501,7 @@ export default function SettingsPage() {
|
||||
min={0}
|
||||
max={1}
|
||||
step={1}
|
||||
description="Enable trailing stop for runner position after TP2. 0 = disabled, 1 = enabled."
|
||||
description="Enable trailing stop for 25% runner position when TP2 triggers. 0 = disabled, 1 = enabled."
|
||||
/>
|
||||
<Setting
|
||||
label="Trailing Stop Distance (%)"
|
||||
@@ -527,7 +519,7 @@ export default function SettingsPage() {
|
||||
min={0.1}
|
||||
max={5}
|
||||
step={0.1}
|
||||
description="Runner must reach this profit % before trailing stop activates. Prevents premature stops. Example: 0.5% = wait until runner is +0.5% profit."
|
||||
description="25% runner must reach this profit % before trailing stop activates. Prevents premature stops. Example: 0.5% = wait until runner is +0.5% profit."
|
||||
/>
|
||||
</Section>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user