Summing up open buy and sell orders profits

 

Hi

I have got a code but it doesn't seem to work properly.

The EA opens 1 buy and 1 Sell trade of the same pair. I want the code to calculate the total profit of the two orders and return the result. I have got this function.


 double Money()

 {

   double sum_profits = 0;

      int i, iOrders = OrdersTotal() - 1;        //
   for(i = iOrders; i >= 0; i--)

  {

   if(OrderSelect(i, SELECT_BY_POS, MODE_TRADES)==true)

   {    

      if( Symbol() == OrderSymbol())  sum_profits += OrderProfit();

   }

  } 

   return( sum_profits );

}  

 It doesn't seem to work. Any ideas  what went wrong?

Thanks.


Thanks.

 

seems correct

 
Dua Yong Rew:

seems correct


It still does not work. Basically im trying to close the two orders if total profit is greater than  0 is there a problem with my closing order function

 
prweza:

It still does not work. Basically im trying to close the two orders if total profit is greater than  0 is there a problem with my closing order function


OK I think my problem is closing the two orders. I have two orders open one is  buy and the other is a sell. i want to close both orders  when the sum of all profits is greater than 0. I have used the sum of profit code above but it seems that only one order gets closed.  Could someone let me know how to close both orders?


Thanks.

 

Post the code on how u close the order

 
Dua Yong Rew: Post the code on how u close the order

Please don't write "u" Please don't write ur - it's "you are" or "your" - MQL4 and MetaTrader 4 - MQL4 programming forum