CloseAll

它执行满仓的部分平仓。

virtual bool  CloseAll(
   double    lot    // 手数
   )

参数

lot

[输入] 减仓的手数。

返回值

true 如果交易操作已被执行, 否则 false。

注释

在“单边持仓”模式,使用CExpertTrade::Buy或CExpertTrade::Sell 类函数来平仓。在“锁仓持仓”模式,则使用CTrade::PositionClose 类函数,它也可以用于单边模式下的账户。DeleteOrders()类函数用于删除订单。

实现

//+------------------------------------------------------------------+
//| 平仓并删除订单                                 |
//| 输入:  手数 - 平仓交易量。                                 |
//| OUTPUT: true-if trade operation processed, false otherwise.      |
//| 备注: 无。                                                     |
//+------------------------------------------------------------------+
bool CExpert::CloseAll(double lot)
  {
   bool result;
//--- 检查平仓操作
   if(m_position.PositionType()==POSITION_TYPE_BUY) result=m_trade.Sell(lot,0,0,0);
   else                                     result=m_trade.Buy(lot,0,0,0);
   result|=DeleteOrders();
//---
   return(result);
  }