Download MetaTrader 5

How may I calculate the actual profit of an open order?

To add comments, please log in or register
Sign up for MQL5.community to leave your comments!
Luciano Ola
1007
Luciano Ola 2014.02.11 20:03 

I have tried

This,

OOPrS=OrderProfit() +OrderSwap() +OrderCommission() +OrderSwap();   

with this

if(.......&& OOPrS>0  &&...)FunctionCall(int)

but some orders still close when the trade is a losing one. Btw I know I add orderswap twice, and this is likely wrong but it was the only way to slightly alleviate the problem..

Simon Gniadkowski
Moderator
17998
Simon Gniadkowski 2014.02.11 20:06  
MetaNt:

I have tried

This,

but some orders still close when the trading is a losing one.

Maybe price moved to your disadvantage between checking the Profit and closing the trade ? Print all the variables and find out.
qjol
3243
qjol 2014.02.11 20:06  

to use those functions u must use OrderSelect()

or else show your code

Luciano Ola
1007
Luciano Ola 2014.02.11 20:12  
RaptorUK:
Maybe price moved to your disadvantage between checking the Profit and closing the trade ? Print all the variables and find out.


Well I used print and it was showing that the OOPrS was negative, I am using a 4hr chart and it is odd that the price can move like that it's not like the strategy tester hit a news event when this happened. Might it be something else?

Sorry I say move like that because some of the losses were large, around 1% of the capital.

qjol:

to use those functions u must use OrderSelect()

or else show your code


I was only showing a section of the code, here is a larger section..

for(int l=OrdersTotal()-1;l>=0;l--)
          {
          if(OrderSelect(l,SELECT_BY_POS,MODE_TRADES))
           {
            if(OrderMagicNumber()==MagicNumber && OrderSymbol()==Symbol()&& OrderType()==OP_SELL)            
            {OOPS=OrderOpenPrice();OOPrS=OrderProfit() +OrderSwap() +OrderCommission() +OrderSwap();     
             if((Time[0]-OrderOpenTime())<=0 && OrderOpenTime()!=0 && OrderOpenTime()!=NULL)OOTS=Time[0];
              //else OOTS=OOTS;      
                 if(OpenOrdersThisPair(Symbol())>=1)ShiftToOpenS =iBarShift(NULL,0,OOTS,1);
                 SEnvPU = iEnvelopes(NULL,0,EnvelopeMA,2,0,Applied,0.01,MODE_UPPER,ShiftToOpenS);
                 
Luciano Ola
1007
Luciano Ola 2014.02.11 20:23  
BTW I also have OOPrS and OOPrB (The buy version) refreshing when there are no orders open, I have a maximum of one order open at a time (special cases excluded, but this issue has not arisen during the aforementioned special cases).
Ubzen
5394
Ubzen 2014.02.11 20:23  
MetaNt: Well I used print and it was showing that the OOPrS was negative, I am using a 4hr chart and it is odd that the price can move like that it's not like the strategy tester hit a news event when this happened. Might it be something else?

Yes it could be a couple of reasons.

1) Slippage ... Like RaptorUK suggested.

2) OrderSelect is failing || Selecting Something Else ... Like qjol suggested.

Bring the Calculation of Net-Profit closer to the OrderClose().

Print the OrderTicket(). Verify that what you're checking is whats being Closed.

Ubzen
5394
Ubzen 2014.02.11 20:26  

Are these Global_Variables &|| Static_Variables?

OOPS=OrderOpenPrice();OOPrS=OrderProfit() +OrderSwap() +OrderCommission() +OrderSwap();   
Where is the OrderClose routine?
Luciano Ola
1007
Luciano Ola 2014.02.11 20:29  
ubzen:

Yes it could be a couple of reasons.

1) Slippage ... Like RaptorUK suggested.

2) OrderSelect is failing || Selecting Something Else ... Like qjol suggested.

Bring the Calculation of Net-Profit closer to the OrderClose().

Print the OrderTicket(). Verify that what you're checking is whats being Closed.


Selecting something else? It's only meant to be selecting sell orders which are open, and I only have one open at a time. I'm using a slippage of 7 points a believe, and this may be the issue, I don't understand what you mean when you say bring the calculation of Net-Profit closer to OrderClose(), do you mean reduce the slippage? As for printing the OrderTicket() if it is selecting historical trades how can I fix that?
Luciano Ola
1007
Luciano Ola 2014.02.11 20:32  
ubzen:

Are these Global_Variables &|| Static_Variables?

Where is the OrderClose routine?


Global but not static.

 if(direction==2 /*|| CurrMACD_5_50_5<CurrMACD_SIGNAL*/)
      {
       for(int m=OrdersTotal()-1;m>=0;m--)
          {
          if(OrderSelect(m,SELECT_BY_POS,MODE_TRADES))
            if(OrderMagicNumber()==MagicNumber)
               if(OrderSymbol()==Symbol())                                                                 
                  if(OrderType()==OP_BUY)
                   if(OrderTicket()==buyticket1 && OpenOrdersThisPair(Symbol())==1)OrderClose(buyticket1, OrderLots(), bid,7,Yellow);
                   if(OrderTicket()==buyticket0 && OpenOrdersThisPair(Symbol())==3)OrderClose(buyticket0, OrderLots(), bid,7,Yellow);
                   if(OrderTicket()==buyticket2 && OpenOrdersThisPair(Symbol())==5)OrderClose(buyticket2, OrderLots(), bid,7,Yellow);
                    /*if(OrderTicket()==Ticket2 && OpenOrdersThisPair(Symbol())==3){OrderClose(OrderTicket(), OrderLots(), bid,7,Yellow);}*/                       
          } 
      }

Well here is my closing sequence.

I'm having some issues with this too be honest, but it's after trying to adjust a previously built closing sequence with some new closing triggers, with the 5th order only half of it gets closed, I think it's something I can deal with though however, the profit problem has been bugging me for some time.

Luciano Ola
1007
Luciano Ola 2014.02.11 20:40  

I thought this might be a useful piece of info.

The lotsize of the trade which is having this issue is about one twelfth of the capital.

Simon Gniadkowski
Moderator
17998
Simon Gniadkowski 2014.02.11 20:42  
MetaNt:


Global but not static.

Globals are static.
123
To add comments, please log in or register