MQL4 - automated forex trading   /  

Forum

How to total up the profit/loss of two or more open trades(different currency pair)?

Back to topics list To post a new topic, please log in or register

avatar
11
pwfx 2006.09.11 19:13 
can anyone guide me how to total up ? why the function of "TotalProfit" in MQL II no longer be used in MQL4?
Two-Stage Modification of Opened Positions

Two-Stage Modification of Opened Positions

The two-stage approach allows you to avoid the unnecessary closing and re-opening of positions in situations close to the trend and in cases of possible occurrence of divirgence.


avatar
233
codersguru 2006.09.12 16:21 
Here's TotalProfit() back:

double TotalProfit()
{
      int total  = OrdersTotal();
      double MyCurrentProfit=0;
      for (int cnt = 0 ; cnt < total ; cnt++)
      {
         OrderSelect(cnt,SELECT_BY_POS,MODE_TRADES);
         MyCurrentProfit += OrderProfit();
      }
      Return(MyCurrentProfit);
}

Hope it helps!

avatar
11
pwfx 2006.09.27 23:56 
Thanks, Codersguru.
I tried and managed to total up all open trades P/L.

Further if we want to total the profit/loss of only 2 or 3 specific open trades out of 6 open trades (for example)
either the open trades are same /different pair of currency, how do we code it?
Your reply is appreciated. TQ.

avatar
118
rfiche 2006.09.28 05:24 
double TotalProfit(string symbol)
{
      int total  = OrdersTotal();
      double MyCurrentProfit=0;
      for (int cnt = 0 ; cnt < total ; cnt++)
      {
         OrderSelect(cnt,SELECT_BY_POS,MODE_TRADES);
 
         if (symbol != OrderSymbol()) continue;
 
         MyCurrentProfit += OrderProfit();
      }
      return(MyCurrentProfit);
}

So, you should call "TotalProfit" function for each symbol your EA can trade.
Back to topics list  

To add comments, please log in or register