Print OrderProfit of last 5 close trade

 

Hi guys, with my EA I would to know the profit about the 5 last close position, but I have a question.

Why this one works

   if(OrderSelect(OrdersHistoryTotal()-5,SELECT_BY_POS,MODE_HISTORY))
   {  
   Print("Profit is ", OrderProfit());
   }
   else Print("OrderSelect returned the error of ",GetLastError());
   if(OrderSelect(OrdersHistoryTotal()-4,SELECT_BY_POS,MODE_HISTORY))
   {  
   Print("Profit is ", OrderProfit());;
   }
   else Print("OrderSelect returned the error of ",GetLastError());
   
   if(OrderSelect(OrdersHistoryTotal()-3,SELECT_BY_POS,MODE_HISTORY))
   {  
   Print("Profit is ", OrderProfit());
   }
   else Print("OrderSelect returned the error of ",GetLastError());
   
   if(OrderSelect(OrdersHistoryTotal()-2,SELECT_BY_POS,MODE_HISTORY))
   {  
   Print("Profit is ", OrderProfit());
   }
   else Print("OrderSelect returned the error of ",GetLastError());
   if(OrderSelect(OrdersHistoryTotal()-1,SELECT_BY_POS,MODE_HISTORY))
   {  
   Print("Profit is ", OrderProfit());
   }
   else Print("OrderSelect returned the error of ",GetLastError());

and this one not?
I cannot understand

for(i=5;i<=0;i--)
{
    if(OrderSelect(OrdersHistoryTotal()-i,SELECT_BY_POS,MODE_HISTORY))
   {  
   Print("Profit is ", OrderProfit());
   }
   else Print("OrderSelect returned the error of ",GetLastError());

Thank you for the support

 
steven.beqiri:

Hi guys, with my EA I would to know the profit about the 5 last close position, but I have a question.

Why this one works

and this one not?
I cannot understand

Thank you for the support

You say it does not work but not what error(s) you get....

the i=5  is a static value in your loop but there maybe more or less orders than this so you need to adjust it to the number of orders available

then loop through them selecting the ones that you want