Download MetaTrader 5

Summing up open buy and sell orders profits

To add comments, please log in or register
prweza
239
prweza  

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.

Dua Yong Rew
5510
Dua Yong Rew  

seems correct

prweza
239
prweza  
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
239
prweza  
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.

Dua Yong Rew
5510
Dua Yong Rew  

Post the code on how u close the order

whroeder1
15917
whroeder1  
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

To add comments, please log in or register