Stop loss must be above order price(selling)? What if I want it not to be?

 

Hi All!


Drazen Penic said in https://www.mql5.com/en/forum/91438

Drazen Penic:

Stop loss and take profit in the MqlRequest struct are prices, not a number of points or pips.

 

sl

Stop Loss price in case of the unfavorable price movement

tp

Take Profit price in the case of the favorable price movement

 

 

One of them must be below, other must be above the order price (depending on order type - buy or sell). 

-----------------------------------------------------------------------------------------------------------------------------------------

My question is:

What if I want to place an "Stop Loss" order below the price (in case of selling) or if I want to place an "Stop Loss" order above the price (in case of buying)?

I'm trying to program a trailing stop that give me some profit, using PositionModify(), and I receive "Failed modify #10 sell 1 WIN$N sl: 96090, tp: 95715 -> sl: 96002, tp: 95715 [Invalid stops]"
This is occurring because this rule Drazen Penic said ("One of them must be below, other must be above the order price (depending on order type - buy or sell). ").

The is any way I can cancel this rule?


Best Regards!

João


Documentation on MQL5: Constants, Enumerations and Structures / Data Structures / Trade Request Structure
Documentation on MQL5: Constants, Enumerations and Structures / Data Structures / Trade Request Structure
  • www.mql5.com
Interaction between the client terminal and a trade server for executing the order placing operation is performed by using trade requests. The trade request is represented by the special predefined structure of MqlTradeRequest type, which contain all the fields necessary to perform trade deals. The request processing result is represented by...
 

You can't change this.

Stop loss and take profit must be on different sides of the current price - not the order open price. 

If you want to create trailing stop EA, there is no problem to move stop loss to be near the current price. 

For buy orders, SL must be below the current price, for sell orders SL must be above the current price.

There is one more thing you must take care - you have to use SymbolInfoInteger() and check the stop level - minimal distance in points from your stop loss to the current price. 

Documentation on MQL5: Market Info / SymbolInfoInteger
Documentation on MQL5: Market Info / SymbolInfoInteger
  • www.mql5.com
2. Returns true or false depending on whether a function is successfully performed. In case of success, the value of the property is placed into a recipient variable, passed by reference by the last parameter. It is recommended to use SymbolInfoTick() if the function is used for getting information about the last tick. It may well be that not a...
 
Drazen Penic:

You can't change this.

Stop loss and take profit must be on different sides of the current price - not the order open price. 

If you want to create trailing stop EA, there is no problem to move stop loss to be near the current price. 

Thank you Drazen!

In this specific case, i see in the journal:

---------

2020.05.25 15:38:01.795 2019.06.05 11:06:20   StopLoss change, at tickprice of 97120.0

2020.05.25 15:38:01.795 2019.06.05 11:06:20   failed modify #4 sell 1 WIN$N sl: 97300, tp: 96945 -> sl: 97216, tp: 96945 [Invalid stops]

2020.05.25 15:38:01.795 2019.06.05 11:06:20   CTrade::OrderSend: modify WIN$N (sl: 97216, tp: 96945) [invalid stops]

----------

It is a sell position, so, Stop loss is above current price!

I don't understand how I get the error...  There is a reason for PositionModify() not work in trailing stops? There is an alternative to it?

 
Did you check your broker's stoplevel for this ?
Basic Principles - Trading Operations - MetaTrader 5 Help
Basic Principles - Trading Operations - MetaTrader 5 Help
  • www.metatrader5.com
is an instruction given to a broker to buy or sell a financial instrument. There are two main types of orders: Market and Pending. In addition, there are special Take Profit and Stop Loss levels. is the commercial exchange (buying or selling) of a financial security. Buying is executed at the demand price (Ask), and Sell is performed at the...
 
Ahmet Metin Yilmaz:
Did you check your broker's stoplevel for this ?

Did it just now using:

Print("Stop changed, at price: "+last_tick.last+" broker's stoplevel is "+SymbolInfoInteger(_Symbol, SYMBOL_TRADE_STOPS_LEVEL));

The result is:

2020.05.25 15:58:48.529 2019.06.05 11:06:20   Stop changed, at price: 97120.0  broker's stoplevel is 0

2020.05.25 15:38:01.795 2019.06.05 11:06:20   failed modify #4 sell 1 WIN$N sl: 97300, tp: 96945 -> sl: 97216, tp: 96945 [Invalid stops]

2020.05.25 15:38:01.795 2019.06.05 11:06:20   CTrade::OrderSend: modify WIN$N (sl: 97216, tp: 96945) [invalid stops]

-------------------------


Maybe I used SymbolInfoInteger() Wrong?

 
aguilera_joao:

Did it just now using:

The result is:

2020.05.25 15:58:48.529 2019.06.05 11:06:20   Stop changed, at price: 97120.0  broker's stoplevel is 0

2020.05.25 15:38:01.795 2019.06.05 11:06:20   failed modify #4 sell 1 WIN$N sl: 97300, tp: 96945 -> sl: 97216, tp: 96945 [Invalid stops]

2020.05.25 15:38:01.795 2019.06.05 11:06:20   CTrade::OrderSend: modify WIN$N (sl: 97216, tp: 96945) [invalid stops]

-------------------------


Maybe I used SymbolInfoInteger() Wrong?

I dont think so, but it is ok now

 
Ahmet Metin Yilmaz:

I dont think so, but it is ok now

I still can't change the SL...
 
try this and see what is?
//+------------------------------------------------------------------+
//| The function prints out order types allowed for a symbol         |
//+------------------------------------------------------------------+
void Check_SYMBOL_ORDER_MODE(string symbol)
  {
//--- receive the value of the property describing allowed order types
   int symbol_order_mode=(int)SymbolInfoInteger(symbol,SYMBOL_ORDER_MODE);
//--- check for market orders (Market Execution)
   if((SYMBOL_ORDER_MARKET&symbol_order_mode)==SYMBOL_ORDER_MARKET)
      Print(symbol+": Market orders are allowed (Buy and Sell)");
//--- check for Limit orders
   if((SYMBOL_ORDER_LIMIT&symbol_order_mode)==SYMBOL_ORDER_LIMIT)
      Print(symbol+": Buy Limit and Sell Limit orders are allowed");
//--- check for Stop orders
   if((SYMBOL_ORDER_STOP&symbol_order_mode)==SYMBOL_ORDER_STOP)
      Print(symbol+": Buy Stop and Sell Stop orders are allowed");
//--- check for Stop Limit orders
   if((SYMBOL_ORDER_STOP_LIMIT&symbol_order_mode)==SYMBOL_ORDER_STOP_LIMIT)
      Print(symbol+": Buy Stop Limit and Sell Stop Limit orders are allowed");
//--- check if placing a Stop Loss orders is allowed
   if((SYMBOL_ORDER_SL&symbol_order_mode)==SYMBOL_ORDER_SL)
      Print(symbol+": Stop Loss orders are allowed");
//--- check if placing a Take Profit orders is allowed
   if((SYMBOL_ORDER_TP&symbol_order_mode)==SYMBOL_ORDER_TP)
      Print(symbol+": Take Profit orders are allowed");
//---
  }
Or use your terminal strings--- symbolinfosample
 
Ahmet Metin Yilmaz:
try this and see what is?


2020.05.25 16:38:48.287 2019.06.05 09:05:47   WIN$N: Market orders are allowed (Buy and Sell)

2020.05.25 16:38:48.287 2019.06.05 09:05:47   WIN$N: Buy Limit and Sell Limit orders are allowed

2020.05.25 16:38:48.287 2019.06.05 09:05:47   WIN$N: Buy Stop and Sell Stop orders are allowed

2020.05.25 16:38:48.287 2019.06.05 09:05:47   WIN$N: Buy Stop Limit and Sell Stop Limit orders are allowed

2020.05.25 16:38:48.287 2019.06.05 09:05:47   WIN$N: Stop Loss orders are allowed

2020.05.25 16:38:48.287 2019.06.05 09:05:47   WIN$N: Take Profit orders are allowed


 
Or use your terminal strings--- symbolinfosample
 

I forgot to mention - if you are setting stop loss for the sell order, you must use ask price as reference.

You can't set stop loss between bid and ask.