Thread: MQL4 Learning
View Single Post
  #190 (permalink)  
Old 08-04-2007, 12:13 AM
ralph.ronnquist's Avatar
ralph.ronnquist ralph.ronnquist is offline
Senior Member
 
Join Date: Oct 2006
Posts: 281
ralph.ronnquist is on a distinguished road
The main problems with the code, I think, were that it didn't take spread and stop level into account, and then that the stop-loss for the SELL was placed below the open price. The following is a rehash of the code resolving those problems.

PHP Code:
void AdjustingPendingOrders()
{
    Print ( 
"Adjusting the MT pending orders" );
    
double spread MarketInfoSymbol(), MODE_SPREAD );
    
double level MarketInfoSymbol(), MODE_STOPLEVEL );
    
double offset MathMaxspreadlevel );
    
double price Bid offset Point;
    
double SL;
    for ( 
int N OrdersTotal() - 1>= 0N-- ) {
        if ( ! 
OrderSelectNSELECT_BY_POSMODE_TRADES ) )
            continue;
        if ( 
OrderType() != OP_BUYSTOP && OrderType() != OP_SELLSTOP )
            continue;
        
//---- working with pending orders only
        //---- modifying
        
if ( OrderType() == OP_BUYSTOP ) {
            
SL price StopLoss Point;
        } else {
            
SL price StopLoss Point;
        }
        
OrderModifyOrderTicket(), priceSLOrderTakeProfit(), 0CLR_NONE );
    }

Reply With Quote