Skip to content

Trading API

dbaechtel edited this page Mar 28, 2017 · 1 revision

Trading API

OrderClose
OrderCloseBy
OrderClosePrice
OrderCloseTime
OrderComment
OrderComission
OrderDelete
OrderExpiration
OrderLots
OrderModify
OrderOpenPrice
OrderOpenTime
OrderPrint
OrderProfit
OrderSelect
OrderSend
OrdersHistoryTotal
OrderStopLoss
OrdersTotal
OrderSwap
OrderSymbol
OrderTakeProfit
OrderTicket
OrderType
OrderStatus

OrderClose

Closes open order

protected bool OrderClose(int ticket, double lots, double price, int slippage, color Color = default(color))

Parameters

  • ticket - Unique number of the order ticket
  • lots - Number of lots
  • price - Closing price
  • slippage - Value of the maximum slippage in points
  • Color - Color of the closing arrow on the chart. If the parameter is missing or has CLR_NONE value closing arrow will not be drawn on the chart

Returns

  • Returns true if successful, otherwise false

OrderCloseBy

Closes an opened order by another opposite opened order

protected bool OrderCloseBy(int ticket, int opposite, color Color = default(color))

Parameters

  • ticket - Unique number of the order ticket
  • opposite - Unique number of the opposite order ticket
  • Color - Color of the closing arrow on the chart. If the parameter is missing or has CLR_NONE value closing arrow will not be drawn on the chart

Returns

  • Returns true if successful, otherwise false

OrderClosePrice

Returns close price of the currently selected order

protected double OrderClosePrice()

Returns

  • The close price of currently selected order

OrderCloseTime

Returns close time of the currently selected order

protected datetime OrderCloseTime()

Returns

  • Close time for the currently selected order. If order close time is not 0, then the order selected and has been closed and retrieved from the account history. Open and pending orders close time is equal to 0.

Note

  • The order must be previously selected by the OrderSelect() function.

OrderComment

Returns comment of the currently selected order

protected string OrderComment()

Returns

  • Comment of the currently selected order

OrderComission

Returns calculated commission of the currently selected order

protected double OrderCommission()

Returns

  • The calculated commission of the currently selected order

Note

  • The order must be previously selected by the OrderSelect() function.

OrderDelete

Deletes previously opened pending order

protected bool OrderDelete(int ticket, color Color = default(color))

Parameters

  • ticket - Unique number of the order ticket
  • Color - Color of the delete arrow on the chart. If the parameter is missing or has CLR_NONE value closing arrow will not be drawn on the chart

Returns

  • If the function succeeds, it returns true, otherwise false

OrderExpiration

Returns expiration date of the selected pending order

protected datetime OrderExpiration()

Returns

  • Expiration date of the selected pending order

OrderLots

Returns amount of lots of the selected order

protected double OrderLots()

Returns

  • Amount of lots (trade volume) of the selected order

Note

  • The order must be previously selected by the OrderSelect() function.

OrderModify

Modification of characteristics of the previously opened or pending orders

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

Parameters

  • ticket - Unique number of the order ticket
  • price - New open price of the pending order
  • stoploss - New stoploss level
  • takeprofit - New takeprofit level
  • expiration - Pending order expiration time

Returns

  • If the function succeeds, it returns true, otherwise false

OrderOpenPrice

Returns open price of the currently selected order

protected double OrderOpenPrice()

Returns

  • Open price of the currently selected order

Note

  • The order must be previously selected by the OrderSelect() function.

OrderOpenTime

Returns open time of the currently selected order

protected datetime OrderOpenTime()

Returns

  • Open time of the currently selected order

OrderPrint

Prints information about the selected order in the log and app journal

protected void OrderPrint()

Note

  • The order must be previously selected by the OrderSelect() function.

OrderProfit

Returns profit of the currently selected order

protected double OrderProfit()

Returns

  • Profit of the currently selected order

Note

  • The order must be previously selected by the OrderSelect() function.

