MT5 ea 求助

 

想获取历史利润,写完后在回测中一直获取的是0

在模拟盘上测试就可以正常获取

测试了好久怀疑是ticket获取不对,因为打印出来都是订单数1,2,3,4的

求懂的大佬指点一下


double probl=0;      //历史利润

   HistorySelect(0,TimeCurrent());

   for(int i=HistoryDealsTotal()-1; i>=0; i--)

     {

      ulong dealticketbl=HistoryDealGetTicket(i);

      Alert(dealticketbl);

      if(HistoryDealGetString(dealticketbl,DEAL_SYMBOL)==Symbol() && HistoryDealGetInteger(dealticketbl,DEAL_MAGIC)==magic && HistoryDealGetInteger(dealticketbl,DEAL_ENTRY)==(1 || 3))

        {

         probl=probl+HistoryDealGetDouble(dealticketbl,DEAL_PROFIT);

        }

     }

附加的文件:
 
// 获取图表显示的该品从某日至此的历史(已平仓)盈亏
double HistoryProfit()
  {
   HistorySelect(DAY,TimeCurrent()); // DAY 即某日开始
   int    i,j,x=0;
   ulong  ticket, Get_ID[10000]={0};
   double yk=0;
   for(i=HistoryDealsTotal()-1;i>=0;i--)
     {
      if((ticket=HistoryDealGetTicket(i))>0)
        {
         if(HistoryDealGetString(ticket,DEAL_SYMBOL)==_Symbol && HistoryDealGetInteger(ticket,DEAL_ENTRY)==DEAL_ENTRY_IN)
           {
            yk=yk+HistoryDealGetDouble(ticket,DEAL_PROFIT)+HistoryDealGetDouble(ticket,DEAL_SWAP)+HistoryDealGetDouble(ticket,DEAL_COMMISSION);
            Get_ID[x]=HistoryDealGetInteger(ticket,DEAL_POSITION_ID);
            x++;
           }
        }
     }
   for(j=0;j<x;j++)
     {
      for(i=0;i<HistoryDealsTotal();i++)
        {
         if((ticket=HistoryDealGetTicket(i))>0)
           {
            if(HistoryDealGetInteger(ticket,DEAL_ENTRY)==DEAL_ENTRY_OUT || HistoryDealGetInteger(ticket,DEAL_ENTRY)==DEAL_ENTRY_OUT_BY)
              {
               if(HistoryDealGetString(ticket,DEAL_SYMBOL)==_Symbol && HistoryDealGetInteger(ticket,DEAL_POSITION_ID)==Get_ID[j])
               yk=yk+HistoryDealGetDouble(ticket,DEAL_PROFIT)+HistoryDealGetDouble(ticket,DEAL_SWAP)+HistoryDealGetDouble(ticket,DEAL_COMMISSION);
              }
           }
        }
     }
   return(yk);
  }
 
// 获取图表显示的该品的持仓总盈亏
double PositionsProfit()
  {
   double yk=0;
   for(int i=0;i<PositionsTotal();i++)
     {
      if(PositionGetSymbol(i)==_Symbol)
      yk=yk+PositionGetDouble(POSITION_PROFIT)+PositionGetDouble(POSITION_SWAP);
     }
   return(yk);
  }