Delete Pending order if price moved

 

i'd like to delete a pending order if the price moved 500 points without executing it 

Here's my attempt 

  CTrade trade;

    MqlRates pricedata [];
    ArraySetAsSeries(pricedata,true);
    int data =CopyRates(Symbol(),Period(),0,550,pricedata);

    for (int i = OrdersTotal() - 1; i >=0; i-- ) {
  
     ulong order_ticket = OrderGetTicket(i);
     double order_price = OrderGetDouble(ORDER_PRICE_OPEN);
     double current_open_price = pricedata[0].open;  // current price
      
    if ( MathAbs(order_price - current_open_price )*_Point > 500 )
        
        trade.OrderDelete(order_ticket);
        
       
    }  
 
I would try:

if ( MathAbs(order_price - current_open_price) > (500 * _Point))
 
Soewono Effendi:
I would try:

Thanks , it works

Reason: