MQL5中OnTradeTransaction取值DEAL_ENTRY总是0是为什么

 

Hi , all


我在OnTradeTransaction函数中,HistoryDealGetInteger(dealTicket, DEAL_ENTRY)总是取值为0,应该是分为DEAL_ENTRY_IN和DEAL_ENTRY_OUT两个值的,请问这是为什么?

void OnTradeTransaction(const MqlTradeTransaction& trans,
                        const MqlTradeRequest& request,
                        const MqlTradeResult& result) {
//---
   switch(trans.type) {
   case  TRADE_TRANSACTION_DEAL_ADD: {
      ulong dealTicket = trans.order;
      ulong positionID = trans.order;
      
      for(int i = 0; i < 50; i++) {
         if(HistoryDealGetInteger(dealTicket, DEAL_TIME) > 0)
            break;
         Sleep(10);
      }      
      ENUM_DEAL_ENTRY deal_entry = (ENUM_DEAL_ENTRY)HistoryDealGetInteger(dealTicket, DEAL_ENTRY);
      ENUM_DEAL_REASON deal_reason = (ENUM_DEAL_REASON)HistoryDealGetInteger(dealTicket, DEAL_REASON);

      printf("dealTicket=="+dealTicket);
      printf("positionID=="+positionID);
      printf("DEAL_ENTRY_IN=="+DEAL_ENTRY_IN);
      printf("DEAL_ENTRY_OUT=="+DEAL_ENTRY_OUT);
      printf("deal_entry=="+IntegerToString(deal_entry));//result:0
      printf("deal_reason=="+IntegerToString(deal_reason));//result:0
      if(deal_entry == DEAL_ENTRY_OUT) {
         printf("111");
         if(positionInfo.SelectByTicket(positionID)) {
            double positionProfit = positionInfo.Profit();  // 使用系统自带的Profit函数

            // 判断是否亏损
            printf("positionProfit==="+positionProfit);
            if(positionProfit < 0) {
               LossCount++;
            }
         }
      }
      // 检查是否是平仓相关的交易原因
      if(deal_reason == DEAL_REASON_SL ||
            deal_reason == DEAL_REASON_TP ||
            deal_reason == DEAL_REASON_SO ) {
         // 通过positionID获取持仓信息
      };
   }
   break;
   }
}