Require equityProfit; return null when balance invalid
computeDailyTarget now requires equityProfit (amount - accountSize) and returns null when it's undefined/null/NaN. 0 is still a valid value. - Removed totalProfit parameter (was only used as fallback) - Callers handle null by skipping the account (eligibility) or throwing (execution paths) - State API sets dailyTarget to null when no valid balance, avoids incorrect targetHit computation Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 4.6
parent
b7430df16e
commit
670ee9fbeb
+10
-6
@@ -200,7 +200,8 @@ export async function runTrade(action: 'Buy' | 'Sell' | 'Auto', symbol: string)
|
||||
|
||||
// Use the same target formula as the dashboard — skip if $0 (challenge complete)
|
||||
const equityProfit = cash.amount - cfg.accountSize;
|
||||
const target = computeDailyTarget(effective.profitTarget, effective.consistency, totalProfit, dailyPnL, cfg.minDayPnL, effective.minTradingDays, equityProfit);
|
||||
const target = computeDailyTarget(effective.profitTarget, effective.consistency, dailyPnL, cfg.minDayPnL, effective.minTradingDays, equityProfit);
|
||||
if (!target) continue; // skip accounts without a valid balance
|
||||
|
||||
// Allow through if it's an MNQ extra-day trade: no min day P&L, profit done, days still needed
|
||||
const isMnqExtraDay = cfg.minDayPnL <= 0
|
||||
@@ -266,7 +267,8 @@ export async function runTrade(action: 'Buy' | 'Sell' | 'Auto', symbol: string)
|
||||
}
|
||||
|
||||
const equityProfit = cash.amount - cfg.accountSize;
|
||||
const target = computeDailyTarget(effective.profitTarget, effective.consistency, totalProfit, dailyPnL, cfg.minDayPnL, effective.minTradingDays, equityProfit);
|
||||
const target = computeDailyTarget(effective.profitTarget, effective.consistency, dailyPnL, cfg.minDayPnL, effective.minTradingDays, equityProfit);
|
||||
if (!target) throw new Error(`${acc.name}: invalid balance, cannot compute target`);
|
||||
|
||||
const rawContracts = Math.max(1, Math.ceil(target.amount / 1000));
|
||||
const contracts = cfg.maxPositionSize > 0 ? Math.min(rawContracts, cfg.maxPositionSize) : rawContracts;
|
||||
@@ -444,8 +446,8 @@ export async function copyTrade() {
|
||||
);
|
||||
|
||||
const equityProfit = cash.amount - cfg.accountSize;
|
||||
const target = computeDailyTarget(effective.profitTarget, effective.consistency, totalProfit, dailyPnL, cfg.minDayPnL, effective.minTradingDays, equityProfit);
|
||||
if (target.amount <= 0) continue;
|
||||
const target = computeDailyTarget(effective.profitTarget, effective.consistency, dailyPnL, cfg.minDayPnL, effective.minTradingDays, equityProfit);
|
||||
if (!target || target.amount <= 0) continue;
|
||||
|
||||
eligible.push({ firmName: firm.name, client, acc, contract, firmConfig, cash, dailyPnL, daysTraded });
|
||||
}
|
||||
@@ -471,7 +473,8 @@ export async function copyTrade() {
|
||||
);
|
||||
|
||||
const equityProfit = cash.amount - cfg.accountSize;
|
||||
const target = computeDailyTarget(effective.profitTarget, effective.consistency, totalProfit, dailyPnL, cfg.minDayPnL, effective.minTradingDays, equityProfit);
|
||||
const target = computeDailyTarget(effective.profitTarget, effective.consistency, dailyPnL, cfg.minDayPnL, effective.minTradingDays, equityProfit);
|
||||
if (!target) throw new Error(`${acc.name}: invalid balance, cannot compute target`);
|
||||
|
||||
const rawContracts = Math.max(1, Math.ceil(target.amount / 1000));
|
||||
const contracts = cfg.maxPositionSize > 0 ? Math.min(rawContracts, cfg.maxPositionSize) : rawContracts;
|
||||
@@ -559,7 +562,8 @@ function hasRemainingConfiguredAccounts(): boolean {
|
||||
);
|
||||
|
||||
const equityProfit = cash.amount - cfg.accountSize;
|
||||
const target = computeDailyTarget(effective.profitTarget, effective.consistency, totalProfit, dailyPnL, cfg.minDayPnL, effective.minTradingDays, equityProfit);
|
||||
const target = computeDailyTarget(effective.profitTarget, effective.consistency, dailyPnL, cfg.minDayPnL, effective.minTradingDays, equityProfit);
|
||||
if (!target) continue; // no valid balance → skip this account
|
||||
const isMnqExtraDay = cfg.minDayPnL <= 0
|
||||
&& effective.minTradingDays > daysTraded
|
||||
&& totalProfit >= effective.profitTarget;
|
||||
|
||||
Reference in New Issue
Block a user