OrderSelect

The function selects an order for further processing

protected bool OrderSelect(int index, int select, int pool = MODE_TRADES)

Parameters

  • index - Order index or order ticket depending on the second parameter
  • select - Selecting flags. It can be any of the following values:
    • SELECT_BY_POS - index in the order pool
    • SELECT_BY_TICKET - index is order ticket
  • pool - Optional order pool index. Used when the selected parameter is SELECT_BY_POS. It can be any of the following values:
    • MODE_TRADES (default)- order selected from trading pool(opened and pending orders)
    • MODE_HISTORY - order selected from history pool (closed and canceled order)

Returns

  • It returns true if the function succeeds, otherwise false

OrderSend

The main function used to open market or place a pending order

protected int OrderSend(string symbol, int cmd, double volume, double price,
  int slippage, double stoploss, double takeprofit, string comment = default(string),
  int magic = 0, datetime expiration = null, color arrow_color = default(color))

Parameters

  • symbol - Symbol for trading
  • cmd - Operation type. It can be any of the Trade operation enumeration
  • volume - Number of lots
  • price - Order price
  • slippage - Maximum price slippage for buy or sell orders
  • stoploss - Stop loss level
  • takeprofit - Take profit level
  • comment - Order comment text. Last part of the comment may be changed by server
  • magic - Order magic number. May be used as user defined identifier (0 default)
  • expiration - Order expiration time (for pending orders only)
  • arrow_color - Color of the opening arrow on the chart. If parameter is missing or has CLR_NONE value opening arrow is not drawn on the chart

Returns

  • Number of the ticket assigned to the order by the trade server or -1 if it fails

OrdersHistoryTotal

Returns the number of closed orders in the account history loaded into the terminal

protected int OrdersHistoryTotal()

Returns

  • The number of closed orders in the account history loaded into the terminal

OrderStopLoss

Returns stop loss value of the currently selected order

protected double OrderStopLoss()

Returns

  • Stop loss value of the currently selected order

Note

  • The order must be previously selected by the OrderSelect() function.

OrdersTotal

Returns the number of market and pending orders

protected int OrdersTotal()

Returns

  • Total amount of market and pending orders

OrderSwap

Returns swap value of the currently selected order

protected double OrderSwap()

Returns

  • Swap value of the currently selected order

Note

  • The order must be previously selected by the OrderSelect() function.

OrderSymbol

Returns symbol name of the currently selected order

protected string OrderSymbol()

Returns

  • The symbol name of the currently selected order

Note

  • The order must be previously selected by the OrderSelect() function.

OrderTakeProfit

Returns take profit value of the currently selected order

protected double OrderTakeProfit()

Returns

  • Take profit value of the currently selected order

Note

  • The order must be previously selected by the OrderSelect() function.

OrderTicket

Returns ticket number of the currently selected order

protected int OrderTicket()

Returns

  • Ticket number of the currently selected order

Note

  • The order must be previously selected by the OrderSelect() function.

OrderType

Returns order operation type of the currently selected order

protected int OrderType()

Returns

  • Order operation type of the currently selected order. It can be any of the following values:
    • OP_BUY - buy order
    • OP_SELL - sell order
    • OP_BUYLIMIT - buy limit pending order
    • OP_BUYSTOP - buy stop pending order
    • OP_SELLLIMIT - sell limit pending order
    • OP_SELLSTOP - sell stop pending order

Note

  • The order must be previously selected by the OrderSelect() function.

OrderStatus

Returns the status of the currently selected order

protected int OrdersStatus()

Returns

  • OrderStatus of the currently selected order. It can be any of the following values:
    • Unknown = -1,
    • PendingNew = 0,
    • New = 1,
    • Filled = 2,
    • Processing = 3,
    • Deleted = 32,
    • Closed = 33,
    • Rejected = 34

Note

  • The order must be previously selected by the OrderSelect() function.

Clone this wiki locally