-
Notifications
You must be signed in to change notification settings - Fork 17
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
Closes open order
protected bool OrderClose(int ticket, double lots, double price, int slippage, color Color = default(color))
- 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 true if successful, otherwise false
Closes an opened order by another opposite opened order
protected bool OrderCloseBy(int ticket, int opposite, color Color = default(color))
- 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 true if successful, otherwise false
Returns close price of the currently selected order
protected double OrderClosePrice()
- The close price of currently selected order
Returns close time of the currently selected order
protected datetime OrderCloseTime()
- 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.
- The order must be previously selected by the OrderSelect() function.
Returns comment of the currently selected order
protected string OrderComment()
- Comment of the currently selected order
Returns calculated commission of the currently selected order
protected double OrderCommission()
- The calculated commission of the currently selected order
- The order must be previously selected by the OrderSelect() function.
Deletes previously opened pending order
protected bool OrderDelete(int ticket, color Color = default(color))
- 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
- If the function succeeds, it returns true, otherwise false
Returns expiration date of the selected pending order
protected datetime OrderExpiration()
- Expiration date of the selected pending order
Returns amount of lots of the selected order
protected double OrderLots()
- Amount of lots (trade volume) of the selected order
- The order must be previously selected by the OrderSelect() function.
Modification of characteristics of the previously opened or pending orders
protected bool OrderModify(int ticket, double price, double stoploss, double takeprofit, datetime expiration)
- 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
- If the function succeeds, it returns true, otherwise false
Returns open price of the currently selected order
protected double OrderOpenPrice()
- Open price of the currently selected order
- The order must be previously selected by the OrderSelect() function.
Returns open time of the currently selected order
protected datetime OrderOpenTime()
- Open time of the currently selected order
Prints information about the selected order in the log and app journal
protected void OrderPrint()
- The order must be previously selected by the OrderSelect() function.
Returns profit of the currently selected order
protected double OrderProfit()
- Profit of the currently selected order
- The order must be previously selected by the OrderSelect() function.
The function selects an order for further processing
protected bool OrderSelect(int index, int select, int pool = MODE_TRADES)
- 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)
- It returns true if the function succeeds, otherwise false
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)
- 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
- Number of the ticket assigned to the order by the trade server or -1 if it fails
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.
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");
Returns the number of closed orders in the account history loaded into the terminal
protected int OrdersHistoryTotal()
- The number of closed orders in the account history loaded into the terminal
Returns stop loss value of the currently selected order
protected double OrderStopLoss()
- Stop loss value of the currently selected order
- The order must be previously selected by the OrderSelect() function.
Returns the number of market and pending orders
protected int OrdersTotal()
- Total amount of market and pending orders
Returns swap value of the currently selected order
protected double OrderSwap()
- Swap value of the currently selected order
- The order must be previously selected by the OrderSelect() function.
Returns symbol name of the currently selected order
protected string OrderSymbol()
- The symbol name of the currently selected order
- The order must be previously selected by the OrderSelect() function.
Returns take profit value of the currently selected order
protected double OrderTakeProfit()
- Take profit value of the currently selected order
- The order must be previously selected by the OrderSelect() function.
Returns ticket number of the currently selected order
protected int OrderTicket()
- Ticket number of the currently selected order
- The order must be previously selected by the OrderSelect() function.
Returns order operation type of the currently selected order
protected int OrderType()
- 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
- The order must be previously selected by the OrderSelect() function.
Returns the status of the currently selected order
protected int OrdersStatus()
- 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
- The order must be previously selected by the OrderSelect() function.