User login

  

Trading and Market Functions

The following lists alphabetically built-in PTL functions available for trading and market operations.

List of available functions:

CancelOrder OpenOrderMarket OrderDelete OrderSend
CancelOrderByAccount OpenOrderLimit OrderExpiration OrdersHistoryTotal
CancelOrderBySymbol OpenOrderStopLimit OrderModify OrderStopLoss
ChangeOrder OrderClose OrderOpenPrice OrdersTotal
ChangeSLTP OrderCloseBy OrderOpenTime OrderSwap
ClosePosition OrderClosePrice OrderPrint OrderSymbol
ClosePositionMutual OrderCloseTime OrderProfit OrderTakeProfit
LastTime OrderComment OrderSelect OrderTicket
OpenOrder OrderCommission OrderSend OrderType

 

 

CancelOrder

Deletes the previously placed pending order with the specified identifier from the system, and returns true. Returns false if the order cannot be deleted.

Syntax

bool CancelOrder( string token)

Parameters

  • Token - String uniquely identifying the order to be deleted.

 

CancelOrderByAccount

Deletes the previously placed pending order in the specified account from the system, and returns true. Returns false if the orders cannot be deleted.

Syntax

bool CancelOrderByAccount( string account)

Parameters

  • account - String variable specifying the account in which to cancel the orders.

 

CancelOrderBySymbol

Deletes the previously placed pending order for the specified symbol in the specified account from the system, and returns true. Returns false if the orders cannot be deleted.

Syntax

bool CancelOrderBySymbol( string symbol, string account)

Parameters

  • symbol - String representing the symbol the orders for which to cancel.
  • account - String variable specifying the account in which to cancel the orders.

 

ChangeOrder

Modifies the previously placed pending order parameters, and returns true. Returns false if the order cannot be changed.

Syntax

bool ChangeOrder( string orderNumber, int newPrice)

bool ChangeOrder( string orderNumber, double newPrice)

bool ChangeOrder( string orderNumber, int amount, double newPrice)

bool ChangeOrder( string orderNumber, double amount, double newPrice)

bool ChangeOrder( string orderNumber, int amount, int tif, double newPrice)

bool ChangeOrder( string orderNumber, double amount, int tif, double newPrice)

bool ChangeOrder( string orderNumber, int amount, int tif, double newPrice, double stoploss, double takeprofit)

bool ChangeOrder( string orderNumber, double amount, int tif, double newPrice, double stoploss, double takeprofit)

bool ChangeOrder( string orderNumber, double amount, int dispQty, int orderType, int tif, double newPrice, double stopPrice)

Parameters

  • orderNumber - String variable specifying the order to change.
  • amount - The new quantity of asset to be bought or sold.
  • dispQty - Displayed quantity.
  • orderType - New order type.
  • newPrice - The new price at which the order is to be filled.
  • stopPrice - The order's new stop price.
  • tif - Determines how long your order works in the market.
  • stoplose - The order's new stoplose price.
  • takeprofit - The order's new takeprofit price.

 

ChangeSLTP

Modifies stoploss and takeprofit for an order or a position.

Syntax

bool ChangeSLTP( string orderNumber, double stoploss, double takeprofit)

Parameters

  • orderNumber - String variable specifying the account.
  • stoplose - The order's new stoplose price.
  • takeprofit - The order's new takeprofit price.

 

ClosePosition

Close existed position(s), and returns true. Returns false if the positions cannot be closed.

Syntax

bool ClosePositions( string stringId)

bool ClosePositions( string stringId, double lots)

bool ClosePositions( string account, string symbol)

bool ClosePositions( string account, string symbol, int part)

Parameters

  • stringId - The id of the position.
  • account - String variable specifying the account in which to close the positions.
  • symbol - String constant representing the symbol the positions in which to close.
  • lots - Double variable specifying the volume to close.
  • part - Integer variable specifying the part of all position to close.

 

ClosePositionMutual

Closes open mutual positions and returns true. Returns false if the positions cannot be closed.

Syntax

bool ClosePositions( string id, string opposite)

Parameters

  • id - String variable specifying the id of first position to close.
  • oposite - String variable specifying the id of the second positions to close.

 

LastTime

Returns last quotes' time for main symbol.

Syntax

datetime LastTime()

Parameters

none

 

OpenOrder

Opens an order.

Syntax

string OpenOrder( int buysell)

string OpenOrder( int orderType, int buysell, double price)

string OpenOrder( string symbol, int orderType,double price, int buysell)

string OpenOrder( string symbol, int orderType, double price, int buysell, double quoty)

string OpenOrder( string symbol, int orderType, double price, int buysell, int quoty)

string OpenOrder( string symbol, int orderType, double price, int buysell, double quoty, int validTo)

string OpenOrder( string symbol, int orderType, double price, int buysell, double quoty, double stoploss, double takeprofit)

