HistoryDealGetDouble

返回要求的交易属性,交易属性一定是双精度型,有2中变量函数可供使用。

1. 立即返回属性值。

double  HistoryDealGetDouble(
   ulong                      ticket_number,     // 订单号
   ENUM_DEAL_PROPERTY_DOUBLE  property_id        // 属性标识符
   );

2. 依据函数成功与否返回真值或者错误值。如果成功,目标变量的属性值通过引用传递到最后参量。

bool  HistoryDealGetDouble(
   ulong                      ticket_number,     // 订单号
   ENUM_DEAL_PROPERTY_DOUBLE  property_id,       // 属性标识符
   double&                    double_var         // 这里接受属性值
   );

参量

ticket_number

[in]  交易订单号。

property_id

[in] 交易属性标识符。值可以是 ENUM_DEAL_PROPERTY_DOUBLE enumeration列举值中的一个。

double_var

[out]  接收要求属性值的双精度类型变量。

返回值

双精度 型值。

注释

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

示例:

//+------------------------------------------------------------------+
//| 脚本程序起始函数                                                    |
//+------------------------------------------------------------------+
void OnStart()
  {
//--- 请求交易和订单历史
   if(!HistorySelect(0TimeCurrent()))
     {
      Print("HistorySelect() failed. Error "GetLastError());
      return;
     }
 
//--- 根据账户历史中的交易列表做循环
   int total=HistoryDealsTotal();
   for(int i=0i<totali++)
     {
      //--- 取得下一个交易的编号 (自动选择交易以取得它的属性)
      ulong ticket=HistoryDealGetTicket(i);
      if(ticket==0)
         continue;
      
      //--- 取得交易的类型和方向并显示选中交易实数属性列表的标题
      string type=DealTypeDescription((ENUM_DEAL_TYPE)HistoryDealGetInteger(ticketDEAL_TYPE));
      string entry=DealEntryDescription((ENUM_DEAL_ENTRY)HistoryDealGetInteger(ticketDEAL_ENTRY));
      PrintFormat("Double properties of an deal %s entry %s #%I64u:"typeentryticket);
      
      //--- 在标题下方打印选中交易的全部实数类型属性
      HistoryDealPropertiesDoublePrint(ticket12);
     }
   /*
   real:
   Double properties of an deal Buy entry In #2785070622:
   Volume:     0.50
   Price:      1.10480
   Commission0.00
   Swap:       0.00
   Profit:     0.00 USD
   Fee:        0.00
   StopLoss:   0.00000
   TakeProfit0.00000
   Double properties of an deal Sell entry Out #2785071538:
   Volume:     0.50
   Price:      1.10491
   Commission0.00
   Swap:       0.00
   Profit:     5.50 USD
   Fee:        0.00
   StopLoss:   0.00000
   TakeProfit0.00000
   */
  }
//+------------------------------------------------------------------+
//| 在日志中显示选中交易的实数类型属性                                    |
//+------------------------------------------------------------------+
void HistoryDealPropertiesDoublePrint(const ulong ticketconst uint header_width=0)
  {
   uint   w=0;
   string header="";
   double value=0;
   
//--- 取得交易的交易品种, 利润货币和交易品种的小数点位数
   string symbol  = HistoryDealGetString(ticketDEAL_SYMBOL);
   string currencySymbolInfoString(symbolSYMBOL_CURRENCY_PROFIT);
   int    digits  = (int)SymbolInfoInteger(symbolSYMBOL_DIGITS);
   
//--- 定义标题文字和标题栏位的宽度
//--- 如果传给函数的标题宽度为0, 则宽度为标题文字行的大小+1
   header="Volume:";
   w=(header_width==0 ? header.Length()+1 : header_width);
//--- 取得并在日志中使用指定的标题宽度显示交易量
   if(!HistoryDealGetDouble(ticketDEAL_VOLUMEvalue))
      return;
   PrintFormat("%-*s%-.2f"wheadervalue);
   
//--- 在日志中显示价格
   header="Price:";
   w=(header_width==0 ? header.Length()+1 : header_width);
   if(!HistoryDealGetDouble(ticketDEAL_PRICEvalue))
      return;
   PrintFormat("%-*s%-.*f"wheaderdigitsvalue);
   
//--- 在日志中显示交易佣金
   header="Commission:";
   w=(header_width==0 ? header.Length()+1 : header_width);
   if(!HistoryDealGetDouble(ticketDEAL_COMMISSIONvalue))
      return;
   PrintFormat("%-*s%-.2f"wheadervalue);
   
//--- 在日志中显示平仓时的累积库存费
   header="Swap:";
   w=(header_width==0 ? header.Length()+1 : header_width);
   if(!HistoryDealGetDouble(ticketDEAL_SWAPvalue))
      return;
   PrintFormat("%-*s%-.2f"wheadervalue);
   
//--- 在日志中显示交易的财务结果
   header="Profit:";
   w=(header_width==0 ? header.Length()+1 : header_width);
   if(!HistoryDealGetDouble(ticketDEAL_PROFITvalue))
      return;
   PrintFormat("%-*s%-.2f %s"wheadervaluecurrency);
   
//--- 在日志中显示交易费用
   header="Fee:";
   w=(header_width==0 ? header.Length()+1 : header_width);
   if(!HistoryDealGetDouble(ticketDEAL_FEEvalue))
      return;
   PrintFormat("%-*s%-.2f"wheadervalue);
   
//--- 在日志中显示止损水平
   header="StopLoss:";
   w=(header_width==0 ? header.Length()+1 : header_width);
   if(!HistoryDealGetDouble(ticketDEAL_SLvalue))
      return;
   PrintFormat("%-*s%-.*f"wheaderdigitsvalue);
 
//--- 在日志中显示止盈水平
   header="TakeProfit:";
   w=(header_width==0 ? header.Length()+1 : header_width);
   if(!HistoryDealGetDouble(ticketDEAL_TPvalue))
      return;
   PrintFormat("%-*s%-.*f"wheaderdigitsvalue);
  }
//+------------------------------------------------------------------+
//| 返回交易类型的描述                                                  |
//+------------------------------------------------------------------+
string DealTypeDescription(const ENUM_DEAL_TYPE type)
  {
   switch(type)
     {
      case DEAL_TYPE_BUY                     :  return("Buy");
      case DEAL_TYPE_SELL                    :  return("Sell");
      case DEAL_TYPE_BALANCE                 :  return("Balance");
      case DEAL_TYPE_CREDIT                  :  return("Credit");
      case DEAL_TYPE_CHARGE                  :  return("Additional charge");
      case DEAL_TYPE_CORRECTION              :  return("Correction");
      case DEAL_TYPE_BONUS                   :  return("Bonus");
      case DEAL_TYPE_COMMISSION              :  return("Additional commission");
      case DEAL_TYPE_COMMISSION_DAILY        :  return("Daily commission");
      case DEAL_TYPE_COMMISSION_MONTHLY      :  return("Monthly commission");
      case DEAL_TYPE_COMMISSION_AGENT_DAILY  :  return("Daily agent commission");
      case DEAL_TYPE_COMMISSION_AGENT_MONTHLY:  return("Monthly agent commission");
      case DEAL_TYPE_INTEREST                :  return("Interest rate");
      case DEAL_TYPE_BUY_CANCELED            :  return("Canceled buy deal");
      case DEAL_TYPE_SELL_CANCELED           :  return("Canceled sell deal");
      case DEAL_DIVIDEND                     :  return("Dividend operations");
      case DEAL_DIVIDEND_FRANKED             :  return("Franked (non-taxable) dividend operations");
      case DEAL_TAX                          :  return("Tax charges");
      default                                :  return("Unknown deal type: "+(string)type);
     }
  }
//+------------------------------------------------------------------+
//| 返回仓位变化的方法                                                  |
//+------------------------------------------------------------------+
string DealEntryDescription(const ENUM_DEAL_ENTRY entry)
  {
   switch(entry)
     {
      case DEAL_ENTRY_IN      :  return("In");
      case DEAL_ENTRY_OUT     :  return("Out");
      case DEAL_ENTRY_INOUT   :  return("Reverce");
      case DEAL_ENTRY_OUT_BY  :  return("Out by");
      case DEAL_ENTRY_STATE   :  return("Status record");
      default                 :  return("Unknown deal entry: "+(string)entry);
     }
  }

另见

HistorySelect()HistoryDealsTotal()HistoryDealGetTicket(), 交易属性