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

1007
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..

Moderator
17998
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.
3243
2014.02.11 20:06

to use those functions u must use OrderSelect()

1007
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()

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

```for(int l=OrdersTotal()-1;l>=0;l--)
{
{
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);
```
1007
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).
5394
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.

5394
2014.02.11 20:26

Are these Global_Variables &|| Static_Variables?

`OOPS=OrderOpenPrice();OOPrS=OrderProfit() +OrderSwap() +OrderCommission() +OrderSwap();   `
Where is the OrderClose routine?
1007
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?
1007
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(OrderMagicNumber()==MagicNumber)
if(OrderSymbol()==Symbol())
/*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.

1007
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.

Moderator
17998
2014.02.11 20:42
MetaNt:

Global but not static.

Globals are static.
123