Last Closed Order with Loos

 

Hello,

i am searching for a code example that can give me the last closed Order profit, wich have beend close with a loose.

I have here a own code example, but i am not sure if this will work always right, for example i dont know if that work when somebody does changes the order history from oldest trades sorting or if he sort in the orderhistory the trades with profit value and so on there are many different ways how somebody can sort hisself the orderhistory and i dont know if my code does work then right.

This is my code:

for (int i = OrdersHistoryTotal() - 1; i >= 0; i--) 
   {
      OrderSelect(i, SELECT_BY_POS, MODE_HISTORY);
      if (OrderProfit()<=0) 
      {
         return(OrderProfit());
      }
   }
 
No it will not. The order in history is not always ordered by close time. Order History sort by closing date - MQL4 forum
 
thank you that functions from you look good.
 
PlanandTrade :
thank you that functions from you look good.


Your code is not selecting OrderSymbol() not selecting OrderMagicNumber() and it doesn't even care what OrderType() it selects

Even when the sorting of OrderHistory is correct then also i have to Ask to you

how do you know you get the result you search ??

My answer would be

You Can't !!!!

 
deVries:


Your code is not selecting OrderSymbol() not selecting OrderMagicNumber() and it doesn't even care what OrderType() it selects

Even when the sorting of OrderHistory is correct then also i have to Ask to you

how do you know you get the result you search ??

My answer would be

You Can't !!!!


that was just a simple example, my original loop looks other. but i did ask because i had not now how the orderhistory structur work.