string OpenOrder( string symbol, int orderType, double price, int buysell, double quoty, int validTo, double stoploss, double takeprofit)

string OpenOrder( string symbol, int orderType, double price, int buysell,  double quoty, double stoploss, double takeprofit, double trailStop)

string OpenOrder( string symbol, int orderType, double price, int buysell, string account, double quoty, int validTo, double stoploss, double takeprofit)

string OpenOrder( string symbol, int orderType, double price, int buysell, string account, string route, double quoty, int validTo, double stoploss, double takeprofit)

 

OpenOrderMarket

Opens a market order. Return true when success

Syntax

bool OpenOrderMarket( string symbol, int buysell, string account, string route, double quoty, int validTo,

                    int type, double trailOffset)

bool OpenOrderMarket( string symbol, int buysell, string account, string route, double quoty, int validTo,

                    int type, double trailOffset, datetime activateTime)

Parameters

  • symbol - String variable specifying the instrument.
  • buysell - Int vconstant specifying the type of order. Values: OPERATION_BUY, OPERATION_SELL, OPERATION_SELLSHORT.
  • account - String variable specifying the account.
  • route - String variable specifying the route to trade. Use string "default" for default route.
  • quoty - Synonym of amount and volume. The number of lots for trade.
  • validTo - Int constants specifying the time live of order. Values: TIF_DAY and TIF_GTC.
  • type - No use now.
  • trailOffset - No use yet. Please, set 0 always.
  • activateTime - No use yet. Please, set 0 always.

 

OpenOrderLimit

Opens a limit order. Return true when success

Syntax

bool OpenOrderLimit( string symbol, int buysell, string account, string route, double quoty, int validTo,

                    int type, double stopPrice, double trailOffset)

bool OpenOrderLimit( string symbol, int buysell, string account, string route, double quoty, int validTo,

                    int type, double stopPrice, double trailOffset, , datetime activateTime)

Parameters

  • symbol - String variable specifying the instrument.
  • buysell - Int vconstant specifying the type of order. Values: OPERATION_BUY, OPERATION_SELL, OPERATION_SELLSHORT.
  • account - String variable specifying the account.
  • route - String variable specifying the route to trade. Use string "default" for default route.
  • quoty - Synonym of amount and volume. The number of lots for trade.
  • validTo - Int constants specifying the time live of order. Values: TIF_DAY and TIF_GTC.
  • type - No use now.
  • stopPrice - The stop price for order.
  • trailOffset - No use yet. Please, sent 0 always.
  • activateTime - No use yet. Please, sent 0 always.

 

OpenOrderStopLimit

Opens a stop limit order. Return true when success

Syntax

bool OpenOrderStopLimit( string symbol, int buysell, string account, string route, double quoty, int validTo,

                   double price, double stopPrice, double trailOffset)

bool OpenOrderStopLimit( string symbol, int buysell, string account, string route, double quoty, int validTo,

                   double price, double stopPrice, double trailOffset, datetime activateTime)

Parameters

  • symbol - String variable specifying the instrument.
  • buysell - Int vconstant specifying the type of order. Values: OPERATION_BUY, OPERATION_SELL, OPERATION_SELLSHORT.
  • account - String variable specifying the account.
  • route - String variable specifying the route to trade. Use string "default" for default route.
  • quoty - Synonym of amount and volume. The number of lots for trade.
  • validTo - Int constants specifying the time live of order. Values: TIF_DAY and TIF_GTC.
  • price - Price
  • stopPrice - The stop price for order.
  • trailOffset - No use yet. Please, sent 0 always.
  • activateTime - No use yet. Please, sent 0 always.

 

OrderClose

Closes the open order and returns true. Returns false if the order cannot be closed.

Syntax

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

Parameters

  • ticket - Number of the order to close.
  • lots - Number of lots to be closed.
  • price - Preferred closing price.
  • slippage - Maximum slippage in points.
  • color - The color of the closing symbol on the chart. If Color = CLR_NONE, no symbol is drawn.

 

OrderCloseBy

Closes the open order with another opposite order and returns true. Returns false if the order cannot be closed.

Syntax

bool CloseOrderBy( int ticket, int opposite, color Color = CLR_NONE)

Parameters

  • ticket - Number of the order to close.
  • lots - Number of opposite closing order.
  • color - The color of the closing symbol on the chart. If Color = CLR_NONE, no symbol is drawn.

 

OrderClosePrice

Returns the close price for the order currently selected with OrderSelect().

Syntax

double OrderOrderPrice()

 

OrderCloseTime

Returns the close time for the order currently selected with OrderSelect(). For open and pending orders, 0 is returned.

Syntax

datetime OrderCloseTime()

 

OrderComment

Returns the comment for the order currently selected with OrderSelect().

Syntax

string OrderComment()

 

OrderCommission

Returns the commission for the order currently selected with OrderSelect().

Syntax

double OrderCommision()

 

OrderDelete

Deletes the previously open order from the system and returns true. Returns false if the order cannot be deleted.

Syntax

bool CloseOrder( int ticket, color Color = CLR_NONE)

Parameters

  • ticket- Number of the order to delete.
  • color - The color of symbol on the chart. If Color = CLR_NONE, no symbol is drawn.

 

OrderExpiration

Returns the expiration date for the pending order currently selected with OrderSelect().

Syntax

datetime OrderExpiration()

 

OrderModify

Modifies the previously placed pending order parameters, and returns true. Returns false if the order cannot be modified.

Syntax

bool OrderModify( int ticket, double price, double stoploss, double takeprofit,

                  datetime expiration, color arrow_color = CLR_NONE)

Parameters

  • ticket - Number of the order to modify.
  • price - New open price.
  • stoploss - New stop loss price.
  • takeprofit - New take profit price.
  • expiration - New expiration date.
  • color - The color of stop loss and take profit modification symbol on the chart. If Color = CLR_NONE, no symbol is drawn.

 

OrderOpenPrice

Returns the open price for the order currently selected with OrderSelect().

Syntax

double OrderOpenPrice()

 

OrderOpenTime

Returns the open time for the order currently selected with OrderSelect().

Syntax

datetime OrderOpenTime()

 

OrderPrint

Prints the details of  the order currently selected with OrderSelect().

Syntax

void OrderPrint()

 

OrderProfit

Returns the net profit amount for the order currently selected with OrderSelect(). For open positions, returns the current unrealized profit.

Syntax

double OrderProfit()

 

OrderSelect

Selects an order for further processing. Returns false if the matching order is not found.

Syntax

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

Parameters

  • index - Order index or ticket number depending on the second parameter.
  • select - Selecting flags: SELECT_BY_POS to select by index from the order pool, or SELECT_BY_TICKET.
  • pool - Used when select = SELECT_BY_POS to indicate whether the order must be selected from the trading pool (= MODE_TRADES) or from the history pool (= MODE_HISTORY).

 

OrderSend

Places a market order (i.e. opens a position) or a pending order.

Syntax

int OrderSend( string symbol, int buysell, int ordertype, int tif, double amount, double price,

               double stoploss, double takeprofit, string comment, string account,

              string route, string boundTo)

Parameters

  • symbol - The symbol to trade.
  • buysell - Operation type (OP_BUY, OP_SELL, OP_BUYLIMIT, OP_SELLLIMIT, OP_BUYSTOP, OP_SELLSTOP).
  • ordertype - Integer constant specifying the type of order (market, stop and etc).
  • tif - Integer constant specifying the time type of order (day or GTC).
  • amount - Number of lots.
  • price - Preferred trade price.
  • stoploss - Stop loss price.
  • takeprofit - Take profit price.
  • comments - Descriptive text.
  • account - String value specified user's account
  • route - String value specified route. For use default route set "default"
  • boundTo - String value specified another order.

 

OrderSend

Places a market order (i.e. opens a position) or a pending order.

Syntax

int OrderSend( string symbol, int buysell, int ordertype, int tif, double amount, double price,

               double stoploss, double takeprofit)

Parameters

  • symbol - The symbol to trade.
  • buysell - Operation type (OP_BUY, OP_SELL, OP_BUYLIMIT, OP_SELLLIMIT, OP_BUYSTOP, OP_SELLSTOP).
  • ordertype - Integer constant specifying the type of order (market, stop and etc).
  • tif - Integer constant specifying the time type of order (day or GTC).
  • amount - Number of lots.
  • price - Preferred trade price.
  • stoploss - Stop loss price.
  • takeprofit - Take profit price.

 

OrdersHistoryTotal

Returns the number of closed orders in the account history.

Syntax

int OrdersHistoryTotal()

 

OrderStopLoss

Returns the stop loss price set for the order currently selected with OrderSelect().

Syntax

double OrderStopLoss()

 

OrdersTotal

Returns the total number of active orders, i.e. open positions and pending orders..

Syntax

int OrdersTotal()

 

OrderSwap

Returns the swap value  for the order currently selected with OrderSelect().

Syntax

double OrderSwap()

 

OrderSymbol

Returns the symbol of the order currently selected with OrderSelect().

Syntax

string OrderSymbol()

 

OrderTakeProfit

Returns the take profit price set for the order currently selected with OrderSelect().

Syntax

double OrderTakeProfit()

 

OrderTicket

Returns ticket number of the order currently selected with OrderSelect().

Syntax

int OrderTicket()

 

OrderType

Returns operation type of order currently selected with OrderSelect():

  • OPERATION_BUY - buying position
  • OPERATION_SELL - selling position
  • OPERATION_BUYLIMIT - buy limit pending position
  • OPERATION_BUYSTOP - buy stop pending position
  • OPERATION_SELLLIMIT - sell limit pending position
  • OPERATION_SELLSTOP - sell stop pending position

Syntax

int OrderType()

 

12345