Skip to content
Don Baechtel edited this page Sep 25, 2018 · 15 revisions

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 = null,
  int magic = 0, datetime expiration = null, color arrow_color = null)

Parameters

  • symbol - Symbol for trading. Not implmented by Alveo. Should always be null or Symbol().
  • cmd - Trade Operation type. It can be any of the Trade operation enumeration.
    Trade Operations
  • volume - Number of lots. One standard lot = 1.00. Must be Normalized to 2 decimal places using NormalizeDouble.
  • price - Order price for the currency pair. Must be Normalized to Digits decimal places.
  • 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 the server
  • magic - Order magic number. Not implemented in Alveo. Alveo always returns a value of zero.
  • expiration - Order expiration time (for pending orders only)
  • arrow_color - Color of the opening arrow on the chart. If the 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

Notes

In Alveo, the operation can only be performed on the security of the current Chart. The symbol parameter should always be null or equal to Symbol().

At the opening of a market order (OP_SELL or OP_BUY), only the latest prices of Bid (for selling) or Ask (for buying) can be used as open price.

Calculated or unnormalized price cannot be applied. If there has not been the requested open price in the price thread or it has not been normalized according to the amount of digits after decimal point, the error 129 (ERR_INVALID_PRICE) will be generated. If the requested open price is fully out of date, the error 138 (ERR_REQUOTE) will be generated independently on the slippage parameter. If the requested price is out of date, but present in the thread, the order will be opened at the current price and only if the current price lies within the range of price+-slippage.

StopLoss and TakeProfit levels cannot be too close to the market. The minimal distance of stop levels in points can be obtained using the MarketInfo() function with a MODE_STOPLEVEL parameter. In the case of erroneous or unnormalized stop levels, the error 130 (ERR_INVALID_STOPS) will be generated. A zero value of MODE_STOPLEVEL means either absence of any restrictions on the minimal distance for Stop Loss/Take Profit or the fact that a trade server utilizes some external mechanisms for dynamic level control, which cannot be translated in the client terminal. In the second case, GetLastError() can return error 130, because MODE_STOPLEVEL is actually "floating" here.

At placing of a pending order, the open price cannot be too close to the market. The minimal distance of the pending price from the current market one in points can be obtained using the MarketInfo() function with the MODE_STOPLEVEL parameter. In case of false open price of a pending order, the error 130 (ERR_INVALID_STOPS) will be generated.

The OrderSend function must not be called more than once per second, otherwise, the order will be rejected for happening too frequently.

Example

int ticket=OrderSend(Symbol(),OP_BUY,1,Ask,3,stoploss,takeprofit,"My order",0,0,Green);   
   if(ticket<0)   
     {   
      Print("OrderSend failed with error #",GetLastError());   
     }   
   else   
      Print("OrderSend placed successfully");   

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.