Download MetaTrader 5


To add comments, please log in or register
Having troubles understanding the code? Perhaps, you can find an article on that topic!
el3reef 2016.10.05 13:53 

for sharing and improving


double last_closed_order_profit(int Magic){
     double orderStopLoss;
     for(int i= OrdersHistoryTotal() ;i >= 0;i--)
        if (OrderMagicNumber() == Magic) break;
   return OrderProfit();


 Waiting for comments and developing

Keith Watford
Keith Watford 2016.10.05 18:31  

Consecutive selection of orders using the SELECT_BY_POS parameter returns information in the sequence in which it was received from the trading server. Sorting of the resulting list of orders cannot be guaranteed.

From the documentation.

Your code does not necessarily find the last closed order, it finds the order in the highest position in the list that has the magic number.

To add comments, please log in or register