Questions from Beginners MQL5 MT5 MetaTrader 5 - page 83

 

I have encountered a problem - when testing at a certain point, for unknown reasons, the error "invalid stops" appears, but the stops are correct.

The algorithm is trivial - put an order

   MqlTradeResult result = { 0 };
   MqlTradeRequest request = { 0 };
   
   double price = SymbolInfoDouble(_Symbol, isBuy ? SYMBOL_ASK : SYMBOL_BID);
   double sl = price - lvl * _Point;
   double tp = price + lvl * _Point;

   request.action = TRADE_ACTION_DEAL;
   request.magic = magic;
   request.symbol = _Symbol;
   request.volume = lot;
   request.price = price;
   request.deviation = deviation;
   request.type = isBuy ? ORDER_TYPE_BUY : ORDER_TYPE_SELL;

   OrderSend(request, result);

   order = result.order;
   
   if (order)
   {   
      ZeroMemory(result);
      ZeroMemory(request);

      request.action = TRADE_ACTION_SLTP;
      request.order = order;
      request.symbol = _Symbol;
      request.sl = isBuy ? sl : tp;
      request.tp = isBuy ? tp : sl;

      if (!OrderSend(request, result))
      {
         Print(" --- Can not modify order --- error = " + GetLastError() + " order = " + order + " price = " + price);
      }
   }

when it is closed, repeat the procedure

As a result, I've got such results (I've started in 2010.05.01):

2013.01.16 13:22:16     Core 1  2011.03.18 21:59:00    --- Can not modify order --- error = 4756 order = 4720 price = 1.41795
2013.01.16 13:22:16     Core 1  2011.03.18 21:59:00   failed modify sell 0.10 EURUSD sl: 0.00000, tp: 0.00000 -> sl: 1.42095, tp: 1.41495 [Invalid stops]
2013.01.16 13:22:16     Core 1  2011.03.18 21:59:00   order performed sell 0.10 at 1.41795 [#4720 sell 0.10 EURUSD at 1.41795]
2013.01.16 13:22:16     Core 1  2011.03.18 21:59:00   deal performed [#4720 sell 0.10 EURUSD at 1.41795]
2013.01.16 13:22:16     Core 1  2011.03.18 21:59:00   deal #4720 sell 0.10 EURUSD at 1.41795 done (based on order #4720)
2013.01.16 13:22:16     Core 1  2011.03.18 21:59:00   exchange sell 0.10 EURUSD at 1.41795 (1.41795 / 1.42399 / 1.41795)
2013.01.16 13:22:16     Core 1  2011.03.18 21:59:00   order performed buy 0.10 at 1.42003 [#4719 buy 0.10 EURUSD at 1.42003]
2013.01.16 13:22:16     Core 1  2011.03.18 21:59:00   deal performed [#4719 buy 0.10 EURUSD at 1.42003]
2013.01.16 13:22:16     Core 1  2011.03.18 21:59:00   deal #4719 buy 0.10 EURUSD at 1.42003 done (based on order #4719)
2013.01.16 13:22:16     Core 1  2011.03.18 21:59:00   stop loss triggered sell 0.10 EURUSD 1.41703 sl: 1.42003 tp: 1.41403 [#4719 buy 0.10 EURUSD at 1.42003]
2013.01.16 13:22:16     Core 1  2011.03.18 17:37:33   position modified [sell 0.10 EURUSD 1.41703 sl: 1.42003 tp: 1.41403]
2013.01.16 13:22:16     Core 1  2011.03.18 17:37:33   order performed sell 0.10 at 1.41703 [#4718 sell 0.10 EURUSD at 1.41703]
2013.01.16 13:22:16     Core 1  2011.03.18 17:37:33   deal performed [#4718 sell 0.10 EURUSD at 1.41703]
2013.01.16 13:22:16     Core 1  2011.03.18 17:37:33   deal #4718 sell 0.10 EURUSD at 1.41703 done (based on order #4718)
2013.01.16 13:22:16     Core 1  2011.03.18 17:37:33   exchange sell 0.10 EURUSD at 1.41703 (1.41703 / 1.41711 / 1.41703)
2013.01.16 13:22:16     Core 1  2011.03.18 17:37:33   order performed buy 0.10 at 1.41711 [#4717 buy 0.10 EURUSD at 1.41711]
2013.01.16 13:22:16     Core 1  2011.03.18 17:37:33   deal performed [#4717 buy 0.10 EURUSD at 1.41711]
2013.01.16 13:22:16     Core 1  2011.03.18 17:37:33   deal #4717 buy 0.10 EURUSD at 1.41711 done (based on order #4717)
2013.01.16 13:22:16     Core 1  2011.03.18 17:37:33   stop loss triggered sell 0.10 EURUSD 1.41411 sl: 1.41711 tp: 1.41111 [#4717 buy 0.10 EURUSD at 1.41711]
2013.01.16 13:22:16     Core 1  2011.03.18 13:29:27   position modified [sell 0.10 EURUSD 1.41411 sl: 1.41711 tp: 1.41111]
2013.01.16 13:22:16     Core 1  2011.03.18 13:29:27   order performed sell 0.10 at 1.41411 [#4716 sell 0.10 EURUSD at 1.41411]
2013.01.16 13:22:16     Core 1  2011.03.18 13:29:27   deal performed [#4716 sell 0.10 EURUSD at 1.41411]
2013.01.16 13:22:16     Core 1  2011.03.18 13:29:27   deal #4716 sell 0.10 EURUSD at 1.41411 done (based on order #4716)
2013.01.16 13:22:16     Core 1  2011.03.18 13:29:27   exchange sell 0.10 EURUSD at 1.41411 (1.41411 / 1.41420 / 1.41411)
2013.01.16 13:22:16     Core 1  2011.03.18 13:29:27   order performed buy 0.10 at 1.41420 [#4715 buy 0.10 EURUSD at 1.41420]
2013.01.16 13:22:16     Core 1  2011.03.18 13:29:27   deal performed [#4715 buy 0.10 EURUSD at 1.41420]
2013.01.16 13:22:16     Core 1  2011.03.18 13:29:27   deal #4715 buy 0.10 EURUSD at 1.41420 done (based on order #4715)
2013.01.16 13:22:16     Core 1  2011.03.18 13:29:27   stop loss triggered sell 0.10 EURUSD 1.41120 sl: 1.41420 tp: 1.40820 [#4715 buy 0.10 EURUSD at 1.41420]
2013.01.16 13:22:16     Core 1  2011.03.18 11:56:13   position modified [sell 0.10 EURUSD 1.41120 sl: 1.41420 tp: 1.40820]
2013.01.16 13:22:16     Core 1  2011.03.18 11:56:13   order performed sell 0.10 at 1.41120 [#4714 sell 0.10 EURUSD at 1.41120]
2013.01.16 13:22:16     Core 1  2011.03.18 11:56:13   deal performed [#4714 sell 0.10 EURUSD at 1.41120]
2013.01.16 13:22:16     Core 1  2011.03.18 11:56:13   deal #4714 sell 0.10 EURUSD at 1.41120 done (based on order #4714)
2013.01.16 13:22:16     Core 1  2011.03.18 11:56:13   exchange sell 0.10 EURUSD at 1.41120 (1.41120 / 1.41126 / 1.41120)
2013.01.16 13:22:16     Core 1  2011.03.18 11:56:13   order performed buy 0.10 at 1.41126 [#4713 buy 0.10 EURUSD at 1.41126]
2013.01.16 13:22:16     Core 1  2011.03.18 11:56:13   deal performed [#4713 buy 0.10 EURUSD at 1.41126]
2013.01.16 13:22:16     Core 1  2011.03.18 11:56:13   deal #4713 buy 0.10 EURUSD at 1.41126 done (based on order #4713)
2013.01.16 13:22:16     Core 1  2011.03.18 11:56:13   stop loss triggered sell 0.10 EURUSD 1.40826 sl: 1.41126 tp: 1.40526 [#4713 buy 0.10 EURUSD at 1.41126]
2013.01.16 13:22:16     Core 1  2011.03.18 11:00:28   position modified [sell 0.10 EURUSD 1.40826 sl: 1.41126 tp: 1.40526]
2013.01.16 13:22:16     Core 1  2011.03.18 11:00:28   order performed sell 0.10 at 1.40826 [#4712 sell 0.10 EURUSD at 1.40826]
2013.01.16 13:22:16     Core 1  2011.03.18 11:00:28   deal performed [#4712 sell 0.10 EURUSD at 1.40826]
2013.01.16 13:22:16     Core 1  2011.03.18 11:00:28   deal #4712 sell 0.10 EURUSD at 1.40826 done (based on order #4712)
2013.01.16 13:22:16     Core 1  2011.03.18 11:00:28   exchange sell 0.10 EURUSD at 1.40826 (1.40826 / 1.40835 / 1.40826)
2013.01.16 13:22:16     Core 1  2011.03.18 11:00:28   order performed buy 0.10 at 1.40832 [#4711 buy 0.10 EURUSD at 1.40832]
2013.01.16 13:22:16     Core 1  2011.03.18 11:00:28   deal performed [#4711 buy 0.10 EURUSD at 1.40832]
2013.01.16 13:22:16     Core 1  2011.03.18 11:00:28   deal #4711 buy 0.10 EURUSD at 1.40832 done (based on order #4711)
2013.01.16 13:22:16     Core 1  2011.03.18 11:00:28   stop loss triggered sell 0.10 EURUSD 1.40532 sl: 1.40832 tp: 1.40232 [#4711 buy 0.10 EURUSD at 1.40832]
2013.01.16 13:22:16     Core 1  2011.03.18 09:56:28   position modified [sell 0.10 EURUSD 1.40532 sl: 1.40832 tp: 1.40232]
2013.01.16 13:22:16     Core 1  2011.03.18 09:56:28   order performed sell 0.10 at 1.40532 [#4710 sell 0.10 EURUSD at 1.40532]
2013.01.16 13:22:16     Core 1  2011.03.18 09:56:28   deal performed [#4710 sell 0.10 EURUSD at 1.40532]
2013.01.16 13:22:16     Core 1  2011.03.18 09:56:28   deal #4710 sell 0.10 EURUSD at 1.40532 done (based on order #4710)
2013.01.16 13:22:16     Core 1  2011.03.18 09:56:28   exchange sell 0.10 EURUSD at 1.40532 (1.40532 / 1.40542 / 1.40532)
2013.01.16 13:22:16     Core 1  2011.03.18 09:56:28   order performed buy 0.10 at 1.40543 [#4709 buy 0.10 EURUSD at 1.40543]
2013.01.16 13:22:16     Core 1  2011.03.18 09:56:28   deal performed [#4709 buy 0.10 EURUSD at 1.40543]
2013.01.16 13:22:16     Core 1  2011.03.18 09:56:28   deal #4709 buy 0.10 EURUSD at 1.40543 done (based on order #4709)
2013.01.16 13:22:16     Core 1  2011.03.18 09:56:28   take profit triggered sell 0.10 EURUSD 1.40843 sl: 1.41143 tp: 1.40543 [#4709 buy 0.10 EURUSD at 1.40543]
2013.01.16 13:22:16     Core 1  2011.03.18 09:00:37   position modified [sell 0.10 EURUSD 1.40843 sl: 1.41143 tp: 1.40543]
2013.01.16 13:22:16     Core 1  2011.03.18 09:00:37   order performed sell 0.10 at 1.40843 [#4708 sell 0.10 EURUSD at 1.40843]
2013.01.16 13:22:16     Core 1  2011.03.18 09:00:37   deal performed [#4708 sell 0.10 EURUSD at 1.40843]
2013.01.16 13:22:16     Core 1  2011.03.18 09:00:37   deal #4708 sell 0.10 EURUSD at 1.40843 done (based on order #4708)
2013.01.16 13:22:16     Core 1  2011.03.18 09:00:37   exchange sell 0.10 EURUSD at 1.40843 (1.40843 / 1.40852 / 1.40843)
...

What could the problem be? (at that time 80% of my deposit was free)

 
Forux: Met with a problem - when testing at a certain point for unknown reasons, an error "invalid stops" appears, but the stops are correct.

This is what we ended up with (started 2010.05.01):

What could be the problem? (80% of the deposit was free at the time)

The error message pops up in response to position modification. At the same time, there is no check of the allowable distance of sl/tp levels from the current price in the code. It may happen that the current market price approaches the levels of sl or tp at a distance shorter than allowed by the server. Look in ORDER_STOPS_LEVEL handbook
 
Yedelkin:
The error message pops up in response to position modification. The code does not check the allowable distance of sl/tp levels from the current price. It may happen that while processing two trade requests, the current market price has moved closer to the sl or tp levels than the distance allowed by the server. Look in the ORDER_STOPS_LEVEL handbook

Made changes to the code to check:

price = SymbolInfoDouble(_Symbol, isBuy ? SYMBOL_ASK : SYMBOL_BID);
Print(" --- Can not modify order --- error = " + GetLastError() + " order = " + order + " price = " + price);

as a result the error line did not change (i.e. the price did not change). And it probably couldn't, it's two and a half years of testing on minutes, on alpari history (98% history quality).

It looks more like an error of the MetaTrader itself, because before that the same thing was happening, but there was no error.

 
Forux:Made changes to the code to check:
Well, did you check for allowable indentation too?
 
Yedelkin:
Ну а проверку на допустимый отступ тоже сделали?
Yedelkin
:

Have you checked the allowable indentation as well?

The allowable distance in the test is 0. And the price has not changed, after the error it is the same as the price at which the order was created, before the modification.

price = SymbolInfoDouble(_Symbol, isBuy ? SYMBOL_ASK : SYMBOL_BID);
Print("SymbolInfoInteger(_Symbol, SYMBOL_TRADE_STOPS_LEVEL) == " + SymbolInfoInteger(_Symbol, SYMBOL_TRADE_STOPS_LEVEL));
Print(" --- Can not modify order --- error = " + GetLastError() + " isBuy = " + isBuy + " order = " + order +  " price = " + price);

Log

2013.01.16 14:32:28     Core 1  2011.03.18 21:59:00    --- Can not modify order --- error = 4756 isBuy = false order = 4720 price = 1.41795
2013.01.16 14:32:28     Core 1  2011.03.18 21:59:00   SymbolInfoInteger(_Symbol, SYMBOL_TRADE_STOPS_LEVEL) == 0
2013.01.16 14:32:28     Core 1  2011.03.18 21:59:00   failed modify sell 0.10 EURUSD sl: 0.00000, tp: 0.00000 -> sl: 1.42095, tp: 1.41495 [Invalid stops]
2013.01.16 14:32:28     Core 1  2011.03.18 21:59:00   order performed sell 0.10 at 1.41795 [#4720 sell 0.10 EURUSD at 1.41795]
2013.01.16 14:32:28     Core 1  2011.03.18 21:59:00   deal performed [#4720 sell 0.10 EURUSD at 1.41795]
2013.01.16 14:32:28     Core 1  2011.03.18 21:59:00   deal #4720 sell 0.10 EURUSD at 1.41795 done (based on order #4720)
2013.01.16 14:32:28     Core 1  2011.03.18 21:59:00   exchange sell 0.10 EURUSD at 1.41795 (1.41795 / 1.42399 / 1.41795)
...
 
Forux: And the price hasn't changed, after the error it is the same as the price at which the order was created before the modification.

The price itself (in general) may initially be closer to the levels than the server currently allows. Therefore it is always advisable to check such a condition.

Forux : The allowable distance in the test is 0.

Yes, it's clear now that checking for indentation doesn't solve the problem in this case. Did I correctly understand that the sl/tp levels for a Sell position are set based on the Bid price?

 
Yedelkin:

The price itself (in general) may initially be closer to the levels than the server currently allows. Therefore it is always advisable to check such a condition.

Yes, it is clear now that checking for indentation does not solve the problem in this case. Did I understand correctly that sl/tp levels for Sell positions are set on the basis of Bid price?

Yes, and entry and exit are either at Ask or Bid, depending on the order type.
Документация по MQL5: Стандартные константы, перечисления и структуры / Торговые константы / Свойства ордеров
Документация по MQL5: Стандартные константы, перечисления и структуры / Торговые константы / Свойства ордеров
  • www.mql5.com
Стандартные константы, перечисления и структуры / Торговые константы / Свойства ордеров - Документация по MQL5
 
Forux: Yes, and entry and exit are either by asc or bid, depending on the order type.
Did I understand correctly that sl/tp levels for a Sell position are set based onthe Bid price? If not difficult, print out the current Ask, Bid, SL & TP for the problem area
 
Yedelkin:
Did I understand correctly that the sl/tp levels for a Sell position are set based onthe Bid price? If not difficult, print out the current Ask, Bid, SL & TP for the problem area.
2013.01.16 15:55:57     Core 1  2011.03.18 21:59:00    --- Can not modify order --- error = 4756 isBuy = false order = 4720 price = 1.41795
2013.01.16 15:55:57     Core 1  2011.03.18 21:59:00   TP == 1.41495
2013.01.16 15:55:57     Core 1  2011.03.18 21:59:00   SL == 1.42095
2013.01.16 15:55:57     Core 1  2011.03.18 21:59:00   BID == 1.41795
2013.01.16 15:55:57     Core 1  2011.03.18 21:59:00   ASK == 1.42399
2013.01.16 15:55:57     Core 1  2011.03.18 21:59:00   SymbolInfoInteger(_Symbol, SYMBOL_TRADE_STOPS_LEVEL) == 0
2013.01.16 15:55:57     Core 1  2011.03.18 21:59:00   failed modify sell 0.10 EURUSD sl: 0.00000, tp: 0.00000 -> sl: 1.42095, tp: 1.41495 [Invalid stops]
2013.01.16 15:55:57     Core 1  2011.03.18 21:59:00   order performed sell 0.10 at 1.41795 [#4720 sell 0.10 EURUSD at 1.41795]
2013.01.16 15:55:57     Core 1  2011.03.18 21:59:00   deal performed [#4720 sell 0.10 EURUSD at 1.41795]
2013.01.16 15:55:57     Core 1  2011.03.18 21:59:00   deal #4720 sell 0.10 EURUSD at 1.41795 done (based on order #4720)
2013.01.16 15:55:57     Core 1  2011.03.18 21:59:00   exchange sell 0.10 EURUSD at 1.41795 (1.41795 / 1.42399 / 1.41795)
...
Question removed. (Well, and the spread o_o).
 

Hello! There was no MT-5 programme before, but now they have started giving me in the "signals" section

I don't need any information. I use mobile Internet and pay for every Mb.

And these signals increased the consumption of the Internet by 3-4 times.

Question: how to configure what and where not to receive these signals? I have not subscribed to any of the signals.

Reason: