Download MetaTrader 5
To add comments, please log in or register
Articles can help you to solidify your knowledge. Come and read them!
el3reef
178
el3reef 2016.08.23 13:54 
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
7887
Keith Watford 2016.08.23 14:20  
As in your other topic, is there a point here?
whroeder1
13596
whroeder1 2016.08.23 16:36  
  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