Invalid stops

 

Hi guys,

I am very new in programming in MQL5 and I have an issue that make me crazy and probably is just cause of my non experience.

When I run my EA, I am buying/selling lots of GOLD if the price decrese(buy) if the price increse(sell), then my program need to update the TP of the previous open positions and I create this function:

void ModifyTP(double TakeProfit)
  {
   ulong Ticket = trade.ResultOrder();
   uint check=0;

   for(int i=1; i<=PositionsTotal(); i++)
     {
      trade.PositionModify(Ticket-i,0,TakeProfit);
      check = trade.ResultRetcode();
     }
  }



Now is coming my problem:

time to time, not always, the EA is not able to succeed the modification of the TakeProfit. I don't understand the reason.

2022.10.17 15:48:43.034 2021.06.14 02:01:05   failed modify #6 buy 0.1 GOLD sl: 0.00, tp: 1893.50 -> sl: 0.00, tp: 1873.50 [Invalid stops]
2022.10.17 15:48:43.034 2021.06.14 02:01:05   CTrade::OrderSend: modify position #6 GOLD (sl: 0.00, tp: 1873.50) [invalid stops]
2022.10.17 15:48:43.034 2021.06.14 02:01:05   Alert: ERROR: 10016  invalid stops

In attached the Positions open that I wanted modify the TP.

Thanks for any advice.

Files:
error.jpg  43 kb
 

Check the offset of the stops:

  1. further away than minimum distance ( SYMBOL_TRADE_STOPS_LEVEL) to either ask or bid depending on buy or sell
  2. on the right side depending on buy or sell.
Either use Print, Comment or the debugger ...
 
Carl Schreiber #:

Check the offset of the stops:

  1. further away than minimum distance ( SYMBOL_TRADE_STOPS_LEVEL) to either ask or bid depending on buy or sell
  2. on the right side depending on buy or sell.
Either use Print, Comment or the debugger ...

Hi Carl,


I did this:

   long x = SymbolInfoInteger(_Symbol,SYMBOL_TRADE_STOPS_LEVEL);

the result of x during debugging is 200.

Sorry but I don't understand what it means.

 
  1. carlini87 #: the result of x during debugging is 200. Sorry but I don't understand what it means.

    200 points or $2.00

  2. failed modify #6 buy 0.1 GOLD sl: 0.00, tp: 1893.50 -> sl: 0.00, tp: 1873.50 [Invalid stops]

    How can the TP be below the open price of a buy order?

 
William Roeder #:
  1. 200 points or $2.00

  2. How can the TP be below the open price of a buy order?

You are right, there was a logic mistake.

Thanks for help.

 

I fixed my logic issue, but I have a better example where I get this issue:

2022.10.17 23:08:26.778 2021.06.14 06:01:37   failed modify #8 buy 0.2 GOLD sl: 0.00, tp: 1873.30 -> sl: 0.00, tp: 1873.33 [Invalid stops]
2022.10.17 23:08:26.778 2021.06.14 06:01:37   CTrade::OrderSend: modify position #8 GOLD (sl: 0.00, tp: 1873.32) [invalid stops]
2022.10.17 23:08:26.778 2021.06.14 06:01:37   failed modify #7 buy 0.1 GOLD sl: 0.00, tp: 1883.35 -> sl: 0.00, tp: 1873.33 [Invalid stops]
2022.10.17 23:08:26.778 2021.06.14 06:01:37   CTrade::OrderSend: modify position #7 GOLD (sl: 0.00, tp: 1873.32) [invalid stops]
2022.10.17 23:08:26.778 2021.06.14 06:01:37   failed modify #6 buy 0.1 GOLD sl: 0.00, tp: 1883.35 -> sl: 0.00, tp: 1873.33 [Invalid stops]
2022.10.17 23:08:26.778 2021.06.14 06:01:37   CTrade::OrderSend: modify position #6 GOLD (sl: 0.00, tp: 1873.32) [invalid stops]


The actual price is 1862.35 (see screenshot in attached) and I want modify 3 buy positions with 1873.32 but I get invalid stops for all.

Thanks