Create an Entry Limit Order

A regular entry order opens a position when the specified market condition is met.

A netting entry order closes all positions for the specified instrument and account which are in the direction (buy or sell) opposite to the direction of the entry order.

A limit entry order with a sell direction is filled when the market is above the rate specified in the order.

A limit entry order with a buy direction is filled when the market is below the rate specified in the order.

Please note that if hedging is disabled for the account, the order, first, closes existing opposite positions for the same account and instrument and only then opens a new position in the remaining amount.

Valuemap field





The command. Must be CreateOrder.



The type of the order. Must be LE.



The identifier of the instrument the order should be placed for. The value must be obtained from the "Offers" table, the OfferID column.



The identifier of the account the order should be placed for. The value must be obtained from the "Accounts" table, the AccountID column.

Please note that the account identifier may not necessarily be equal to the account name which is shown in the Trading Station application.



The order direction.

The value must be B - for buy orders and S - for sell orders.



The quantity of the instrument to be bought or sold. The quantity is expressed in contracts and must be divisible by the value of the lot size (see baseUnitSize trading option in the following call:"getTradingProperty", ...)).

The quantity must not be specified in case the value of the NetQtyFlag field is y.



The net quantity flag. The value can be either y or n. The value is optional. The default value is n.

An entry order in the netting mode does not create any positions but closes all positions which exist at the moment of the order filling and which are created for the order account and order instrument in the direction (see BuySell) opposite to the direction of the order.



The rate at which the order must be filled.

The sell order rate must be above the market. The buy order rate must be below the market.



The trailing entry order follows the market in case the market moves in the direction opposite to that of the order (i.e. when the distance between the order and the current market price increases).

The value specifies the maximum change of the market price after that the rate of the order will be changed as well.

The value is expressed in pips.

If the value is 1, it means that the dynamic trailing mode is used, i.e. the order rate is changed with every change of the market price. Please note that in some systems, only dynamic trailing mode is supported. See"getTradingProperty", ...) for details about permitted types of the trailing mode. In case only dynamic trailing stop is supported, any non-zero value of this parameter will cause creating a dynamic trailing stop.

The value is optional. By default, this value is 0. 0 means no-trailing order.



Time-In-Force value.

Can be GTC (Good-Till-Cancelled) or DAY (Good-Till-End-Of-Day).

The value is optional.

Conditional orders are GTC orders by default.



The custom identifier of the order. This value will be populated into all order-related QTXT columns of the following tables: "Orders", "Trades", and "Closed Trades".



Specify the identifier of the existing contingency group to include the order into the that group. Don't specify the parameter if the order must not be included into any contingency group.

You can also create a pair of stop and limit orders for the trade using the same command. Please refer to Attach Stop and/or Limit Orders to the Command for details.

Note: If-Then Orders. If the order is a sell limit entry order with the order amount equal to zero. This order can be created above the market, and will be triggered when the market crosses the order rate up. Such order does not create or close any trades. If the order is used as a root order of the OTO, such order will activate all other orders included into the OTO group, so, you can use it for conditional activation of other orders.

Create Entry Stop or Entry Limit order for chosen account/instrument on chosen distance to market. [hide]

   function Init()
       strategy.parameters:addString("Account", "Account to trade", "", "");
       strategy.parameters:setFlag("Account", core.FLAG_ACCOUNT);
       strategy.parameters:addInteger("Amount", "Amount in lots to trade", "", 1, 1, 100);
       strategy.parameters:addInteger("Distance", "Distance to market", "", 100, -1000, 1000);
       strategy.parameters:addString("BuySell", "Buy or Sell?", "", "B");
       strategy.parameters:addStringAlternative("BuySell", "Buy", "", "B");
       strategy.parameters:addStringAlternative("BuySell", "Sell", "", "S");
   local offer;
   local account;
   local amount;
   local pipsize;
   local BuySell;
   local distance;
   function Prepare()
       instance:name(profile:id() .. "(" .. .. ")");
       account = instance.parameters.Account;
       BuySell = instance.parameters.BuySell;
       distance = instance.parameters.Distance;
       local lotSize ="getTradingProperty", "baseUnitSize",, account);
       amount = lotSize * instance.parameters.Amount;
       offer ="offers"):find("Instrument",;
       pipsize =;
   local create = true;
   local trade = false;
   local requestId;
   function Update()
       if create then
           create = false;
           -- create order
           local valuemap = core.valuemap();
           valuemap.Command = "CreateOrder";
           -- get the order type
           if BuySell == "B" and distance < 0 then
               valuemap.OrderType = "LE";
           elseif BuySell == "B" and distance > 0 then
               valuemap.OrderType = "SE";
           elseif BuySell == "S" and distance < 0 then
               valuemap.OrderType = "SE";
           elseif BuySell == "S" and distance > 0 then
               valuemap.OrderType = "LE";
           if distance >= 0 then
               valuemap.Rate = instance.ask[NOW] + distance * pipsize;
               valuemap.Rate =[NOW] + distance * pipsize;
           valuemap.OfferID = offer;
           valuemap.AcctID = account;
           valuemap.Quantity = amount;
           valuemap.BuySell = BuySell;
           local success, msg = terminal:execute(100, valuemap);
           if not (success) then
               terminal:alertMessage(,[NOW], "create order failed:" .. msg,;
               requestId = core.parseCsv(msg, ",")[0];
               terminal:alertMessage(,[NOW], "order sent:" .. requestId,;
       elseif not(trade) then
           -- check whether trade has been created
           local row;
           row ="trades"):find("OpenOrderReqID", requestId);
           if row ~= nil then
               trade = true;
               terminal:alertMessage(,[NOW], "trade created:" .. row.TradeID,;
               trade = true;
   function AsyncOperationFinished(cookie, success, msg)
       if cookie == 100 then
           if not(success) then
               terminal:alertMessage(,[NOW], "create order failed:" .. msg,;
               terminal:alertMessage(,[NOW], "order created:" .. msg,;