如何获取一笔交易当前的浮动盈亏呢?

enbo lu  

HistoryDealGetDouble(deal_ticket,DEAL_PROFIT)

你要管理组成某一个position的deals,首先用 PositionGetInteger(POSITION_IDENTIFIER获取交易对象的 position_id,然后用 HistorySelectByPosition(position_id) 来载入该头寸的历史数据,接着用 HistoryDealsTotal() 获取组成该position的所有deal数量,再遍历 deals 用 HistoryDealGetXX()来获取每一个deal的属性。

https://www.mql5.com/en/forum/9701/page1 

MQL5: Get the amount of deals since the postions was (re)opened
MQL5: Get the amount of deals since the postions was (re)opened
  • www.mql5.com
So for example if I do the following trades on any currency pair:. - - Category: expert advisors and automated trading
Amy Liu  
luenbo:

HistoryDealGetDouble(deal_ticket,DEAL_PROFIT)

你要管理组成某一个position的deals,首先用 PositionGetInteger(POSITION_IDENTIFIER获取交易对象的 position_id,然后用 HistorySelectByPosition(position_id) 来载入该头寸的历史数据,接着用 HistoryDealsTotal() 获取组成该position的所有deal数量,再遍历 deals 用 HistoryDealGetXX()来获取每一个deal的属性。

https://www.mql5.com/en/forum/9701/page1 

谢谢版主,我是这么做的,但是 HistoryDealGetXX()来获取每一个deal的属性时,DEAL_PROFIT仅对ENUM_DEAL_ENTRY为DEAL_ENTRY_OUT的deal有效,这时返回的就不是浮动权益了,而是实际损益。DEAL_ENTRY_IN的deal,DEAL_PROFIT属性返回值为0。所以,我的问题实际上是如何获取DEAL_ENTRY_IN的deal的浮动权益?
enbo lu  

通过DEAL_PRICE 和现价 ,同时考虑 DEAL_SWAP ,DEAL_COMMISSION 计算一下吧。

另外,重新审视原始需求,也许会发现其他方式。 

Amy Liu  
luenbo:

通过DEAL_PRICE 和现价 ,同时考虑 DEAL_SWAP ,DEAL_COMMISSION 计算一下吧。

另外,重新审视原始需求,也许会发现其他方式。 

非常感谢!
原因: