帮忙看看代码哪里出错了? 新评论 Kwong Yuan 2024.09.23 08:51 各位老大,帮忙看看代码哪里出错了??? void CheckAndOpenLimitOrdersForSymbol(string symbol, SymbolData &data) { ………… double volume = GetTradeVolume(symbol); bool isRecoveryMode = false; if(Recovery) // 只有当Recovery为true时才检查恢复模式 { datetime startTime = TimeCurrent() - 30 * 24 * 60 * 60; // 30天前 HistorySelect(startTime, TimeCurrent()); double lastLossAmount = 0; double recoveryProfit = 0; double lastLossVolume = 0; bool foundLoss = false; datetime lastLossTime = 0; Print("Checking orders for recovery mode from ", TimeToString(startTime), " to ", TimeToString(TimeCurrent())); for(int i = HistoryDealsTotal() - 1; i >= 0; i--) { ulong dealTicket = HistoryDealGetTicket(i); if(HistoryDealSelect(dealTicket) && HistoryDealGetString(dealTicket, DEAL_SYMBOL) == symbol && HistoryDealGetInteger(dealTicket, DEAL_MAGIC) == InpMagicNumber) // 检查魔术号 { double dealProfit = HistoryDealGetDouble(dealTicket, DEAL_PROFIT); datetime dealTime = (datetime)HistoryDealGetInteger(dealTicket, DEAL_TIME); Print("Deal found: Time=", TimeToString(dealTime), ", Profit=", DoubleToString(dealProfit, 2)); if(dealProfit < 0) { foundLoss = true; lastLossAmount = MathAbs(dealProfit); lastLossVolume = HistoryDealGetDouble(dealTicket, DEAL_VOLUME); lastLossTime = dealTime; Print("Found loss: Amount=", DoubleToString(lastLossAmount, 2), ", Volume=", DoubleToString(lastLossVolume, 2), ", Time=", TimeToString(lastLossTime)); break; } } } if(foundLoss) { for(int i = HistoryDealsTotal() - 1; i >= 0; i--) { ulong dealTicket = HistoryDealGetTicket(i); if(HistoryDealSelect(dealTicket) && HistoryDealGetString(dealTicket, DEAL_SYMBOL) == symbol && HistoryDealGetInteger(dealTicket, DEAL_MAGIC) == InpMagicNumber) { double dealProfit = HistoryDealGetDouble(dealTicket, DEAL_PROFIT); datetime dealTime = (datetime)HistoryDealGetInteger(dealTicket, DEAL_TIME); if(dealTime > lastLossTime) { recoveryProfit += dealProfit; Print("Recovery profit: ", DoubleToString(recoveryProfit, 2), ", Deal Time: ", TimeToString(dealTime)); } } } if(recoveryProfit < lastLossAmount) { isRecoveryMode = true; volume = lastLossVolume * coefficient; double maxAllowedVolume = SymbolInfoDouble(symbol, SYMBOL_VOLUME_MAX); volume = (volume > maxAllowedVolume) ? maxAllowedVolume : volume; Print("In recovery mode. New volume: ", DoubleToString(volume, 2), " (coefficient: ", DoubleToString(coefficient, 2), ")"); } else { Print("Exiting recovery mode. Loss recovered. Recovery profit: ", DoubleToString(recoveryProfit, 2)); } } else { Print("No recent losses found. Using normal volume: ", DoubleToString(volume, 2)); } } ………… 下面是回测里面的日志: 2024.09.23 14:03:03.616 Core 01 2024.04.30 11:00:00 Checking orders for recovery mode from 2024.03.31 11:00 to 2024.04.30 11:002024.09.23 14:03:03.616 Core 01 2024.04.30 11:00:00 Deal found: Time=2024.04.30 10:33, Profit=3852.962024.09.23 14:03:03.616 Core 01 2024.04.30 11:00:00 Deal found: Time=2024.04.30 10:25, Profit=0.002024.09.23 14:03:03.616 Core 01 2024.04.30 11:00:00 Deal found: Time=2024.04.30 09:07, Profit=4397.402024.09.23 14:03:03.616 Core 01 2024.04.30 11:00:00 Deal found: Time=2024.04.30 09:03, Profit=0.002024.09.23 14:03:03.616 Core 01 2024.04.30 11:00:00 Deal found: Time=2024.04.30 08:30, Profit=5255.942024.09.23 14:03:03.616 Core 01 2024.04.30 11:00:00 Deal found: Time=2024.04.30 08:25, Profit=0.002024.09.23 14:03:03.616 Core 01 2024.04.30 11:00:00 Deal found: Time=2024.04.29 19:24, Profit=1895.072024.09.23 14:03:03.616 Core 01 2024.04.30 11:00:00 Deal found: Time=2024.04.29 19:22, Profit=0.002024.09.23 14:03:03.616 Core 01 2024.04.30 11:00:00 Deal found: Time=2024.04.29 19:13, Profit=-16772.942024.09.23 14:03:03.616 Core 01 2024.04.30 11:00:00 Found loss: Amount=16772.94, Volume=10.47, Time=2024.04.29 19:132024.09.23 14:03:03.616 Core 01 2024.04.30 11:00:00 Recovery profit: 3852.96, Deal Time: 2024.04.30 10:332024.09.23 14:03:03.616 Core 01 2024.04.30 11:00:00 Recovery profit: 3852.96, Deal Time: 2024.04.30 10:252024.09.23 14:03:03.616 Core 01 2024.04.30 11:00:00 Recovery profit: 8250.36, Deal Time: 2024.04.30 09:072024.09.23 14:03:03.616 Core 01 2024.04.30 11:00:00 Recovery profit: 8250.36, Deal Time: 2024.04.30 09:032024.09.23 14:03:03.616 Core 01 2024.04.30 11:00:00 Recovery profit: 13506.30, Deal Time: 2024.04.30 08:302024.09.23 14:03:03.616 Core 01 2024.04.30 11:00:00 Recovery profit: 13506.30, Deal Time: 2024.04.30 08:252024.09.23 14:03:03.616 Core 01 2024.04.30 11:00:00 Recovery profit: 15401.37, Deal Time: 2024.04.29 19:242024.09.23 14:03:03.616 Core 01 2024.04.30 11:00:00 Recovery profit: 15401.37, Deal Time: 2024.04.29 19:222024.09.23 14:03:03.616 Core 01 2024.04.30 11:00:00 In recovery mode. New volume: 20.94 (coefficient: 2.00)代码在回测中是完全没有问题的。 下面是实盘中EA的打印日志: 2024.09.23 13:00:01.435 Jade Emperor 4.1 (XAUUSD,H1) Checking orders for recovery mode from 2024.08.24 08:00 to 2024.09.23 08:002024.09.23 13:00:01.435 Jade Emperor 4.1 (XAUUSD,H1) Deal found: Time=2024.09.20 18:42, Profit=113.432024.09.23 13:00:01.435 Jade Emperor 4.1 (XAUUSD,H1) No recent losses found. Using normal volume: 0.58代码在实盘中只找到最近一个订单,而且还是盈利的。 各位老大,帮忙看看,怎么回测中没问题,而实盘中就出错。问题出现在哪里?谢谢。 Better NN EA development ASCTrend system Result of the previous trade 新评论 您错过了交易机会: 免费交易应用程序 8,000+信号可供复制 探索金融市场的经济新闻 注册 登录 拉丁字符(不带空格) 密码将被发送至该邮箱 发生错误 使用 Google 登录 您同意网站政策和使用条款 如果您没有帐号,请注册 可以使用cookies登录MQL5.com网站。 请在您的浏览器中启用必要的设置,否则您将无法登录。 忘记您的登录名/密码? 使用 Google 登录
各位老大,帮忙看看代码哪里出错了???
下面是回测里面的日志:
2024.09.23 14:03:03.616 Core 01 2024.04.30 11:00:00 Checking orders for recovery mode from 2024.03.31 11:00 to 2024.04.30 11:00
2024.09.23 14:03:03.616 Core 01 2024.04.30 11:00:00 Deal found: Time=2024.04.30 10:33, Profit=3852.96
2024.09.23 14:03:03.616 Core 01 2024.04.30 11:00:00 Deal found: Time=2024.04.30 10:25, Profit=0.00
2024.09.23 14:03:03.616 Core 01 2024.04.30 11:00:00 Deal found: Time=2024.04.30 09:07, Profit=4397.40
2024.09.23 14:03:03.616 Core 01 2024.04.30 11:00:00 Deal found: Time=2024.04.30 09:03, Profit=0.00
2024.09.23 14:03:03.616 Core 01 2024.04.30 11:00:00 Deal found: Time=2024.04.30 08:30, Profit=5255.94
2024.09.23 14:03:03.616 Core 01 2024.04.30 11:00:00 Deal found: Time=2024.04.30 08:25, Profit=0.00
2024.09.23 14:03:03.616 Core 01 2024.04.30 11:00:00 Deal found: Time=2024.04.29 19:24, Profit=1895.07
2024.09.23 14:03:03.616 Core 01 2024.04.30 11:00:00 Deal found: Time=2024.04.29 19:22, Profit=0.00
2024.09.23 14:03:03.616 Core 01 2024.04.30 11:00:00 Deal found: Time=2024.04.29 19:13, Profit=-16772.94
2024.09.23 14:03:03.616 Core 01 2024.04.30 11:00:00 Found loss: Amount=16772.94, Volume=10.47, Time=2024.04.29 19:13
2024.09.23 14:03:03.616 Core 01 2024.04.30 11:00:00 Recovery profit: 3852.96, Deal Time: 2024.04.30 10:33
2024.09.23 14:03:03.616 Core 01 2024.04.30 11:00:00 Recovery profit: 3852.96, Deal Time: 2024.04.30 10:25
2024.09.23 14:03:03.616 Core 01 2024.04.30 11:00:00 Recovery profit: 8250.36, Deal Time: 2024.04.30 09:07
2024.09.23 14:03:03.616 Core 01 2024.04.30 11:00:00 Recovery profit: 8250.36, Deal Time: 2024.04.30 09:03
2024.09.23 14:03:03.616 Core 01 2024.04.30 11:00:00 Recovery profit: 13506.30, Deal Time: 2024.04.30 08:30
2024.09.23 14:03:03.616 Core 01 2024.04.30 11:00:00 Recovery profit: 13506.30, Deal Time: 2024.04.30 08:25
2024.09.23 14:03:03.616 Core 01 2024.04.30 11:00:00 Recovery profit: 15401.37, Deal Time: 2024.04.29 19:24
2024.09.23 14:03:03.616 Core 01 2024.04.30 11:00:00 Recovery profit: 15401.37, Deal Time: 2024.04.29 19:22
2024.09.23 14:03:03.616 Core 01 2024.04.30 11:00:00 In recovery mode. New volume: 20.94 (coefficient: 2.00)
代码在回测中是完全没有问题的。
下面是实盘中EA的打印日志:
2024.09.23 13:00:01.435 Jade Emperor 4.1 (XAUUSD,H1) Checking orders for recovery mode from 2024.08.24 08:00 to 2024.09.23 08:00
2024.09.23 13:00:01.435 Jade Emperor 4.1 (XAUUSD,H1) Deal found: Time=2024.09.20 18:42, Profit=113.43
2024.09.23 13:00:01.435 Jade Emperor 4.1 (XAUUSD,H1) No recent losses found. Using normal volume: 0.58
代码在实盘中只找到最近一个订单,而且还是盈利的。
各位老大,帮忙看看,怎么回测中没问题,而实盘中就出错。问题出现在哪里?谢谢。