MT5.SingleOrder.Rd
Function used to open market or place a pending order. Only accept only order at time, for multiple orders consider to use MT5.MultipleOrders()
instead.
The switch for pending order and market order is using fPrice
. Any value higher than 0
is considered a pending order.
Some Forex brokers take 200ms
to accept orders into market, so take this time on mind. Always check MT5's "Experts" tab for more information.
MT5.SingleOrder( sSymbol, iCmd, fVol, fPrice = 0, fStop = 0, fGain = 0, iFillType = 0 )
sSymbol | character; symbol for trading. |
---|---|
iCmd | int; operation type:
|
fVol | numeric; number of lots. |
fPrice | numeric; order price. WARNING: if |
fStop | numeric; if applicable use any value > |
fGain | numeric; if applicable use any value > |
iFillType | int; order type filling:
|
Returns TRUE
if the order was successfully sent, FALSE
otherwise.
Not all columns need to be filled as MT5.MultipleOrders()
request. See examples.
For fPrice = 0
, a market order will be sent and it will automatically set iFillType
to 1
.
For more information about ORDER_TYPE_*
see references.
WARNING! INVALID STOPS: take note that buy orders are rejected when order's stop loss are higher than symbol's ask price, and vice versa for sell orders. This is a sanity check made by MT5, not by mt5R. Always check MT5's "Experts" tab for more details when an order is rejected.
https://www.mql5.com/en/docs/constants/tradingconstants/orderproperties
https://www.investopedia.com/terms/m/marketorder.asp
MT5.DeleteOrder()
, MT5.ModifyOrder()
, MT5.MultipleOrders()
, MT5.ShowOrders()
, MT5.ClosePosition()
, MT5.ModifyPosition()
, MT5.ShowPositions()
if (FALSE) { ## Sell market order. Using arguments MT5.SingleOrder("EURUSD", iCmd = 1, fVol = 0.01) ## Sell market order, same above. Omitting arguments MT5.SingleOrder("EURUSD", 1, 0.01) ## Buy market order, using stop. fStop need to be lower than symbol's ask price, otherwise the order will be rejected. MT5.SingleOrder("EURUSD", 0, 0.01, fStop = 1.200) ## Last price: 1.2242 18-12-20. 1.200 < 1.2242 = OK ## Sell pending order MT5.SingleOrder("EURUSD", iCmd = 1, fVol = 0.01, fPrice = 1.2334) ## Pending Order MT5.SingleOrder("EURUSD", iCmd = 1, fVol = 0.01, fPrice = 1.18320) ## Sell Pending Order MT5.SingleOrder("EURUSD", iCmd = 0, fVol = 0.01, fPrice = 1.18320, fStop = 1.18200) ## Buy Pending Order with stop MT5.SingleOrder("EURUSD", iCmd = 1, fVol = 0.01, fPrice = 1.18720, fStop = 1.18790) ## Sell Pending Order with stop }