代码返回值混乱。求解

 

a

打印结果必须放在循环体外,才能得到总的亏损,不然循环一次就打 一次,结果就不是总体的亏损
b

 
这么写会出问题的。。入金出金的利润都会加上,,,比如入金1000美金会变成  a=a+1000的;
 

你这好像是MT4,MT4不太了解,MT5是这样:

帮助文档已经写了

HistoryDealGetDouble




注释

不要弄混 订单交易仓位。 每笔交易都按照订单执行,每个仓位都是一个或多个交易的值。

英文版是

Note

Do not confuse orders, deals and positions. Each deal is the result of the execution of an order, each position is the summary result of one or more deals.



order deal position是三种不同的东西,你是不是获取错了。

Documentation on MQL5: Constants, Enumerations and Structures / Trade Constants / Order Properties
Documentation on MQL5: Constants, Enumerations and Structures / Trade Constants / Order Properties
  • www.mql5.com
Order Properties - Trade Constants - Constants, Enumerations and Structures - MQL5 Reference - Reference on algorithmic/automated trading language for MetaTrader 5
 

1、pirnt 放在 return (a )前一行的位置。

2、或者直接把print那行直接删除了,调用函数的时候在打印。

比如:

double SellHisLoss=sellloss();

printf(_Symbol+"历史空单总亏损: %f",SellHisLoss); 

原因: