Return data from Closed Order Manually

 
Guys, I already have the code that returns the total amount that an EA executed on the day.

But when I close the order manually, the magic number is 0 and the function does not count the value.

Would you have any example of how I can capture the data of manually closed orders that started from an EA by magic number?


double retornaValoreDiaFechado()
{

   double Total_Fechadas=0;
   
   datetime time_start;
   
   time_start = (datetime) (86400*(((ulong)TimeCurrent())/86400));
   
   
   if(HistorySelect(time_start,TimeCurrent()))
         for(int i = HistoryDealsTotal() - 1; i >= 0; i--)
           {
            const ulong Ticket = HistoryDealGetTicket(i);
   
            //if(HistoryDealGetInteger(Ticket, DEAL_MAGIC) == in_magic && HistoryDealGetString(Ticket, DEAL_SYMBOL) == _Symbol)
            if(HistoryDealGetInteger(Ticket, DEAL_MAGIC) == in_magic)
               Total_Fechadas += HistoryDealGetDouble(Ticket, DEAL_PROFIT);
           }
   
   return Total_Fechadas;

}

The problem in this case is to know which robot originated the order.

I need to know the value generated by each entry made by the EA even if it was completed manually.

I have more than 1 EA with different magic numbers running on the same symbol.

 

https://www.mql5.com/en/docs/trading/ordergetticket


An example here allows to enumerates Tickets and their magic numbers.

Could you execute it before manual closure, and afterwards. And provide the output here.

I'm not sure whether magic number is affected by manual order closure.


Thanks.

Documentation on MQL5: Trade Functions / OrderGetTicket
Documentation on MQL5: Trade Functions / OrderGetTicket
  • www.mql5.com
OrderGetTicket - Trade Functions - MQL5 Reference - Reference on algorithmic/automated trading language for MetaTrader 5
 

Thanks Siarhei, I managed to solve in a similar way.


 double retornaValoreDiaFechado()
{

   double Total_Fechadas= 0 ;
   
   datetime time_start;
   
   time_start = ( datetime ) ( 86400 *((( ulong ) TimeCurrent ())/ 86400 ));
   double position_id;
   
   if ( HistorySelect (time_start, TimeCurrent ()))
   {
      
       int hst = HistoryDealsTotal ();
   
       for ( int i = hst - 1 ; i >= 0 ; i--)
      {
         const ulong Ticket = HistoryDealGetTicket (i);
            
         if ( HistoryDealGetInteger (Ticket, DEAL_MAGIC ) == in_magic)
            Total_Fechadas += HistoryDealGetDouble (Ticket, DEAL_PROFIT );
         else if ( HistoryDealGetInteger (Ticket, DEAL_MAGIC ) == 0 )
         {
            position_id = HistoryDealGetInteger (Ticket, DEAL_POSITION_ID );
                        
             for ( int ii = hst - 1 ; ii >= 0 ; ii--)
            {
               ulong Ticket2 = HistoryDealGetTicket (ii);
               if ( HistoryDealGetInteger (Ticket2, DEAL_MAGIC ) == in_magic && HistoryDealGetInteger (Ticket2, DEAL_POSITION_ID ) == position_id)
                  Total_Fechadas += HistoryDealGetDouble (Ticket, DEAL_PROFIT );
            } 
         }
              
      }
           
   }
   
   return Total_Fechadas;

}
Reason: