Download MetaTrader 5

last_order_profit(int magic)

To add comments, please log in or register
el3reef
188
el3reef  
double last_order_profit(int magic){
 
   for(int i=OrdersHistoryTotal();i >= 0;i--)
     {
     
         OrderSelect(i,SELECT_BY_POS,MODE_HISTORY); 
         if (OrderMagicNumber() == magic){
             
           break;
         }
 
     }
 
   return OrderProfit();
}
Keith Watford
Moderator
10637
Keith Watford  
As in your other topic, is there a point here?
whroeder1
15712
whroeder1  
  for(int i=OrdersHistoryTotal();i >= 0;i--){
     OrderSelect(i,SELECT_BY_POS,MODE_HISTORY); 
     if (OrderMagicNumber() == magic) break;
You are assuming that history is orders, it isn't. Go through all orders and remember the last closed one and it's profit (=OrderProfit()+OrderSwap()+OrderCommission())
To add comments, please log in or register