OrderClose : bugs or expected ?

 

So, i just found some possible issues with the function OrderClose :

 I placed an order with this line of code :

ticket = OrderSend(Symbol(),OP_BUY,1.6,Ask,10,0,0,DoubleToStr(1.6,5),MAGIC,0,CLR_NONE); 

Next i closed partially this order :

 OrderClose(ticket,0.5,Bid,10,CLR_NONE);

Firstly, i verified the OrderLots of the order and then i get : 0.5

So, the second parameter seems to be the number of lots that we want to stay after the operation, and not the number we want to close. Bug or expected ?

 Secondly, i verified the OrderComment of the order and then the value has disappeared. Bug or expected ?

 

Partial close creates a new ticket for the remaining lots, so the original comment is lost.

Look at the new ticket to see how many lots are remaining in play, or see Trades tab in the Terminal.

 
phy:

Partial close creates a new ticket for the remaining lots, so the original comment is lost.

Look at the new ticket to see how many lots are remaining in play, or see Trades tab in the Terminal.



Thanks for the reply,

 

About the new ticket, is there an easy way to get it after the partial close ? otherwise, in my current implementation, it will be tricky to find it. 

 

Looks like the newest order is placed "on top" of the current orders list, so...

OrderClose(..., ..., ...); // to partial close a selected order, which generates a new ticket.

newTicket = OrderSelect(OrdersTotal()-1, SEL_BY_POSITION, MODE_TRADES); // get the ticket on the top of the pile.

I wouldn't consider this to be a robust solution, but looks like it would work in the simple case.

 

Ok, i'll do some tests whit that and i'll see.

Thanks. 

 
squallmat:

Ok, i'll do some tests whit that and i'll see.

Thanks.

if you are testing this, could you please verify also if the MagicNumber gets altered also?

thanks

 
I just tested, the MagicNumber is not altered, it is "copied" to the new order.
 

thanks

//z

 

I realize that this system make my closing function very complex.

I use many EA-symbol in same time and each tick execute this function to close dynamically totally or partially (or not)  each order depending on conditions. (and some other orders are closed by there stoploss/takeprofit)

This function select all orders and filter them by Magic and Symbol, then close them (or not). 

int total=OrdersTotal();
for(int i=0; i<total; i++)
      {
         OrderSelect(i,SELECT_BY_POS,MODE_TRADES);
         if(OrderSymbol()==Symbol() && OrderMagicNumber()==MAGIC)

The loop on a pool of orders that is changing during the loop, first by the partial closing that creates an other order in another place, and secondly by other EA-symbol functioning at the same time, make this function very tricky to achieve and make it robust.

Is there someone that has already tried to achieve that sort of function and can help me ?  

 

 

(PS : sorry for my english, it is not perfect) 

 

when closing orders normaly you should iterate backwards trough the orderlist.

for(int i=OrderstTotal()-1;i>=0;i--){
  if(OrderSelect(i,SELELCT_BY_POS)>=0){
    //do some stuff
  }
}

i think you will not have have processing time issius with this solution.

but if you don't want such a work-loop you have to keep trace of your orders trough internally stored ticket numbers. recovery can still be done trough MagicNumbers but only once on init.

 

https://www.mql5.com/en/forum/123683, "Closure Order Positive?"

https://www.mql5.com/en/forum/114039, "Always price error"

Reason: