How to sum the total of the losses for the closed orders as long as the orders closes at losses

To add comments, please log in or register
shartouny
48
shartouny  

Hello everybody,


im trying to sum the total loss of the closed orders that closes on LOSS ,


i tried as much as i can, here is what i got :

double TOTAL_LOSSES()
     {
      double pr_2=0;
      for( i=OrdersHistoryTotal()-1; i>=0; i--)
      {
       if(OrderSelect(i,SELECT_BY_POS,MODE_HISTORY))
       {
        if(OrderSymbol()==Symbol()&&OrderMagicNumber()==MagicNumber)
        {
         if((OrderProfit()+OrderCommission()+OrderSwap())<0)
         {
          pr_2+=(OrderProfit()+OrderCommission()+OrderSwap());
         }
        }
       }return(pr_2);
      }return(pr_2++);
     }

but it seems that its calculating the last Order LOSSES only,


any help appreciated ,

thanks in advance

Keith Watford
Moderator
17654
Keith Watford  
shartouny:
double TOTAL_LOSSES()
     {
      double pr_2=0;
      for( i=OrdersHistoryTotal()-1; i>=0; i--)
      {
       if(OrderSelect(i,SELECT_BY_POS,MODE_HISTORY))
       {
        if(OrderSymbol()==Symbol()&&OrderMagicNumber()==MagicNumber)
        {
         if((OrderProfit()+OrderCommission()+OrderSwap())<0)
         {
          pr_2+=(OrderProfit()+OrderCommission()+OrderSwap());
         }
        }
       }return(pr_2);
      }return(pr_2++);
     }

You are returning after the first run of the loop

shartouny
48
shartouny  
Keith Watford:

You are returning after the first run of the loop

thank you buddy yea i tried it like this now : 

double LOSSES()
     {
      double pr_2=0;
      for( i=OrdersHistoryTotal()-1; i>=0; i--)
      {
       if(OrderSelect(i,SELECT_BY_POS,MODE_HISTORY))
       {
        if(OrderSymbol()==Symbol()&&OrderMagicNumber()==MagicNumber)
        {
         if((OrderProfit()+OrderCommission()+OrderSwap())<0)
         {
          pr_2+=(OrderProfit()+OrderCommission()+OrderSwap());
         }
        }
       }
      }return(pr_2++);
     }

now its summing the losses for all orders from 0 to last one , excluding the profit one,but i want it to return(0) after hitting a takeprofit, any idea how to do that? 

Keith Watford
Moderator
17654
Keith Watford  
shartouny:

thank you buddy yea i tried it like this now : 

now its summing the losses for all orders from 0 to last one , excluding the profit one,but i want it to return(0) after hitting a takeprofit, any idea how to do that? 

Check if the trade earned  profit, if it did, return(0) but what would be the point of that?

shartouny
48
shartouny  
Keith Watford:

Check if the trade earned  profit, if it did, return(0) but what would be the point of that?

yes buddy i know but how to write that in the code? 

Keith Watford
Moderator
17654
Keith Watford  
shartouny:

yes buddy i know but how to write that in the code? 

Please don't refer to me as "buddy".

You already know how to check if it made a loss so it is a tiny step from there to check for a profit. You could even use an else.

To add comments, please log in or register