Broker API HubMenu

MQL4 OrderModify()

functionOrderModify()MQL4Sending orders

Changes an open or pending order: its stop loss and take profit, and for a pending order its price and expiry too.

Risk warning: CFDs and spread bets are complex instruments and come with a high risk of losing money rapidly due to leverage. You can lose money on these products, and each provider publishes its own loss figure under FCA rules. You should consider whether you understand how they work and whether you can afford to take the high risk of losing your money. Automated and API trading can amplify losses through bugs, connectivity failures and runaway orders.

Independent and unofficialdocs.mql4.comchecked

This is an MQL4 function, not an HTTP endpoint. It has no method, no path and no address to send a request to: it runs inside the MetaTrader 4 terminal, in a program written in MQL4.

The page says the open price and the expiry can be changed only on a pending order.

Signature

The form of the call on the vendor's page, with the vendor's comments taken out.

bool OrderModify(
  int ticket,
  double price,
  double stoploss,
  double takeprofit,
  datetime expiration,
  color arrow_color
)

Arguments

NameTypeDescription
ticketrequiredintThe order's ticket number.
pricerequireddoubleThe new open price, for a pending order.
stoplossrequireddoubleThe new stop loss level.
takeprofitrequireddoubleThe new take profit level.
expirationrequireddatetimeThe pending order's expiry time.
arrow_colorcolorThe colour of the arrows drawn on the chart for the stop loss and take profit change. Left out or set to CLR_NONE, none is drawn.

Return value

Type
bool
What comes back
True on success, false otherwise. The page points to GetLastError() for the reason.

Sample

Written by this site from the signature and arguments recorded on this page. It has not been run against a terminal, a server or an account, and the values in it are placeholders. It holds no credential and needs none: the program runs inside a terminal that is already logged in to an account. Nothing is entered on this site.

// Run it only on a demo account: it moves the stop loss of one order.
void MoveStop(const int ticket,const double new_stop)
  {
   if(!OrderSelect(ticket,SELECT_BY_TICKET))
      return;
   if(!OrderModify(ticket,OrderOpenPrice(),new_stop,OrderTakeProfit(),0,clrNONE))
      Print("OrderModify failed with error #",GetLastError());
  }

Return codes documented for this function

The page says GetLastError() gives the detail of a failure and names two of the codes: 1, raised when the values passed are unchanged, and 147, raised where the trade server does not allow expiry times. They are among MetaTrader 4's trade server return codes, each of which recorded here is below. docs.mql4.comchecked