MQL4参考 交易函数 OrderModify

OrderModify

Modification of characteristics of the previously opened or pending orders.

bool  OrderModify(
   int        ticket,      // ticket
   double     price,       // price
   double     stoploss,    // stop loss
   double     takeprofit,  // take profit
   datetime   expiration,  // expiration
   color      arrow_color  // color
   );

Parameters

ticket

[in]  Unique number of the order ticket.

price

[in]  New open price of the pending order.

stoploss

[in]  New StopLoss level.

takeprofit

[in]  New TakeProfit level.

expiration

[in]  Pending order expiration time.

arrow_color

[in]  Arrow color for StopLoss/TakeProfit modifications in the chart. If the parameter is missing or has CLR_NONE value, the arrows will not be shown in the chart.

Returned value

If the function succeeds, it returns true, otherwise false. To get the detailed error information, call the GetLastError() function.

Note

Open price and expiration time can be changed only for pending orders. If unchanged values are passed as the function parameters, the error 1 (ERR_NO_RESULT) will be generated.

Pending order expiration time can be disabled in some trade servers. In this case, when a non-zero value is specified in the expiration parameter, the error 147 (ERR_TRADE_EXPIRATION_DENIED) will be generated.

Example:

void OnStart()
  {
   int TrailingStop=50;
//--- modifies Stop Loss price for buy order №12345
   if(TrailingStop>0)
     {
      OrderSelect(12345,SELECT_BY_TICKET);
      if(Bid-OrderOpenPrice()>Point*TrailingStop)
        {
         if(OrderStopLoss()<Bid-Point*TrailingStop)
           {
            bool res=OrderModify(OrderTicket(),OrderOpenPrice(),NormalizeDouble(Bid-Point*TrailingStop,Digits),OrderTakeProfit(),0,Blue);
            if(!res)
               Print("Error in OrderModify. Error code=",GetLastError());
            else
               Print("Order modified successfully.");
           }
        }
     }
  }