Error #1 when modifying orders - page 2

 
borilunad:
Victor, you, Renat, in general rightly pointed out, Alexey showed the necessary last check, and earlier check all the necessary checks for each parameter with all the nuances to avoid ambiguity of meaning and without missing any condition!
What good would that do? Because I'm resetting _LastError value in each function. It's not like it's constantly hanging in memory...
 
hoz:
What's the use of it? Because I reset _LastError in every function. It's not like it's constantly hanging in memory...
Sorry, you're a victim of your functions and checks! Output the info to the chart for interest, and print the error checks only after the trading functions!
 
evillive:
still need to check that if none of the 3 parameters has changed, then OrderModify doesn't need to be touched either.

I hear you. It didn't help. Here's a piece of code from my modification method:

   ResetLastError();
   
//---- Определяем цвет значков модификации ордеров
   if (fc_Arrow == CLR_NONE)
       fc_Arrow = ColorByModify [OrderType() % 2];
   
//---- Выполняем модификацию в тестере
   if (!CBase.GetRealTrade())         \\ Если работаем в тестере...
   {
      if ((OrderOpenPrice() != fd_OpenPrice) || (OrderStopLoss() != fd_NewSL) || (OrderTakeProfit() != fd_NewTP))
      
      if (!OrderModify (fi_Ticket, fd_OpenPrice, fd_NewSL, fd_NewTP, fdt_Expiration, fc_Arrow))
      {
         CLogs.WriteLog (StringConcatenate ("fOrderModify(): ", CErrs.ErrorToString (_LastError)));
         Print (__FUNCTION__, ": ", "После модификации тикета № ", fi_Ticket);
         Print (__FUNCTION__, ": ", "Тикет № ", fi_Ticket, "; OOP = ", fd_OpenPrice, "; SL = ", fd_NewSL, "; TP = ", fd_NewTP);
         return (false);
      }
   }
We can clearly see that the error value is reset.

Then it gets the market info. If the modification is in the tester... then... I do the test proposed by Alexei, and... if the modification is unsuccessful, then... write a log and prints in the log...

In general, we can see that there are no errors between ResetLastError()... There's nothing to be wrong there.

Log:

0       20:24:08        2013.08.26 00:00  Kevin Martens_Moi_Myrei EURUSD,M15: PositionsManipulations::fOrderModify: Вошли в функцию 
0       20:24:08        2013.08.26 00:00  Kevin Martens_Moi_Myrei EURUSD,M15: PositionsManipulations::fOrderModify: До проверки на FREEZELEVEL и STOPLEVEL  тикета № 2
0       20:24:08        2013.08.26 00:00  Kevin Martens_Moi_Myrei EURUSD,M15: PositionsManipulations::fOrderModify: Тикет № 2; OOP = 1.34048; SL = 1.34125; TP = 1.33362
0       20:24:08        2013.08.26 00:00  Kevin Martens_Moi_Myrei EURUSD,M15: PositionsManipulations::CheckLevelsBLOCK: Вошли в функцию
0       20:24:08        2013.08.26 00:00  Kevin Martens_Moi_Myrei EURUSD,M15: PositionsManipulations::CheckLevelsBLOCK: Тикет № 2; fd_NewOpenPrice = 1.34048; fd_NewSL = 1.34125; fd_NewTP = 1.33362
0       20:24:08        2013.08.26 00:00  Kevin Martens_Moi_Myrei EURUSD,M15: PositionsManipulations::CheckLevelsBLOCK: fi_Type > 2 = true
0       20:24:08        2013.08.26 00:00  Kevin Martens_Moi_Myrei EURUSD,M15: PositionsManipulations::CheckLevelsBLOCK: Тикет № 2; fd_NewOpenPrice = 1.34048; fd_NewSL = 1.34125; fd_NewTP = 1.33362
0       20:24:08        2013.08.26 00:00  Kevin Martens_Moi_Myrei EURUSD,M15: PositionsManipulations::CheckLevelsBLOCK: Вышли из функции
0       20:24:08        2013.08.26 00:00  Kevin Martens_Moi_Myrei EURUSD,M15: PositionsManipulations::fOrderModify: После проверки на FREEZELEVEL и STOPLEVEL  тикета № 2
0       20:24:08        2013.08.26 00:00  Kevin Martens_Moi_Myrei EURUSD,M15: PositionsManipulations::fOrderModify: Тикет № 2; OOP = 1.34048; SL = 1.34125; TP = 1.33362
2       20:24:08        2013.08.26 00:00  Kevin Martens_Moi_Myrei EURUSD,M15: modify #2  sell limit 0.10 EURUSD at 1.34048 sl: 1.34125 tp: 1.33362 ok
3       20:24:08        2013.08.26 00:00  Kevin Martens_Moi_Myrei EURUSD,M15: OrderModify error 1
 
