Error #1 when modifying orders - page 3

 

error 1 is a normal error...

in the tester, it usually does not occur (unless the code is curved and modifies unchanged order parameters or if the tester can generate slippages).

in the real market this (with correct order modification code) is possible when you change stops close to the market, especially with slippage - type of stop loss moves right behind the price when the order is moving to the positive and due to slippage and price movement, the error often occurs and it's clear why... good error...

 
borilunad:

Sorry, SellLimit requires dist:

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

Boris, my fOrderModify() method takes into account all checks, both, on STOPLEVEL and FRIZLEVEL. So, if any of these conditions weren't met, the modification wouldn't have been completed.

Renat:

You are absolutely wrong. The last error is still reset in many important functions. It works that way in WinAPI too.

So, save the error code into local variable right after it occurs, and don't try to use it after clearing this system variable ten times in mass of your intermediate functions.

Well, even if the error was overwritten as an option, the last one would still be there. The last error would still be 1 in my case. Isn't it so?

If I'm not even working with errors that way. Can I show you what you mean by an example?

Here's my modification function with all printers, because I'm debugging it now.(Ignore the other methods it uses).

// 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, "; New_OOP = ", fd_OpenPrice, "; New_SL = ", fd_NewSL, "; New_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, "; New_OOP = ", fd_OpenPrice, "; New_SL = ", fd_NewSL, "; New_TP = ", fd_NewTP);
   
   ResetLastError();
   
//---- Определяем цвет значков модификации ордеров
   if (fc_Arrow == CLR_NONE)
       fc_Arrow = ColorByModify [OrderType() % 2];
   
//---- Выполняем модификацию в тестере
   if (!CBase.GetRealTrade())
   {
      static int i = 0;
      
      if ((ND (OrderOpenPrice()) != fd_OpenPrice) || ND ((OrderStopLoss()) != fd_NewSL) || (ND (OrderTakeProfit()) != fd_NewTP)) {
      ResetLastError();
      
      Print (__FUNCTION__, ": ", " i = [", IToS (i), "] Тикет № ", OrderTicket(), "; OrderOpenPrice() = ", OrderOpenPrice(),
             "; OrderStopLoss() = ", OrderStopLoss(), "; OrderTakeProfit() = ", OrderTakeProfit());
      Print (__FUNCTION__, ": ", "Тикет № ", fi_Ticket, "; New_OOP = ", fd_OpenPrice, "; New_SL = ", fd_NewSL, "; New_TP = ", fd_NewTP);
      
      i++;
      
      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, "; New_OOP = ", fd_OpenPrice, "; New_SL = ", fd_NewSL, "; New_TP = ", fd_NewTP);
         return (false);
      }
      }
   }
   
//---- Выполняем модификацию в on-line торговле
   while (IsTradeAllowed() == true)
   {
      if (!IsExpertEnabled() || IsStopped() || li_Cnt > 200)
      {
         CLogs.WriteLog (StringConcatenate ("Error: Trying to modify ticket #", fi_Ticket, ", which is ", GetNameOP (SPos.gi_Type), " NOT IsTradeContextBusy"));
 
         if (!IsExpertEnabled()) {CLogs.WriteLog ("Permit ExpertEnabled !!!");}
             return (false);
      }
   
      if (OrderModify (fi_Ticket, fd_OpenPrice, fd_NewSL, fd_NewTP, fdt_Expiration, fc_Arrow))
      {
         break;
      }
   
      if (CErrs.ErrorHandling (_LastError, lb_InvalidSTOP))
         break;
 
      CLogs.WriteLog (StringConcatenate ("Error Occured : ", CErrs.ErrorToString (_LastError)));
      CLogs.WriteLog (StringConcatenate ("fOrderModify(): ", SPos.gs_Symbol, "# ", fi_Ticket, "/", GetNameOP (SPos.gi_Type), " | Price = ", DToS (fd_OpenPrice), " | SL = ", DToS (fd_NewSL), " | TP = ", DToS (fd_NewTP)));
   
      if (lb_InvalidSTOP)
      {
         RefreshRates();
 
         ld_Price = CBase.GetTradePrice (SPos.gi_Type % 2, true, SPos.gs_Symbol);
 
         if (SPos.gi_Type < 2)
         {
            CheckValidStops (ld_Price, SPos.gi_Type, fd_NewSL, fd_NewTP, false);
         }
         else
         {
            CheckValidOOP (SPos.gs_Symbol, SPos.gi_Type, fd_OpenPrice, fd_NewSL, fd_NewTP, ld_Price, lb_FixInvalidPrice);
         }
      }
      li_Cnt++;
   
      if (NumberOfTry < li_Cnt)
          return (false);
   }
