Create a Stop Order
A stop order is used for limiting losses of the existing position when the market condition is met.
Stop orders can be created for existing trades as well as for existing entry orders. Stop orders created for entry orders remain inactive until the trade is created by the entry order.
Only one stop order can be attached to a position or an the entry order.
Please note that close orders must be permitted for the account in order to be used.
Please note that stop and limit orders cannot be attached to netting entry orders.
Parameter name |
Datatype |
Description |
||||||
Command |
string |
The command. Must be |
||||||
OrderType |
string |
The type of the order. Must be |
||||||
OfferID |
string |
The identifier of the instrument the order should be placed for.
The value must be obtained from the Offers table, the |
||||||
AccountID |
string |
The identifier of the account the order should be placed for.
The value must be obtained from the Accounts table, the Please note that the account identifier may not necessarily be equal to the account name which is shown in the Trading Station application. |
||||||
TradeID |
string |
The identifier of the trade to be closed.
The value must be obtained from the Trades table, the |
||||||
BuySell |
string |
The order direction. The value must be |
||||||
Amount |
int |
The amount of the order. In the case of FX instruments, the amount is expressed in the base currency of an instrument. In the case of CFD instruments, the amount is expressed in contracts. Must be divisible by the value of the lot size. The amount must be equal to the size of the position (see the |
||||||
Rate |
double |
The rate at which the order must be filled. The rate must be below the market for sell orders and above the market for buy orders. To specify the stop order price, use:
|
||||||
PegType |
string |
"Pegged" means that the price is specified as an offset (in pips) against the market price. The field specifies which price should be used to calculate the order price:
Please note that "pegged" orders are stored as "pegged" only while the order is attached to an entry order. Once the entry order gets filled and a position is opened, the peg price is automatically converted to a regular market price. |
||||||
PegOffset |
int |
The offset to the price specified in the The offset must be positive for buy orders and negative for sell orders. |
||||||
TrailStep |
int |
The trailing stop order follows the market in case the market moves in the direction opposite to that of the order (e.g. in the profitable direction for the position). The value specifies the maximum change of the market price after which the rate of the order will be changed as well. The value is expressed in the units of the minimum change of the
price (see the For example, if the value of the 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. The value is optional. By default, this value is 0. 0 means no-trailing order. |
||||||
TimeInForce |
string |
The Time In Force value. Can be The value is optional. Stop orders are |
||||||
ClientRate |
double |
The current price of the order instrument. The value is optional. It is used for logging purposes. |
||||||
CustomID |
string |
The custom identifier of the order. This value will be populated into these columns of the trading tables:
The value is optional. |
Example: Create a Stop order [hide]
public void PrepareParamsFromLoginRules(O2GLoginRules loginRules) { mParams = new OrderCreationParameters(); O2GResponseReaderFactory factory = mSession.getResponseReaderFactory(); if (factory == null) return; // Gets first account from login. O2GResponse accountsResponse = loginRules.getTableRefreshResponse(O2GTable.Accounts); O2GAccountsTableResponseReader accountsReader = factory.createAccountsTableReader(accountsResponse); O2GAccountRow account = accountsReader.getRow(0); // Store account id mParams.AccountID = account.AccountID; // Store base iAmount mParams.BaseAmount = account.BaseUnitSize; // Get offers for eur/usd O2GResponse offerResponse = loginRules.getTableRefreshResponse(O2GTable.Offers); O2GOffersTableResponseReader offersReader = factory.createOffersTableReader(offerResponse); for (int i = 0; i < offersReader.Count; i++) { O2GOfferRow offer = offersReader.getRow(i); if (string.Compare(offer.Instrument, "EUR/USD", true) == 0) { mParams.OfferID = offer.OfferID; mParams.Ask = offer.Ask; mParams.Bid = offer.Bid; mParams.PointSize = offer.PointSize; break; } } } public void PrepareParamsAndCallStopOrder(O2GTradeRow tradeRow, int iAtMarket) { string sTradeBuySell = tradeRow.BuySell; // Close order is opposite to the trade bool bBuyOrder = false; if (sTradeBuySell == Constants.Sell) bBuyOrder = true; string sTradeOfferID = tradeRow.OfferID; double dCurrentRate = 0; double dStopRate = 0; double dPointSize = mParams.PointSize; if (bBuyOrder) { dCurrentRate = mParams.Ask; dStopRate = dCurrentRate + iAtMarket * dPointSize; } else { dCurrentRate = mParams.Bid; dStopRate = dCurrentRate - iAtMarket * dPointSize; } CreateStopOrder(sTradeOfferID, tradeRow.AccountID, tradeRow.TradeID, tradeRow.Amount, dStopRate, bBuyOrder ? Constants.Buy : Constants.Sell); } public void CreateStopOrder(string sOfferID, string sAccountID, string sTradeID, int iAmount, double dRate, string sBuySell) { O2GRequestFactory factory = mSession.getRequestFactory(); if (factory == null) return; O2GValueMap valuemap = factory.createValueMap(); valuemap.setString(O2GRequestParamsEnum.Command, Constants.Commands.CreateOrder); valuemap.setString(O2GRequestParamsEnum.OrderType, Constants.Orders.Stop); valuemap.setString(O2GRequestParamsEnum.AccountID, sAccountID); // The identifier of the account the order should be placed for valuemap.setString(O2GRequestParamsEnum.OfferID, sOfferID); // The identifier of the instrument the order should be placed for valuemap.setString(O2GRequestParamsEnum.TradeID, sTradeID); // The identifier of the trade to be closed valuemap.setString(O2GRequestParamsEnum.BuySell, sBuySell); // The order direction (Constants.Buy for Buy, Constants.Sell for Sell). Must be opposite to the direction of the trade valuemap.setInt(O2GRequestParamsEnum.Amount, iAmount); // The quantity of the instrument to be bought or sold. Must be = size of the position (Lot of the trade). Must be divisible by baseUnitSize valuemap.setDouble(O2GRequestParamsEnum.Rate, dRate); // The dRate at which the order must be filled (< market for "Sell" order, market for "Buy" order) valuemap.setString(O2GRequestParamsEnum.CustomID, "StopOrder"); // The custom identifier of the order O2GRequest request = factory.createOrderRequest(valuemap); mSession.sendRequest(request); }