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.
- www.mql5.com
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?
- www.metatrader5.com
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?
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
I dont think so, but it is ok now
//+------------------------------------------------------------------+ //| 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
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
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.
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
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