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

 
RaptorUK:
Globals are static.


I make mine refresh at the close of each order so the data gets deleted.

 
MetaNt:


Global but not static. 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.

Yeah thats why you're having problems. I would recommend doing the OrderClose within the same OrderSelect_Loop which you performed the OrderProfit()+ calculations.

I would use local variables for these. Global variables save their values from start-to-start and requires manual reset of the globals.

 
MetaNt:


Global but not static.

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.

OK, this is the code to close the Buy, you were talking about OP_SELL earlier . . . please show where you use OOPrS to determine if the Order should be closed or not and also how that then makes the close happen . . . you have a time element too . . . maybe that is the issue ?
 
ubzen:

Yeah thats why you're having problems. I would recommend doing the OrderClose within the same OrderSelect_Loop which you performed the OrderProfit()+ calculations.

I would use local variables for these. Global variables save their values from start-to-start and requires manual reset of the globals.


I use comment to monitor the values and they seem to be resetting.

Please note.

if(OpenOrdersThisPair(Symbol())==0||....||....)OOPrB=0;   
if(OpenOrdersThisPair(Symbol())==0||....||....)OOPrS=0;   

If you still think I should do as suggested then I'll try it.

 
RaptorUK:
OK, this is the code to close the Buy, you were talking about OP_SELL earlier . . . please show where you use OOPrS to determine if the Order should be closed or not and also how that then makes the close happen . . . you have a time element too . . . maybe that is the issue ?


I realise this, but I spotted the issue with buy orders first, as they were the first to be carried out, my sell code is pretty much identical. The close sequence is held within the FunctionCall (int direction)

if(.......&& OOPrB>0  &&...)FunctionCall(2)

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);}*/                       
          } 
      }
    
 
I've relocated the print (to the close sequence) and it does not print any negative values.
 
MetaNt: I've relocated the print (to the close sequence) and it does not print any negative values.

You need to do a little more than that. Try the following ... use only 1 order select loop and no-globals.

for( int i=orderstotal-1; i>=0; i--){

            if( orderselect == true )

            if( orderclose_condition == true)
         
            double OOPrs = orderprofit + ordercommission + orderswap;

            if( OOPrS > 0) OrderClose( OrderTicket() ... );

}
Try giving that a shot.
 
There is an issue with this, I can't refresh the OOPrs
 
MetaNt: There is an issue with this, I can't refresh the OOPrs
It'll refresh every-time you need it.
 
ubzen:
It'll refresh every-time you need it.
That's what I thought, but it doesn't get the chance, as every order after the first closes immediately.
Reason: