StopLimit

 

Are you usingStopLimit in real trading?

It is clear thatStopLimit works inadequately in the tester.

Does it make sense to use it in real trading? What are the advantages and disadvantages?

 
Sergey Chalyshev:

Are you usingStopLimit in real trading?

It is clear thatStopLimit does not work adequately in the tester.

Does it make sense to use it in real trading? What are the advantages and disadvantages?

What is wrong with the tester?
 
Artyom Trishkin:
What's wrong with the tester?

Apparently no one uses it,

the order is opened at non-existent prices:

sl

A simple example to check:

//+------------------------------------------------------------------+
//|                                               StopLimit_Test.mq5 |
//+------------------------------------------------------------------+
#include <Trade\Trade.mqh>
CTrade trade;

input int Deviation = 100;
//+------------------------------------------------------------------+
void OnTick()
  {
   MqlTick tick;
   SymbolInfoTick(_Symbol,tick);
   trade.SetTypeFilling(ORDER_FILLING_RETURN);
   double ticksise=SymbolInfoDouble(_Symbol,SYMBOL_TRADE_TICK_SIZE);

   if(OrdersTotal()==0)
      trade.OrderOpen(
         _Symbol,                      // символ
         ORDER_TYPE_BUY_STOP_LIMIT,    // тип ордера
         1.0,                          // объем ордера
         tick.ask+Deviation*ticksise,  // цена исполнения
         tick.ask+10*ticksise,         // цена стоплимита
         0,                            // цена stop loss
         0                             // цена take profit
      );
  }
//+------------------------------------------------------------------+
 
Sergey Chalyshev:

Apparently no one uses it,

the order is opened at non-existent prices:

A simple example to check:

A BuyStopLimit order works like this:

  1. A BuyStop order is placed above the price (price value in the trade request structure = price + stop order setting distance)
  2. When a BuyStop order triggers, a BuyLimit order is placed below the price
    (at stoplimit price in the trade request structure which should be correctly calculated: stoplimit = price - stop order setting distance)
  3. When a BuyLimit order triggers, an entry into the market is made at the price of the BuyLimit order

Example:


 
Artyom Trishkin:

A BuyStopLimit order works this way:

  1. We set an order BuyStop above price (value of price in the trade request structure = price + stop order setting distance)
  2. When BuyStop is triggered, a BuyLimit order is placed below price
    (at stoplimit price in the trade request structure which should be correctly calculated: stoplimit = price - stop order setting distance)
  3. When a BuyLimit order triggers, an entry into the market is made at the price of the BuyLimit order

Example:


WhenBuyLimit is below the price, it works fine in the tester.

WhenBuyLimit is higher than the price, it should open at the Ask price. On the exchange, on the real, it works that way.

It doesn't make sense to use StopLimit to setBuyLimit below the price.

 
Sergey Chalyshev:

WhenBuyLimit is below the price, it works fine in the tester.

WhenBuyLimit is above price, it should open at Ask price. On the exchange, on the real, it works that way.

Using a StopLimit to put the BuyLimit below the price makes no sense.

Field

Description

action

Type of trade operation. Value can be one of the values of ENUM_TRADE_REQUEST_ACTIONSenumeration

magic

Identifier of the Expert Advisor. Allows arranging of analytical processing of trade orders. Each Expert Advisor can display its own unique identifier when sending a trade request

order

Order Ticket. Required for modification of pending orders

symbol

Name of the symbol for which the order is placed. Not needed for modification of orders and closing of positions

Volume

Requested volume of a deal in lots. The actual value of volume when opening a position will depend on the type of order being executed.

price

The price when the order should be filled. The price is not requiredfor market orders with the "Market Execution" type ( SYMBOL_TRADE_EXECUTION_MARKET ) with theTRADE_ACTION_DEALtype

stoplimit

Price at which the pending Limit order will be placed once the price reaches the price value (this condition is mandatory). Until that moment, the pending order is not placed in the trading system

sl

Price at which a Stop Loss order will be triggered when the security price moves in an unfavorable direction

tp

Price at which the Take Profit order is triggered by the price movement in the favorable direction

deviation

Maximum acceptable deviation from the requested price, set in points

type

Order type. The value can be one of the values of the enumeration ENUM_ORDER_TYPE

type_filling

Order type to execute. Value can be one of the values ofENUM_ORDER_TYPE_FILLING

type_time

Order type_filling time. Value can be one of the values ofENUM_ORDER_TYPE_TIME

expiration

Expirationtime of the pending order (for ORDER_TIME_SPECIFIEDorders )

comment

Comment to the order

position

Ticket to position. This should be filled out when a position is changed and closed to clearly identify it. This usually corresponds with the ticket of the order which resulted in the position being opened.

position_by

A ticket for a counter position. Used when closing a counter position - open for the same instrument, but in the opposite direction.


I hope you know what a limit order is. And a stop order too, I hope you have no doubts.

And this is what it says here about how a StopLimit order works: when the price reaches the level of a Stop order (and it is placed above the price for Buy), only then will a Limit order be placed (and it is placed below the price for Buy).

 
Sergey Chalyshev:

WhenBuyLimit is below the price, it works fine in the tester.

WhenBuyLimit is above the price, it should open at Ask price.On the exchange, on the real, it works that way.

Using StopLimit to put the BuyLimit below the price makes no sense.

I'm sorry, how do you put the BuyLimit order above the price?

It shouldn't be set at all in this scenario.

If you are using a SB trading class, there is a check for erroneous parameters, and in such a situation a pending order is not placed, but a market order is opened.

 
Artyom Trishkin:

Field

Description

action

Type of trade operation. Value can be one of ENUM_TRADE_REQUEST_ACTIONSenumeration values

magic

Identifier of the Expert Advisor. Allows arranging of analytical processing of trade orders. Each Expert Advisor can display its own unique identifier when sending a trade request

order

Order Ticket. Required for modification of pending orders

symbol

Name of the symbol for which the order is placed. Not needed for modification of orders and closing of positions

Volume

Requested volume of a deal in lots. The actual value of volume when opening a position will depend on the type of order being executed.

price

This is the price at which the order should be filled. The price is not requiredfor market orders of the "Market Execution" type ( SYMBOL_TRADE_EXECUTION_MARKET ) with theTRADE_ACTION_DEALtype

stoplimit

Price at which the pending Limit order will be placed once the price reaches the price value (this condition is mandatory). Until that moment, the pending order is not placed in the trading system

sl

Price at which a Stop Loss order will be triggered when the security price moves in an unfavorable direction

tp

Price at which the Take Profit order is triggered by the price movement in the favorable direction

deviation

Maximum acceptable deviation from the requested price, set in points

type

Order type. The value can be one of the values of the enumeration ENUM_ORDER_TYPE

type_filling

Order type to execute. Value can be one of the values ofENUM_ORDER_TYPE_FILLING

type_time

Order type_filling time. Value can be one of the values ofENUM_ORDER_TYPE_TIME

expiration

Expirationtime of the pending order (for ORDER_TIME_SPECIFIEDorders )

comment

Comment to the order

position

Ticket to position. This should be filled out when a position is changed and closed to clearly identify it. This usually corresponds with the ticket of the order which resulted in the position being opened.

position_by

A ticket for a counter position. It is used when closing a position with a counter position - opened for the same instrument, but in the opposite direction.


I hope you know what a limit order is. And a stop order too, I hope you don't have any doubts.

And this is what it says here about how a StopLimit order works: when the price reaches the Stop order level (and it is placed above the price for Buy), only in this case a Limit order will be placed (and it is placed below the price for Buy).

What makes you think that the BuyLimit order should necessarily be below the price?

I'm talking about the stock market, forex is not interesting.

 
Artyom Trishkin:

Excuse me, what are you doing setting the BuyLimit order above the price?

It should not be set at all in this situation.

If you are using SB-trading class, it has a check for invalid parameters and in such a situation, the pending order is not opened, and the position is opened by market order.

I gave you an example of code above.

It should be set and it is set.

If it was opened by the market, there would be no problem in the tester; it would be opened by the Ask price. But it would be opened at a non-existent price, you can see it on the picture above.

p.s. Just try the above code yourself in an exchange account
 
"Awesome" stoplimit in the standard library, no words :))
limit should set the slippage of a market order, not the setting of a limit order :))
 
Roman:
The "awesome" stoplimit in the standard library, no words :))
limit should set the slippage of the market order, not the limit order setting :))

The slippage is set by the deviation parameter in the trade request.

And the stoplimit level is the level at which the Limit order is set relative to the stop order level.

Документация по MQL5: Константы, перечисления и структуры / Структуры данных / Структура торгового запроса
Документация по MQL5: Константы, перечисления и структуры / Структуры данных / Структура торгового запроса
  • www.mql5.com
Взаимодействие клиентского терминала и торгового сервера для проведения операций постановки ордеров производится посредством торговых запросов. Запрос представлен специальной предопределенной структурой MqlTradeRequest, которая содержит все поля, необходимые для заключения торговых сделок. Результат обработки запроса представлен структурой...
Reason: