Time Critical "Orderclose"

 
Hi,

I'm developing one EA that need to close 3 orders (same SYMBOL(), same PERIOD()) when the accumulated profit is positive.

No problem, the EA has one function that calculates the profit/loss of the 3 order, and if it reaches some amount of pips, closes the 3 orders.

My problem is...

is one of the orders stays open (requotes, trade context busy, etc) in the next tick, the profit will be negative and I lots the rigth momente to close the orders.

Is there a way to make sure that noting else is executed unless the 3 orders are closed?

Many thanks

SB 

 

void CloseAll() {


for ( ... ) {

CloseOrder(...);

}


if (OrdersTotal()>0) CloseAll();


}

 
and one more method to reduce slippages - let say you want to close 3 buy orders of 0.2 lots, then it is better to open new sell order of 0.6 lots and then use OrderCloseBy() function to flat them out
 
nickbilak wrote >>
and one more method to reduce slippages - let say you want to close 3 buy orders of 0.2 lots, then it is better to open new sell order of 0.6 lots and then use OrderCloseBy() function to flat them out

how do you use OrderCloseBy()? What does this function do? many thks

 
bool OrderCloseBy( int ticket, int opposite, color Color=CLR_NONE)
Closes an opened order by another opposite opened order. If the function succeeds, the return value is true. If the function fails, the return value is false. To get the detailed error information, call GetLastError().
Parameters:
ticket - Unique number of the order ticket.
opposite - Unique number of the opposite order ticket.
Color - Color of the closing arrow on the chart. If the parameter is missing or has CLR_NONE value closing arrow will not be drawn on the chart.
Sample:
  if(iRSI(NULL,0,14,PRICE_CLOSE,0)>75)
{
OrderCloseBy(order_id,opposite_id);
return(0);
}
 
I´m trying to understand this, so I have to give an Opposite ID, made by me, to the function, which will make a totally opposite order while closing the first ? Aren´t ticket numbers allocated by server?
 

Ticket1 = OrderSend(..., OP_BUY, ...);

Ticket2 = OrderSend(..., OP_SELL, ...);

OrderCloseBy( Ticket1, Ticket2 );

 
phy wrote >>

Ticket1 = OrderSend(..., OP_BUY, ...);

Ticket2 = OrderSend(..., OP_SELL, ...);

OrderCloseBy( Ticket1, Ticket2 );

Thx. I see OrderCloseBy acts as a dual OrderClose.

Reason: