Download MetaTrader 5

Incorrect OrderProfit and Money Management

To add comments, please log in or register
EUGENE ANDRY
875
EUGENE ANDRY  
Hi, Guys!
I need your help.
I am trying to calculate how much did earn one currency pair for example GBPUSD whilst trading multiple pairs simultaneously in ONE account
And OrderProfit() gives me incorrect data



2015.05.04 08:11:05.454 2012.06.18 20:00  Bounce_Back_MA_GBPUSD_SELL GBPAUD,H1: open #2 buy 1.27 GBPAUD at 1.54633 sl: 1.53043 tp: 1.70823 ok
2015.05.04 08:11:05.454 2012.06.18 20:00  Bounce_Back_MA_GBPUSD_SELL GBPAUD,H1: AcFrMar = NormalizeDouble(current_balance,2)=3191.75;LotSize=1.2767
2015.05.04 08:11:05.454 2012.06.18 20:00  Bounce_Back_MA_GBPUSD_SELL GBPAUD,H1: GBPAUD;AccountFreeMargin()=2938.1916;initial_deposit=1000; current_balance=3191.75
2015.05.04 08:11:05.454 2012.06.18 20:00  Bounce_Back_MA_GBPUSD_SELL GBPAUD,H1: Profit=2191.75;OrderType()=0;OrderOpenPrice=1.51538;OrderOpenTime()=1332727200;OrderTicket()=1;OrderLots()=0.4
2015.05.04 08:11:05.204 2012.05.31 18:37  Tester: stop loss #1 at 1.58531 (1.58530 / 1.58650)
2015.05.04 08:11:04.739 2012.05.23 18:00  Bounce_Back_MA_GBPUSD_SELL GBPAUD,H1: modify #1 buy 0.40 GBPAUD at 1.51538 sl: 1.58531 tp: 1.67728 ok
2015.05.04 08:11:01.679 2012.03.26 02:00  Bounce_Back_MA_GBPUSD_SELL GBPAUD,H1: open #1 buy 0.40 GBPAUD at 1.51538 sl: 1.49948 tp: 1.67728 ok
2015.05.04 08:11:01.679 2012.03.26 02:00  Bounce_Back_MA_GBPUSD_SELL GBPAUD,H1: AcFrMar = NormalizeDouble(current_balance,2)=1000;LotSize=0.4
2015.05.04 08:11:01.679 2012.03.26 02:00  Bounce_Back_MA_GBPUSD_SELL GBPAUD,H1: GBPAUD;AccountFreeMargin()=1000;initial_deposit=1000; current_balance=1000


why Profit=2191.75

2015.05.04 08:11:05.454 2012.06.18 20:00  Bounce_Back_MA_GBPUSD_SELL GBPAUD,H1: Profit=2191.75;OrderType()=0;OrderOpenPrice=1.51538;OrderOpenTime()=1332727200;OrderTicket()=1;OrderLots()=0.4

when true is only 1938.19

76 2012.05.31 18:37 s/l 1 0.4 1.58531 1.58531 1.67728 1938.19 2938.19


why Profit=-1582.19

2015.05.04 08:11:06.974 2012.09.13 21:00  Bounce_Back_MA_GBPUSD_SELL GBPAUD,H1: Profit=-1582.19;OrderType()=0;OrderOpenPrice=1.54633;OrderOpenTime()=1340049600;OrderTicket()=2;OrderLots()=1.27

when -1736.1 is true loss

78 2012.06.29 15:01 s/l 2 1.27 1.53043 1.53043 1.70823 -1736.1 1202.1


my MM is totally out of control ...
what am I missing?
How do I calculate correct profit/loss accumulation for particular pair?




1 2012.03.26 02:00 buy 1 0.4 1.51538 1.49948 1.67728 0 1000
76 2012.05.31 18:37 s/l 1 0.4 1.58531 1.58531 1.67728 1938.19 2938.19
77 2012.06.18 20:00 buy 2 1.27 1.54633 1.53043 1.70823 0 2938.19
78 2012.06.29 15:01 s/l 2 1.27 1.53043 1.53043 1.70823 -1736.1 1202.1
79 2012.09.13 21:00 buy 3 0.64 1.53237 1.51647 1.69427 0 1202.1
115 2012.10.11 11:35 s/l 3 0.64 1.55688 1.55688 1.69427 1062.05 2264.15
116 2012.11.05 17:00 buy 4 1.13 1.54233 1.52643 1.70423 0 2264.15
117 2012.11.12 03:32 s/l 4 1.13 1.52643 1.52643 1.70423 -1481.49 782.66
118 2012.12.04 12:00 buy 5 0.57 1.54022 1.52432 1.70212 0 782.66
126 2013.01.04 17:59 s/l 5 0.57 1.5338 1.5338 1.70212 -462.07 320.59
127 2013.04.29 10:00 buy 6 0.45 1.50453 1.48863 1.66643 0 320.59
128 2013.04.29 21:40 close at stop 6 0.45 1.49621 1.48863 1.66643 -293.35 27.24

2015.05.04 08:11:11.701 GBPAUD,H1: 21324803 tick events (21589 bars, 51180222 bar states) processed within 13650 ms (total time 19859 ms)
2015.05.04 08:11:11.700 2013.04.29 21:40  Tester: order #6 is closed
2015.05.04 08:11:11.700 2013.04.29 21:40  Bounce_Back_MA_GBPUSD_SELL: stopped because of Stop Out
2015.05.04 08:11:11.680 2013.04.29 10:00  Bounce_Back_MA_GBPUSD_SELL GBPAUD,H1: open #6 buy 0.45 GBPAUD at 1.50453 sl: 1.48863 tp: 1.66643 ok
2015.05.04 08:11:11.680 2013.04.29 10:00  Bounce_Back_MA_GBPUSD_SELL GBPAUD,H1: AcFrMar = NormalizeDouble(current_balance,2)=1144.19;LotSize=0.457676
2015.05.04 08:11:11.680 2013.04.29 10:00  Bounce_Back_MA_GBPUSD_SELL GBPAUD,H1: GBPAUD;AccountFreeMargin()=320.5913;initial_deposit=1000; current_balance=1144.19
2015.05.04 08:11:11.680 2013.04.29 10:00  Bounce_Back_MA_GBPUSD_SELL GBPAUD,H1: Profit=2191.75;OrderType()=0;OrderOpenPrice=1.51538;OrderOpenTime()=1332727200;OrderTicket()=1;OrderLots()=0.4
2015.05.04 08:11:11.680 2013.04.29 10:00  Bounce_Back_MA_GBPUSD_SELL GBPAUD,H1: Profit=-1582.19;OrderType()=0;OrderOpenPrice=1.54633;OrderOpenTime()=1340049600;OrderTicket()=2;OrderLots()=1.27
2015.05.04 08:11:11.680 2013.04.29 10:00  Bounce_Back_MA_GBPUSD_SELL GBPAUD,H1: Profit=1229.1;OrderType()=0;OrderOpenPrice=1.53237;OrderOpenTime()=1347570000;OrderTicket()=3;OrderLots()=0.64
2015.05.04 08:11:11.680 2013.04.29 10:00  Bounce_Back_MA_GBPUSD_SELL GBPAUD,H1: Profit=-1407.75;OrderType()=0;OrderOpenPrice=1.54233;OrderOpenTime()=1352134800;OrderTicket()=4;OrderLots()=1.13
2015.05.04 08:11:11.680 2013.04.29 10:00  Bounce_Back_MA_GBPUSD_SELL GBPAUD,H1: Profit=-286.72;OrderType()=0;OrderOpenPrice=1.54022;OrderOpenTime()=1354622400;OrderTicket()=5;OrderLots()=0.57
2015.05.04 08:11:10.347 2013.01.04 17:59  Tester: stop loss #5 at 1.53380 (1.53379 / 1.53499)
2015.05.04 08:11:10.174 2012.12.31 17:00  Bounce_Back_MA_GBPUSD_SELL GBPAUD,H1: modify #5 buy 0.57 GBPAUD at 1.54022 sl: 1.53380 tp: 1.70212 ok
2015.05.04 08:11:10.170 2012.12.31 16:00  Bounce_Back_MA_GBPUSD_SELL GBPAUD,H1: modify #5 buy 0.57 GBPAUD at 1.54022 sl: 1.52915 tp: 1.70212 ok
2015.05.04 08:11:10.048 2012.12.27 13:00  Bounce_Back_MA_GBPUSD_SELL GBPAUD,H1: modify #5 buy 0.57 GBPAUD at 1.54022 sl: 1.52908 tp: 1.70212 ok
2015.05.04 08:11:10.042 2012.12.27 11:00  Bounce_Back_MA_GBPUSD_SELL GBPAUD,H1: modify #5 buy 0.57 GBPAUD at 1.54022 sl: 1.52732 tp: 1.70212 ok
2015.05.04 08:11:09.888 2012.12.21 12:00  Bounce_Back_MA_GBPUSD_SELL GBPAUD,H1: modify #5 buy 0.57 GBPAUD at 1.54022 sl: 1.52718 tp: 1.70212 ok
2015.05.04 08:11:09.884 2012.12.21 11:00  Bounce_Back_MA_GBPUSD_SELL GBPAUD,H1: modify #5 buy 0.57 GBPAUD at 1.54022 sl: 1.52499 tp: 1.70212 ok
2015.05.04 08:11:09.882 2012.12.21 10:00  Bounce_Back_MA_GBPUSD_SELL GBPAUD,H1: modify #5 buy 0.57 GBPAUD at 1.54022 sl: 1.52467 tp: 1.70212 ok
2015.05.04 08:11:09.135 2012.12.04 12:00  Bounce_Back_MA_GBPUSD_SELL GBPAUD,H1: open #5 buy 0.57 GBPAUD at 1.54022 sl: 1.52432 tp: 1.70212 ok
2015.05.04 08:11:09.135 2012.12.04 12:00  Bounce_Back_MA_GBPUSD_SELL GBPAUD,H1: AcFrMar = NormalizeDouble(current_balance,2)=1430.91;LotSize=0.572364
2015.05.04 08:11:09.135 2012.12.04 12:00  Bounce_Back_MA_GBPUSD_SELL GBPAUD,H1: GBPAUD;AccountFreeMargin()=782.65812;initial_deposit=1000; current_balance=1430.91
2015.05.04 08:11:09.135 2012.12.04 12:00  Bounce_Back_MA_GBPUSD_SELL GBPAUD,H1: Profit=2191.75;OrderType()=0;OrderOpenPrice=1.51538;OrderOpenTime()=1332727200;OrderTicket()=1;OrderLots()=0.4
2015.05.04 08:11:09.135 2012.12.04 12:00  Bounce_Back_MA_GBPUSD_SELL GBPAUD,H1: Profit=-1582.19;OrderType()=0;OrderOpenPrice=1.54633;OrderOpenTime()=1340049600;OrderTicket()=2;OrderLots()=1.27
2015.05.04 08:11:09.135 2012.12.04 12:00  Bounce_Back_MA_GBPUSD_SELL GBPAUD,H1: Profit=1229.1;OrderType()=0;OrderOpenPrice=1.53237;OrderOpenTime()=1347570000;OrderTicket()=3;OrderLots()=0.64
2015.05.04 08:11:09.135 2012.12.04 12:00  Bounce_Back_MA_GBPUSD_SELL GBPAUD,H1: Profit=-1407.75;OrderType()=0;OrderOpenPrice=1.54233;OrderOpenTime()=1352134800;OrderTicket()=4;OrderLots()=1.13
2015.05.04 08:11:08.874 2012.11.12 03:32  Tester: stop loss #4 at 1.52643 (1.52643 / 1.52763)
2015.05.04 08:11:08.549 2012.11.05 17:00  Bounce_Back_MA_GBPUSD_SELL GBPAUD,H1: open #4 buy 1.13 GBPAUD at 1.54233 sl: 1.52643 tp: 1.70423 ok
2015.05.04 08:11:08.549 2012.11.05 17:00  Bounce_Back_MA_GBPUSD_SELL GBPAUD,H1: AcFrMar = NormalizeDouble(current_balance,2)=2838.66;LotSize=1.135464
2015.05.04 08:11:08.549 2012.11.05 17:00  Bounce_Back_MA_GBPUSD_SELL GBPAUD,H1: GBPAUD;AccountFreeMargin()=2264.14514;initial_deposit=1000; current_balance=2838.66
2015.05.04 08:11:08.549 2012.11.05 17:00  Bounce_Back_MA_GBPUSD_SELL GBPAUD,H1: Profit=2191.75;OrderType()=0;OrderOpenPrice=1.51538;OrderOpenTime()=1332727200;OrderTicket()=1;OrderLots()=0.4
2015.05.04 08:11:08.549 2012.11.05 17:00  Bounce_Back_MA_GBPUSD_SELL GBPAUD,H1: Profit=-1582.19;OrderType()=0;OrderOpenPrice=1.54633;OrderOpenTime()=1340049600;OrderTicket()=2;OrderLots()=1.27
2015.05.04 08:11:08.549 2012.11.05 17:00  Bounce_Back_MA_GBPUSD_SELL GBPAUD,H1: Profit=1229.1;OrderType()=0;OrderOpenPrice=1.53237;OrderOpenTime()=1347570000;OrderTicket()=3;OrderLots()=0.64
2015.05.04 08:11:08.251 2012.10.11 11:35  Tester: stop loss #3 at 1.55688 (1.55686 / 1.55806)
2015.05.04 08:11:08.038 2012.10.08 00:00  Bounce_Back_MA_GBPUSD_SELL GBPAUD,H1: modify #3 buy 0.64 GBPAUD at 1.53237 sl: 1.55688 tp: 1.69427 ok
2015.05.04 08:11:06.974 2012.09.13 21:00  Bounce_Back_MA_GBPUSD_SELL GBPAUD,H1: open #3 buy 0.64 GBPAUD at 1.53237 sl: 1.51647 tp: 1.69427 ok
2015.05.04 08:11:06.974 2012.09.13 21:00  Bounce_Back_MA_GBPUSD_SELL GBPAUD,H1: AcFrMar = NormalizeDouble(current_balance,2)=1609.56;LotSize=0.643824
2015.05.04 08:11:06.974 2012.09.13 21:00  Bounce_Back_MA_GBPUSD_SELL GBPAUD,H1: GBPAUD;AccountFreeMargin()=1202.09538;initial_deposit=1000; current_balance=1609.56
2015.05.04 08:11:06.974 2012.09.13 21:00  Bounce_Back_MA_GBPUSD_SELL GBPAUD,H1: Profit=2191.75;OrderType()=0;OrderOpenPrice=1.51538;OrderOpenTime()=1332727200;OrderTicket()=1;OrderLots()=0.4
2015.05.04 08:11:06.974 2012.09.13 21:00  Bounce_Back_MA_GBPUSD_SELL GBPAUD,H1: Profit=-1582.19;OrderType()=0;OrderOpenPrice=1.54633;OrderOpenTime()=1340049600;OrderTicket()=2;OrderLots()=1.27
2015.05.04 08:11:06.120 2012.06.29 15:01  Tester: stop loss #2 at 1.53043 (1.53042 / 1.53162)
2015.05.04 08:11:05.454 2012.06.18 20:00  Bounce_Back_MA_GBPUSD_SELL GBPAUD,H1: open #2 buy 1.27 GBPAUD at 1.54633 sl: 1.53043 tp: 1.70823 ok
2015.05.04 08:11:05.454 2012.06.18 20:00  Bounce_Back_MA_GBPUSD_SELL GBPAUD,H1: AcFrMar = NormalizeDouble(current_balance,2)=3191.75;LotSize=1.2767
2015.05.04 08:11:05.454 2012.06.18 20:00  Bounce_Back_MA_GBPUSD_SELL GBPAUD,H1: GBPAUD;AccountFreeMargin()=2938.1916;initial_deposit=1000; current_balance=3191.75
2015.05.04 08:11:05.454 2012.06.18 20:00  Bounce_Back_MA_GBPUSD_SELL GBPAUD,H1: Profit=2191.75;OrderType()=0;OrderOpenPrice=1.51538;OrderOpenTime()=1332727200;OrderTicket()=1;OrderLots()=0.4
2015.05.04 08:11:05.204 2012.05.31 18:37  Tester: stop loss #1 at 1.58531 (1.58530 / 1.58650)
2015.05.04 08:11:04.739 2012.05.23 18:00  Bounce_Back_MA_GBPUSD_SELL GBPAUD,H1: modify #1 buy 0.40 GBPAUD at 1.51538 sl: 1.58531 tp: 1.67728 ok
2015.05.04 08:11:01.679 2012.03.26 02:00  Bounce_Back_MA_GBPUSD_SELL GBPAUD,H1: open #1 buy 0.40 GBPAUD at 1.51538 sl: 1.49948 tp: 1.67728 ok
2015.05.04 08:11:01.679 2012.03.26 02:00  Bounce_Back_MA_GBPUSD_SELL GBPAUD,H1: AcFrMar = NormalizeDouble(current_balance,2)=1000;LotSize=0.4
2015.05.04 08:11:01.679 2012.03.26 02:00  Bounce_Back_MA_GBPUSD_SELL GBPAUD,H1: GBPAUD;AccountFreeMargin()=1000;initial_deposit=1000; current_balance=1000
2015.05.04 08:10:58.046 Bounce_Back_MA_GBPUSD_SELL inputs: Bounce_MA_Distance=19; Bars_Before_Bounce=21; MA_PERIOD=1919; MA_Modes=2; TakeProfit_BUY=1631; TakeProfit_SELL=531; StopLoss_BUY=147; StopLoss_SELL=38; StopLoss_ALL=0; Trailing_Stop=313; LotsPercent=40; LotSize=0.01; MM=1; initial_deposit=1000; debug=1; BUY_MODE=1; 
2015.05.04 08:10:51.844 TestGenerator: spread set to 120
2015.05.04 08:10:51.812 Expert Bounce_Back_MA_GBPUSD_SELL GBPAUD,H1: removed


void LotsCalc() 
{
  
  double current_balance = 0;
 
   int nOrders = 0;    datetime OCTs[];
    for(int iPos=OrdersHistoryTotal()-1; iPos >= 0; iPos--) if (
        OrderSelect(iPos, SELECT_BY_POS, MODE_HISTORY)  // Only orders w/
    &&  OrderMagicNumber()  == Magic             // my magic number
    &&  OrderSymbol()       == Symbol()             // and my pair.
    &&  OrderType()         <= OP_SELL//Avoid cr/bal forum.mql4.com/32363#325360
    )
    {
     if (debug) Print("Profit="+OrderProfit()+";OrderType()="+OrderType()+";OrderOpenPrice="+OrderOpenPrice()+";OrderClosePrice="+OrderClosePrice()+";OrderOpenTime()="+OrderOpenTime()+";OrderTicket()="+OrderTicket()+";OrderLots()="+OrderLots());
     current_balance += OrderProfit();
       
    }
    current_balance += initial_deposit;
    
   if (debug) Print(Symbol() +";AccountFreeMargin()="+AccountFreeMargin()+";initial_deposit="+initial_deposit+"; current_balance="+current_balance); 
   if (!MM) return;
    
   if(MarketInfo(Symbol(),MODE_MINLOT) == 0.1) int LotsDigit = 1;
   else if(MarketInfo(Symbol(),MODE_MINLOT) == 0.01) LotsDigit = 2;
   double MinLots = NormalizeDouble(MarketInfo(Symbol(),MODE_MINLOT),LotsDigit);
   double MaxLots = NormalizeDouble(MarketInfo(Symbol(),MODE_MAXLOT),LotsDigit);
   //double AcFrMar = NormalizeDouble(AccountFreeMargin(),2);
   double AcFrMar = NormalizeDouble(current_balance,2);
   LotSize = (AcFrMar*(LotsPercent/100))/1000;
   if(LotSize > MaxLots) LotSize = MaxLots;
   if(LotSize < MinLots) LotSize = MinLots; 
    
   if (debug) Print ("AcFrMar = NormalizeDouble(current_balance,2)"+"="+AcFrMar+";LotSize="+LotSize); 

   
}

Keith Watford
Moderator
10561
Keith Watford  

I don't know what we are supposed to be looking at in your post.

OrderProfit() does not include commission or swaps 

whroeder1
15553
whroeder1  
Don't paste code
Play video
Please edit your post.
For large amounts of code, attach it.
EUGENE ANDRY
875
EUGENE ANDRY  

yes, after research indeed gotta do +OrderSwap() + OrderCommission()

now it is ok 

To add comments, please log in or register