hoz:

I hear you. It didn't help. Here's a piece of code from my modification method:

You can clearly see that the error value is being reset.

Then it gets the market info. If the modification is in the tester... then... ...then I run the test proposed by Alexei, and... if the modification is unsuccessful... write a log and prints in the log...

In general, we can see that there are no errors between ResetLastError()... There's nothing to be wrong there.

Log:

You need to log the previous OOP, SL and TP values before the change to see if they are the same as the new ones, then the cause of error #1 will also be clearer.
 

That's how it is...

In the Expert Advisor, I call the class method like this:

 if (OrderType() == OP_SELLLIMIT)
      {
         if (OrderOpenPrice() != ND (fd_MurreyLevelsValue[11]))
            New_OOP = ND (fd_MurreyLevelsValue[11]);
         else New_OOP = OrderOpenPrice();
         if (OrderStopLoss() != ND (fd_MurreyLevelsValue[12]))
            New_SL = ND (fd_MurreyLevelsValue[12]);
         else New_SL = OrderStopLoss();
         if (OrderTakeProfit() != ND (fd_MurreyLevelsValue[2]))
            New_TP = ND (fd_MurreyLevelsValue[2]);
         else New_TP = OrderTakeProfit();
         
         Print (__FUNCTION__, ": ", "New_OOP = ", New_OOP, "; New_SL = ", New_SL, "; New_TP = ", New_TP);
         Print (__FUNCTION__, ": ", "Тикет № ", OrderTicket(), "; OrderOpenPrice() = ", OrderOpenPrice(),
             "; OrderStopLoss() = ", OrderStopLoss(), "; OrderTakeProfit() = ", OrderTakeProfit());
             
         if (ND (OrderOpenPrice()) != fd_MurreyLevelsValue[11])
         {
            if (New_OOP < Bid) continue;
            
            if (!CPosMan.fOrderModify (Ticket,  New_OOP, New_SL, New_TP))
            {
               if (_LastError != 0)
                  CLogs.WriteLog (StringConcatenate (__FUNCTION__, ". В строке ", __LINE__, " ", CErrs.ErrorToString (_LastError)),
                                  CLogs.GetNeedLogs(), CLogs.GetPrintUP(), CLogs.GetCommentUP());
            }
            else
            {
               Print (__FUNCTION__, ": ", "Модификация тикета №", OrderTicket(), " успешно завершена!");
               Print (__FUNCTION__, ": ", "Тикет № ", OrderTicket(), "; OrderOpenPrice() = ", OrderOpenPrice(),
             "; OrderStopLoss() = ", OrderStopLoss(), "; OrderTakeProfit() = ", OrderTakeProfit());
            }
         }
      }

Here's the piece of the class we're interested in:

