Calculate total dollar amount of all open trades

 

the function below only calculates the dollar amount of the last open trade. I am looking to calculate the dollar amount of all open trades for the currency the EA is on. I can not find what I am doing wrong. can I get some help? thanks in advance.

double LastBuyProfit()
   {
   for(int iPos=OrdersTotal()-1; iPos>=0; iPos--)
      {//loop end to beginning
      if(OrderSelect(iPos,SELECT_BY_POS,MODE_TRADES)==TRUE)
         {//we found a ticket number
         if(OrderSymbol()==Symbol () &&
            OrderMagicNumber()==MagicNumber &&
            OrderType()==OP_BUY
            )
            {//we found a buy order
            return(OrderProfit()+OrderSwap()+OrderCommission());
            }
         }
      }
   return(0.00);
   }
 
jtubbs13791: the function below only calculates the dollar amount of the last open trade. I am looking to calculate the dollar amount of all open trades for the currency the EA is on. I can not find what I am doing wrong. can I get some help? thanks in advance.
  1. Don't double post

  2. return(OrderProfit()+OrderSwap()+OrderCommission());
    You are returning the first trade you find. If you want all open trade, sum them and return the sum.
 
William Roeder #:
  1. Don't double post

  2. You are returning the first trade you find. If you want all open trade, sum them and return the sum.
Where is the other post? I want the same thing
 
Worldwide Fox #: Where is the other post? I want the same thing

If you click on his name, all messages, then you would have found Trying to calculate total profit for trades - Profit Trading - MQL4 and MetaTrader 4 - MQL4 programming forum