Download MetaTrader 5
To add comments, please log in or register
Having difficulties in understanding the Trading Signals service? Read the article!
DeanDeV
330
DeanDeV 2015.07.03 09:14 

Hey guys,

Is there any way to keep track of the profit that the same EA has made per pair while trading?

Thanks 

honest_knave
Moderator
1888
honest_knave 2015.07.03 09:29  

Yep, use Magic Numbers.

You can then either code your own means to track the trade, or simply connect the account to one of the sites offering trade explorers that can break down by magic number and symbol.

Keith Watford
Moderator
9544
Keith Watford 2015.07.03 09:29  

Loop through closed orders and sum profit for those with the magic number and symbol.

If you need to check open orders, loop through the open orders and add those with the magic number and symbol.

whroeder1
14237
Lynn
49
Lynn 2016.03.22 12:35  
GumRai:

Loop through closed orders and sum profit for those with the magic number and symbol.

If you need to check open orders, loop through the open orders and add those with the magic number and symbol.

GumRai:

 

I am using the code below to try and loop through closed orders and then sum profits by symbol with no success (I did change OrdersTotal() to OrdersHistoryTotal() and MODE_TRADES to MODE_HISTORY). Can you help? I am trying to return the total profit for ALL trades of one symbol in the Account History tab (prefer not to use Magic #s). Thanks in advance for your assistance.

   {
   int i, iOrders = OrdersTotal() - 1;        //defining running parameter for below
   double sum_profits = 0;
  
   for(i = iOrders; i >= 0; i--)
   {
   OrderSelect( i, SELECT_BY_POS, MODE_TRADES );     
      if( Symbol() == OrderSymbol() &&
          OrderMagicNumber() == Magic )
      {
          sum_profits += OrderProfit();
      }        
   }
   
   return( sum_profits ); 

   } 

Keith Watford
Moderator
9544
Keith Watford 2016.03.22 12:51  
7455:

GumRai:

 

I am using the code below to try and loop through closed orders and then sum profits by symbol with no success (I did change OrdersTotal() to OrdersHistoryTotal() and MODE_TRADES to MODE_HISTORY). Can you help? I am trying to return the total profit for ALL trades of one symbol in the Account History tab (prefer not to use Magic #s). Thanks in advance for your assistance.

   } 

I don't see anything wrong with the code that you have posted.

It should give you net profits for open orders that are of the chart symbol and the EA's magic number.

If you prefer to check without the magic number, then remove the check.

Show your code for checking closed trades.

Lynn
49
Lynn 2016.03.22 13:14  
GumRai:

I don't see anything wrong with the code that you have posted.

It should give you net profits for open orders that are of the chart symbol and the EA's magic number.

If you prefer to check without the magic number, then remove the check.

Show your code for checking closed trades.

Here my code. The sum profit seemingly changes when an order for the symbol has not closed (I run the EA on several charts/symbols)

{

  int i, iOrders = OrdersHistoryTotal() - 1; 

   double sum_profits = 0;

 

   for(i = iOrders; i >= 0; i--)

   {

   OrderSelect( i, SELECT_BY_POS, MODE_HISTORY);    

      if( Symbol() == OrderSymbol())

)

      {

          sum_profits += OrderProfit();

      }       

   }

  

   return( sum_profits ); 
Keith Watford
Moderator
9544
Keith Watford 2016.03.22 13:34  
      if( Symbol() == OrderSymbol())

   )


Does the code compile?

You seem to have a stray close bracket

Lynn
49
Lynn 2016.03.22 17:44  
GumRai:


Does the code compile?

You seem to have a stray close bracket

No, it did not compile. However, I changed to a custom function (see below), but it still does not seem to calculate correctly. Is the code correct to sum the total of ALL profits for a particular symbol of ALL closed orders of that symbol found in the Account History tab?

 double Money()

 {

   double sum_profits = 0;

   int i, iOrders = OrdersHistoryTotal() - 1;        //defining running parameter for below

   

   for(i = iOrders; i >= 0; i--)

  {

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

   {    

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

   }

  } 

   return( sum_profits );

}     

Keith Watford
Moderator
9544
Keith Watford 2016.03.22 18:33  

The only thing that I can see is that you don't include commisions and swaps,

 
      sum_profits += OrderProfit()+OrderCommission()+OrderSwap();
Lynn
49
Lynn 2016.03.22 18:41  
GumRai:

The only thing that I can see is that you don't include commisions and swaps,

Great!! I'll give it a whirl and let  you know. Thanks!
/ /12
To add comments, please log in or register