// 1.2 Функция модифицирует выделенный ордер (установка TP и SL). =========================================================================
bool PositionsManipulations::fOrderModify (int       fi_Ticket,             // OrderTicket()
                                           double    fd_OpenPrice,          // OpenPrice
                                           double    fd_NewSL,              // Новый StopLoss (УРОВЕНЬ !!!)
                                           double    fd_NewTP,              // Новый TakeProfit (УРОВЕНЬ !!!)
                                           datetime  fdt_Expiration = 0,    // Время истечения отложенного ордера
                                           color     fc_Arrow = CLR_NONE)   // Цвет стрелок модификации StopLoss и/или TakeProfit на графике
{
   Print (__FUNCTION__, ": ", "Вошли в функцию ");

//---- Проверяем необходимость модификации
   if (fd_NewSL == OrderStopLoss() && fd_NewTP == OrderTakeProfit())
       return (false);
//----
   string ls_fName = "fOrderModify()";
   int    li_Cnt = 0;
   double ld_Price;
   bool   lb_InvalidSTOP = false,
          lb_FixInvalidPrice = false;    // Флаг первоначальной коррекции отложки

//---- Получаем актуальную информацию по символу и текущему ордеру
   CBase.GetMarkerInfo (OrderSymbol(), fi_Ticket);
   
   Print (__FUNCTION__, ": ", "До проверки на FREEZELEVEL и STOPLEVEL  тикета № ", fi_Ticket);
   Print (__FUNCTION__, ": ", "Тикет № ", OrderTicket(), "; OrderOpenPrice() = ", OrderOpenPrice(),
             "; OrderStopLoss() = ", OrderStopLoss(), "; OrderTakeProfit() = ", OrderTakeProfit());
   Print (__FUNCTION__, ": ", "Тикет № ", fi_Ticket, "; OOP = ", fd_OpenPrice, "; SL = ", fd_NewSL, "; TP = ", fd_NewTP);
//---- Проверяем на условия FREEZELEVEL и STOPLEVEL
   if (!CheckLevelsBLOCK (3, SPos.gs_Symbol, SPos.gi_Type, fd_OpenPrice, fd_NewSL, fd_NewTP, lb_FixInvalidPrice))
   {
      if (StringLen (CErrs.ErrInf) > 0)
      {
         CLogs.WriteLog (CErrs.ErrInf);
         return (false);
      }
   }
   Print (__FUNCTION__, ": ", "После проверки на FREEZELEVEL и STOPLEVEL  тикета № ", fi_Ticket);
   Print (__FUNCTION__, ": ", "Тикет № ", fi_Ticket, "; OOP = ", fd_OpenPrice, "; SL = ", fd_NewSL, "; TP = ", fd_NewTP);
   
   ResetLastError();
   
//---- Определяем цвет значков модификации ордеров
   if (fc_Arrow == CLR_NONE)
       fc_Arrow = ColorByModify [OrderType() % 2];
   
//---- Выполняем модификацию в тестере
   if (!CBase.GetRealTrade())
   {
      if ((OrderOpenPrice() != fd_OpenPrice) || (OrderStopLoss() != fd_NewSL) || (OrderTakeProfit() != fd_NewTP))
      
      if (!OrderModify (fi_Ticket, fd_OpenPrice, fd_NewSL, fd_NewTP, fdt_Expiration, fc_Arrow))
      {
         CLogs.WriteLog (StringConcatenate ("fOrderModify(): ", CErrs.ErrorToString (_LastError)));
         Print (__FUNCTION__, ": ", "После модификации тикета № ", fi_Ticket);
         Print (__FUNCTION__, ": ", "Тикет № ", fi_Ticket, "; OOP = ", fd_OpenPrice, "; SL = ", fd_NewSL, "; TP = ", fd_NewTP);
         return (false);
      }
   }

Here's the log piece we want:

0       21:11:44        2013.08.26 09:45  Kevin Martens_Moi_Myrei EURUSD,M15: MovingLimitPositions: Выбран тикет № 2
0       21:11:44        2013.08.26 09:45  Kevin Martens_Moi_Myrei EURUSD,M15: MovingLimitPositions: Тикет № 2; OrderOpenPrice() = 1.34048; OrderStopLoss() = 1.34125; OrderTakeProfit() = 1.33362
0       21:11:44        2013.08.26 09:45  Kevin Martens_Moi_Myrei EURUSD,M15: MovingLimitPositions: New_OOP = 1.3401; New_SL = 1.34048; New_TP = 1.33667
0       21:11:44        2013.08.26 09:45  Kevin Martens_Moi_Myrei EURUSD,M15: MovingLimitPositions: Тикет № 2; OrderOpenPrice() = 1.34048; OrderStopLoss() = 1.34125; OrderTakeProfit() = 1.33362
0       21:11:44        2013.08.26 09:45  Kevin Martens_Moi_Myrei EURUSD,M15: PositionsManipulations::fOrderModify: Вошли в функцию 
0       21:11:44        2013.08.26 09:45  Kevin Martens_Moi_Myrei EURUSD,M15: PositionsManipulations::fOrderModify: До проверки на FREEZELEVEL и STOPLEVEL  тикета № 2
0       21:11:44        2013.08.26 09:45  Kevin Martens_Moi_Myrei EURUSD,M15: PositionsManipulations::fOrderModify: Тикет № 2; OrderOpenPrice() = 1.34048; OrderStopLoss() = 1.34125; OrderTakeProfit() = 1.33362
0       21:11:44        2013.08.26 09:45  Kevin Martens_Moi_Myrei EURUSD,M15: PositionsManipulations::fOrderModify: Тикет № 2; OOP = 1.3401; SL = 1.34048; TP = 1.33667
0       21:11:44        2013.08.26 09:45  Kevin Martens_Moi_Myrei EURUSD,M15: PositionsManipulations::CheckLevelsBLOCK: Вошли в функцию
0       21:11:44        2013.08.26 09:45  Kevin Martens_Moi_Myrei EURUSD,M15: PositionsManipulations::CheckLevelsBLOCK: Тикет № 2; fd_NewOpenPrice = 1.3401; fd_NewSL = 1.34048; fd_NewTP = 1.33667
0       21:11:44        2013.08.26 09:45  Kevin Martens_Moi_Myrei EURUSD,M15: PositionsManipulations::CheckLevelsBLOCK: fi_Type > 2 = true
0       21:11:44        2013.08.26 09:45  Kevin Martens_Moi_Myrei EURUSD,M15: PositionsManipulations::CheckLevelsBLOCK: Ещё Чутка дальше
0       21:11:44        2013.08.26 09:45  Kevin Martens_Moi_Myrei EURUSD,M15: PositionsManipulations::CheckLevelsBLOCK: Тикет № 2; fd_NewOpenPrice = 1.3401; fd_NewSL = 1.34048; fd_NewTP = 1.33667
0       21:11:44        2013.08.26 09:45  Kevin Martens_Moi_Myrei EURUSD,M15: PositionsManipulations::CheckLevelsBLOCK: Вышли из функции
0       21:11:44        2013.08.26 09:45  Kevin Martens_Moi_Myrei EURUSD,M15: PositionsManipulations::fOrderModify: После проверки на FREEZELEVEL и STOPLEVEL  тикета № 2
0       21:11:44        2013.08.26 09:45  Kevin Martens_Moi_Myrei EURUSD,M15: PositionsManipulations::fOrderModify: Тикет № 2; OOP = 1.3401; SL = 1.34048; TP = 1.33667
2       21:11:44        2013.08.26 09:45  Kevin Martens_Moi_Myrei EURUSD,M15: modify #2  sell limit 0.10 EURUSD at 1.34010 sl: 1.34048 tp: 1.33667 ok
3       21:11:44        2013.08.26 09:45  Kevin Martens_Moi_Myrei EURUSD,M15: OrderModify error 1
 

Let me explain. The modification takes place in method fOrderModify(). At the input of this method fOrderModify(), the current values of the order parameters and the new planned values are printed at the beginning of the body. You can see it:

   Print (__FUNCTION__, ": ", "До проверки на FREEZELEVEL и STOPLEVEL  тикета № ", fi_Ticket);
   Print (__FUNCTION__, ": ", "Тикет № ", OrderTicket(), "; OrderOpenPrice() = ", OrderOpenPrice(),
             "; OrderStopLoss() = ", OrderStopLoss(), "; OrderTakeProfit() = ", OrderTakeProfit());
   Print (__FUNCTION__, ": ", "Тикет № ", fi_Ticket, "; OOP = ", fd_OpenPrice, "; SL = ", fd_NewSL, "; TP = ", fd_NewTP);

This piece is in the log:

0       21:11:44        2013.08.26 09:45  Kevin Martens_Moi_Myrei EURUSD,M15: PositionsManipulations::fOrderModify: Вошли в функцию 
0       21:11:44        2013.08.26 09:45  Kevin Martens_Moi_Myrei EURUSD,M15: PositionsManipulations::fOrderModify: До проверки на FREEZELEVEL и STOPLEVEL  тикета № 2
0       21:11:44        2013.08.26 09:45  Kevin Martens_Moi_Myrei EURUSD,M15: PositionsManipulations::fOrderModify: Тикет № 2; OrderOpenPrice() = 1.34048; OrderStopLoss() = 1.34125; OrderTakeProfit() = 1.33362
0       21:11:44        2013.08.26 09:45  Kevin Martens_Moi_Myrei EURUSD,M15: PositionsManipulations::fOrderModify: Тикет № 2; OOP = 1.3401; SL = 1.34048; TP = 1.33667
You can see that the parameters are all different. There should be no problems.
 
hoz:

That's how it is...

In the Expert Advisor, I call the class method like this:

Here's the piece of the class we're interested in:

Here's the log piece we want:

I don't understand what the Bid has to do with the Bid, if the order is pending?

if (OrderType() == OP_SELLLIMIT)
      {
         if (OrderOpenPrice() != ND (fd_MurreyLevelsValue[11]))
            New_OOP = ND (fd_MurreyLevelsValue[11]);
         else New_OOP = OrderOpenPrice();
         if (OrderStopLoss() != ND (fd_MurreyLevelsValue[12]))
            New_SL = ND (fd_MurreyLevelsValue[12]);
         else New_SL = OrderStopLoss();
         if (OrderTakeProfit() != ND (fd_MurreyLevelsValue[2]))
            New_TP = ND (fd_MurreyLevelsValue[2]);
         else New_TP = OrderTakeProfit();
         
         Print (__FUNCTION__, ": ", "New_OOP = ", New_OOP, "; New_SL = ", New_SL, "; New_TP = ", New_TP);
         Print (__FUNCTION__, ": ", "Тикет № ", OrderTicket(), "; OrderOpenPrice() = ", OrderOpenPrice(),
             "; OrderStopLoss() = ", OrderStopLoss(), "; OrderTakeProfit() = ", OrderTakeProfit());
             
         if (ND (OrderOpenPrice()) != fd_MurreyLevelsValue[11])
         {
            if (New_OOP < Bid) continue;
            
            if (!CPosMan.fOrderModify (Ticket,  New_OOP, New_SL, New_TP))
            {
               if (_LastError != 0)
                  CLogs.WriteLog (StringConcatenate (__FUNCTION__, ". В строке ", __LINE__, " ", CErrs.ErrorToString (_LastError)),
                                  CLogs.GetNeedLogs(), CLogs.GetPrintUP(), CLogs.GetCommentUP());
            }
            else
            {
               Print (__FUNCTION__, ": ", "Модификация тикета №", OrderTicket(), " успешно завершена!");
               Print (__FUNCTION__, ": ", "Тикет № ", OrderTicket(), "; OrderOpenPrice() = ", OrderOpenPrice(),
             "; OrderStopLoss() = ", OrderStopLoss(), "; OrderTakeProfit() = ", OrderTakeProfit());
            }
         }
      }


The Bid is always lower than SellLimit, so the line if(New_OOP < Bid) will never be true... ...respectively, the modification is implemented without hindrance.

 
hoz:

Why don't you create an error array as well? It is written in black and white in the documentation that the _LastError variable stores the number of the last error. And it is reset by ResetLastError() function. If there are no more errors between calls of _LastError, _LastError stores the value of the last error. There were no more errors in my code. Well, that's not the question.

You are absolutely wrong. The last error is well reset in many important functions. It works so in WinAPI too.

That is why you should save the error code into a local variable right after it occurs and not try to use it after clearing this system variable ten times in a lot of your intermediate functions.

 

Sorry, SellLimit requires dist:

not if (New_OOP < Bid) continue; butif (New_OOP-dist*Point < Bid) continue;

 
hoz:

How do I get rid of this fucking error? I'm sick of it. I'm checking every input parameter of the function. For me, at the moment, it's like this:

That is, if the parameter hasn't been changed, there's no need to change it. I haven't done that before, but I decided to...

Then the parameters are passed to the order modification method like this:

Nw output in the log:

So, the journal notifies us, like modification: OK, but then... an error. None of the parameters has changed.

The order is pending. So we may change open, stop and take price. And this, as I understand it, did not contradict the documentation.

Who has encountered something like this? How to solve it?

And you don't try to modify the pending orders if none of the parameters are modified.
Reason: