how can i count how many lost orders and how many profit orders in the expert history?

 

i searched very hard for this issue i want to count total lost orders in order history and total profit orders in the closed orders not open orders .... after i searched i found this code but seems doesnt work dont know what's wrong with it


int TotalLostOrders()
{
 int TotalLost;
 for(int i=OrdersHistoryTotal()-1;i>=0;i--)
 {
  OrderSelect(i,SELECT_BY_POS,MODE_HISTORY);
  if(OrderSymbol()==Symbol()&&OrderMagicNumber()==MagicNumber)
  {
   if(OrderProfit()<0)TotalLost++;
   else return(TotalLost);
  }
 }
 return(TotalLost);

 
mosta777:

i searched very hard for this issue i want to count total lost orders in order history and total profit orders in the closed orders not open orders .... after i searched i found this code but seems doesnt work dont know what's wrong with it 

"doesn't work' can mean many things, but this line:

   else return(TotalLost);

should be changed to:

continue;

instead, since you may not have checked all history orders yet.

 
  1. Please edit your (original) post and use the CODE button (Alt-S)! (For large amounts of code, attach it.)
              General rules and best pratices of the Forum. - General - MQL5 programming forum
              Messages Editor

  2. "Doesn't work" is meaningless - just like saying the car doesn't work. Doesn't start, won't go in gear, no electrical, missing the key, flat tires - meaningless.
  3. As Seng said, or just remove the line completely. You want to process all of history, not just the first entry found.

  4. Why did you post your MT4 question in the Root / MT5 General section instead of the MQL4 section, (bottom of the Root page?)
              General rules and best pratices of the Forum. - General - MQL5 programming forum
    Next time post in the correct place. The moderators will likely move this thread there soon.

  5. Do not assume history has only closed orders. You need to add OrderType to your filter.
    Do not assume history is ordered by date, it's not.
              Could EA Really Live By Order_History Alone? (ubzen) - MQL4 programming forum
Reason: