View Single Post
  #3 (permalink)  
Old 04-09-2007, 10:46 PM
ralph.ronnquist's Avatar
ralph.ronnquist ralph.ronnquist is offline
Senior Member
 
Join Date: Oct 2006
Posts: 280
ralph.ronnquist is on a distinguished road
You'll need to scan the orders twice: first to discover whether or not there is the OP_BUY or OP_SELL trades that you want should cause canceling of pending orders. The second loop is to carry out the canceling. Something like the following:
PHP Code:
bool has_sell false;
bool has_buy false;

for (
int i OrdersTotal()-1>= 0i-- ) {
    if ( ! 
OrderSelectiSELECT_BY_POS ) )
        continue;
    
has_sell |= OrderType() == OP_SELL;
    
has_buy |= OrderType() == OP_BUY;
}

for ( 
OrdersTotal()-1>= 0i-- ) {
    if ( ! 
OrderSelectiSELECT_BY_POS ) )
        continue;
    if ( 
has_sell && OrderType() == OP_BUYSTOP )
        
OrderDeleteOrderTicket(), DarkGoldenrod );
    if ( 
has_buy && OrderType() == OP_SELLSTOP )
        
OrderDeleteOrderTicket(), DarkGoldenrod );

Reply With Quote