Помогите разобраться со сделкой

 

Есть в Истории сделка типа DEAL_ENTRY_OUT. Хочу получить ее магик. И получаю через deal.Magic(); НО в конце теста эта сделка имеет Магик = 0. Как получить Магик последней закрытой позиции ? Пытался найти сделку которая породила эту позицию, но как то это криво и не получается. Какие еще есть варианты ? 

 

DEAL_POSITION_ID == ORDER_TICKET_open -> ORDER_MAGIC.

 
Dmitiry Ananiev:

Есть в Истории сделка типа DEAL_ENTRY_OUT. Хочу получить ее магик. И получаю через deal.Magic(); НО в конце теста эта сделка имеет Магик = 0. Как получить Магик последней закрытой позиции ? Пытался найти сделку которая породила эту позицию, но как то это криво и не получается. Какие еще есть варианты ? 

Пример для тестера: открываем BUY 0.3 с Magic '258' и в конце теста тестер сам закрывает позицию (аналог ручного закрытия - Magic равен '0').

И распечатка всей истории:

Deal:
|Ticket              |Order               |Time                |Time msc            |Type                |Entry               |Magic               |Reason              |Position ID        
|1                   |0                   |2020.03.19 00:00:00 |1584576000000       |DEAL_TYPE_BALANCE   |DEAL_ENTRY_IN       |0                   |DEAL_REASON_CLIENT  |0                  
|Volume              |Price               |Commission          |Swap                |Profit              |Symbol              |Comment                                  |External ID        
|0.00                |0.00000             |0.00                |0.00                |10000.00            |                    |                                         |                   
Order 0 is not found in the trade history between the dates 2017.08.07 11:06:20 and 2020.07.15 23:59:59

Deal:
|Ticket              |Order               |Time                |Time msc            |Type                |Entry               |Magic               |Reason              |Position ID        
|2                   |2                   |2020.03.19 00:00:10 |1584576010200       |DEAL_TYPE_BUY       |DEAL_ENTRY_IN       |258                 |DEAL_REASON_EXPERT  |2                  
|Volume              |Price               |Commission          |Swap                |Profit              |Symbol              |Comment                                  |External ID        
|0.30                |1.09131             |0.00                |0.00                |0.00                |EURUSD              |                                         |                   
Order:
|Ticket              |Time setup          |Type                |State               |Time expiration     |Time done           |Time setup msc      |Time done msc       |Type filling       
|2                   |2020.03.19 00:00:10 |ORDER_TYPE_BUY      |ORDER_STATE_FILLED  |2020.03.19 00:00:10 |2020.03.19 00:00:10 |1584576010200       |1584576010200       |ORDER_FILLING_FOK  
|Type time           |Magic               |Reason              |Position id         |Position by id     
|1970.01.01 00:00:00 |258                 |ORDER_REASON_EXPERT |2                   |0                  
|Volume initial      |Volume current      |Open price          |sl                  |tp                  |Price current       |Price stoplimit    
|0.30                |0.00                |1.09131             |0.00000             |0.00000             |1.09119             |0.00000            
|Symbol              |Comment                                  |External id        
|EURUSD              |                                         |                   

Deal:
|Ticket              |Order               |Time                |Time msc            |Type                |Entry               |Magic               |Reason              |Position ID        
|3                   |3                   |2020.07.14 23:59:59 |1594771199000       |DEAL_TYPE_SELL      |DEAL_ENTRY_OUT      |0                   |DEAL_REASON_CLIENT  |2                  
|Volume              |Price               |Commission          |Swap                |Profit              |Symbol              |Comment                                  |External ID        
|0.30                |1.13993             |0.00                |-24.15              |1458.60             |EURUSD              |end of test                              |                   
Order:
|Ticket              |Time setup          |Type                |State               |Time expiration     |Time done           |Time setup msc      |Time done msc       |Type filling       
|3                   |2020.07.14 23:59:59 |ORDER_TYPE_SELL     |ORDER_STATE_FILLED  |2020.07.14 23:59:59 |2020.07.14 23:59:59 |1594771199000       |1594771199000       |ORDER_FILLING_FOK  
|Type time           |Magic               |Reason              |Position id         |Position by id     
|1970.01.01 00:00:00 |0                   |ORDER_REASON_CLIENT |2                   |0                  
|Volume initial      |Volume current      |Open price          |sl                  |tp                  |Price current       |Price stoplimit    
|0.30                |0.00                |1.13993             |0.00000             |0.00000             |1.13993             |0.00000            
|Symbol              |Comment                                  |External id        
|EURUSD              |end of test                              |  

По распечатке можно хорошо видеть взаимосвязи тикетов и идентификатора позиции

 
void CalcProfit()
  {
   HistorySelect(0, TimeCurrent());
   ulong    ticket = 0;
   double pro[10] = {0};
   int tr[10] = {0};
   for(int i = HistoryDealsTotal() - 1; i >= 0; i--)
     {
      if((ticket = HistoryDealGetTicket(i)) > 0)
        {
         if(HistoryDealGetInteger(ticket, DEAL_ENTRY) == DEAL_ENTRY_OUT)
           {
            int posid = (int) HistoryDealGetInteger(ticket, DEAL_POSITION_ID);
            int orticket = (int) PositionGetInteger(POSITION_IDENTIFIER);
            int magic = (int) HistoryOrderGetInteger(orticket, ORDER_MAGIC);
            Print(orticket, "  ", magic);
            double profit = HistoryDealGetDouble(ticket, DEAL_PROFIT);
            double swap = HistoryDealGetDouble(ticket, DEAL_SWAP);
            double comiss = HistoryDealGetDouble(ticket, DEAL_COMMISSION);
            Print(ticket, "   ", magic, "  ", profit, "   ", swap, "   ", comiss);
            pro[magic] += profit + swap + comiss * 2;
            tr[magic] ++;
           }
        }
     }
   for(int i = 0; i < 10; i++)
     {
      Print("Profit mag ", i + 1, " = ", pro[i], "  ", tr[i]);
     }
  }

Вот такой код. Ордера имеют Магики 1,2,3 ит.д.
Магик неправильно определяется. В чем проблема ? 

 
Dmitiry Ananiev:

Магик неправильно определяется. В чем проблема ? 

int magic = (int) HistoryOrderGetInteger(posid, ORDER_MAGIC);
 
Спасибо ! 
Причина обращения: