mirror of
https://github.com/NoFxAiOS/nofx.git
synced 2026-07-14 00:07:01 +08:00
Fix: Resolve Trade History data loss and P&L calculation errors
Major fixes: 1. Trade History data loss issue - Root cause: Open records outside analysis window caused close matching failures - Solution: Pre-populate position state by reading 3x window of historical records - Ensures long-term positions (>5 hours) generate correct trade records 2. P&L calculation errors - Remove incorrect leverage multiplication from absolute P&L - Correct calculation: Futures P&L = quantity × price difference - Leverage only affects P&L percentage (relative to margin) 3. Other fixes - Break-even trades (pnl=0) no longer misclassified as losses - Perfect strategy shows Profit Factor as 999.0 instead of 0.0 - Expand analysis window from 20 to 100 cycles (5 hours) Files changed: - logger/decision_logger.go: Core matching and calculation logic - api/server.go: API analysis window - trader/auto_trader.go: AI decision analysis window Co-Authored-By: tinkle-community <tinklefund@gmail.com>
This commit is contained in:
@@ -510,8 +510,9 @@ func (at *AutoTrader) buildTradingContext() (*decision.Context, error) {
|
||||
marginUsedPct = (totalMarginUsed / totalEquity) * 100
|
||||
}
|
||||
|
||||
// 5. 分析历史表现(最近20个周期)
|
||||
performance, err := at.decisionLogger.AnalyzePerformance(20)
|
||||
// 5. 分析历史表现(最近100个周期,避免长期持仓的交易记录丢失)
|
||||
// 假设每3分钟一个周期,100个周期 = 5小时,足够覆盖大部分交易
|
||||
performance, err := at.decisionLogger.AnalyzePerformance(100)
|
||||
if err != nil {
|
||||
log.Printf("⚠️ 分析历史表现失败: %v", err)
|
||||
// 不影响主流程,继续执行(但设置performance为nil以避免传递错误数据)
|
||||
|
||||
Reference in New Issue
Block a user