//---- Контролируем возможные ошибки
   if (_LastError > 0)
       CLogs.Printing (StringConcatenate ("ls_fName => ", CErrs.ErrorToString (_LastError)));
//----
   return (true);
}
 
Victor, your first post already contained all the necessary information. You are simply sending orders to modify an order with no new values for the parameters of that order.
 

The server responds: What do you want, old man?

Or: You tell me what you want, maybe I'll give you what you want.

 

I didn't get any criticism or a hearty Russian "merci". Sad, girls...

 
tara:

I didn't get any criticism or a hearty Russian "merci". Sad, girls...

What's there to be thankful for?
 
Yes...
 
borilunad:

Sorry, SellLimit requires dist:

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

Boris, have you never encountered an opportunity to place a pending order inside the spread? And what makes you think that New_OOP doesn't contain that?
 
tara:
Victor, your first post already contained all the necessary information. You simply send orders to modify an order with no new values for that order's parameters.

Boris, let's assume that's the case... Assuming. But, if the function re-sends an order to modify the order, the significantton should be modified. And with me it doesn't modify at all. Even if we look at the log in the log, what we see is this:

modify #2  sell limit 0.10 EURUSD at 1.34048 sl: 1.34125 tp: 1.33362 ok
OrderModify error 1
Why is the order being sent? If its parameters weren't correct, the function would crash... And here it's kind of OK... ...it was sent. Then it turned out that there was an error. What is the logic behind it?
 

What does this have to do with errors? I put an error print just before the modify function:

//---- Выполняем модификацию в тестере
   if (!CBase.GetRealTrade())
   {
      if ((ND (OrderOpenPrice()) != fd_OpenPrice) || ND ((OrderStopLoss()) != fd_NewSL) || (ND (OrderTakeProfit()) != fd_NewTP)) {
      ResetLastError();
      
      Print (__FUNCTION__, ": ", " i = [", IToS (i), "] Тикет № ", OrderTicket(), "; OrderOpenPrice() = ", OrderOpenPrice(),
             "; OrderStopLoss() = ", OrderStopLoss(), "; OrderTakeProfit() = ", OrderTakeProfit());
      Print (__FUNCTION__, ": ", "Тикет № ", fi_Ticket, "; New_OOP = ", fd_OpenPrice, "; New_SL = ", fd_NewSL, "; New_TP = ", fd_NewTP);
      Print (__FUNCTION__, ": ", "_LastError = ", _LastError);                    \\ ВОТ ТУТ Я ПРОВЕРЯЮ НАЛИЧИЕ ОШИБКИ ПЕРЕД СЛЕДУЮЩЕЙ ФУНКЦИЕЙ МОДИФИКАЦИИ!!!
      
      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, "; New_OOP = ", fd_OpenPrice, "; New_SL = ", fd_NewSL, "; New_TP = ", fd_NewTP);
         return (false);
      }
      }
   }

And here's the log of this piece of code:

0       11:45:28        2013.08.26 00:00  Kevin Martens_Moi_Myrei EURUSD,M15: PositionsManipulations::fOrderModify: Тикет № 2; New_OOP = 1.34048; New_SL = 1.34125; New_TP = 1.33362
0       11:45:28        2013.08.26 00:00  Kevin Martens_Moi_Myrei EURUSD,M15: PositionsManipulations::fOrderModify:  Тикет № 2; OrderOpenPrice() = 1.34048; OrderStopLoss() = 0.0; OrderTakeProfit() = 0.0
0       11:45:28        2013.08.26 00:00  Kevin Martens_Moi_Myrei EURUSD,M15: PositionsManipulations::fOrderModify: Тикет № 2; New_OOP = 1.34048; New_SL = 1.34125; New_TP = 1.33362
0       11:45:28        2013.08.26 00:00  Kevin Martens_Moi_Myrei EURUSD,M15: PositionsManipulations::fOrderModify: _LastError = 0
2       11:45:28        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       11:45:28        2013.08.26 00:00  Kevin Martens_Moi_Myrei EURUSD,M15: OrderModify error 1
You can clearly see that there are no errors before the modification function! What does this have to do with errors?
Reason: