Error nº 1 al modificar los pedidos - página 2

 
borilunad:
¡Víctor, usted, Renat, en general señaló correctamente, Alexey mostró la última comprobación necesaria, y antes de comprobar todos los controles necesarios para cada parámetro con todos los matices para evitar la ambigüedad de significado y sin perder ninguna condición!
¿De qué serviría eso? Porque estoy restableciendo el valor de _LastError en cada función. No es que esté constantemente colgado en la memoria...
 
hoz:
¿Para qué sirve? Porque reinicio _LastError en cada función. No es que esté constantemente colgado en la memoria...
Lo siento, ¡eres víctima de tus funciones y controles! Imprime la información en el gráfico para que sea interesante, e imprime las comprobaciones de errores sólo después de las funciones de negociación.
 
evillive:
todavía tiene que comprobar que si ninguno de los 3 parámetros ha cambiado, entonces OrderModify tampoco necesita ser tocado.

Te escucho. No sirvió de nada. Aquí hay un trozo de código de mi método de modificación:

   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);
      }
   }
Podemos ver claramente que el valor del error se restablece.

Entonces obtiene la información del mercado. Si la modificación está en el probador... entonces... ...luego hago la prueba propuesta por Alexei, y... si la modificación no tiene éxito... escribir un registro y las impresiones en el registro...

En general, podemos ver que no hay errores entre ResetLastError()... No hay nada de malo en ello.

Registro:

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:

Te escucho. No sirvió de nada. Aquí hay un trozo de código de mi método de modificación:

Se puede ver claramente que el valor del error se está restableciendo.

Entonces obtiene la información del mercado. Si la modificación está en el probador... entonces... Hago la prueba propuesta por Alexei, y... si la modificación no tiene éxito, entonces... escribir un registro y las impresiones en el registro...

En general, podemos ver que no hay errores entre ResetLastError()... No hay nada de malo en ello.

Registro:

Es necesario registrar los valores anteriores de OOP, SL y TP antes del cambio para ver si son los mismos que los nuevos, entonces la causa del error #1 también estará más clara.
 

Así es...

En el Asesor Experto, llamo al método de la clase así:

 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());
            }
         }
      }

Esta es la parte de la clase que nos interesa:

// 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);
      }
   }

Aquí está el trozo de tronco que queremos:

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
 

Déjeme explicarle. La modificación tiene lugar en el método fOrderModify(). A la entrada de este método fOrderModify(), se imprimen al principio del cuerpo los valores actuales de los parámetros de la orden y los nuevos valores previstos. Puedes verlo:

   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);

Esta pieza está en el registro:

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
Puedes ver que los parámetros son todos diferentes. No debería haber ningún problema.
 
hoz:

Así es...

En el Asesor Experto, llamo al método de la clase así:

Esta es la parte de la clase que nos interesa:

Aquí está el trozo de tronco que queremos:

No entiendo qué tiene que ver la Oferta con la Oferta, si la orden está pendiente?

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());
            }
         }
      }


La Oferta siempre es menor que el Límite de Venta, por lo que la línea if(New_OOP < Oferta) nunca será verdadera... ...respectivamente, la modificación se lleva a cabo sin obstáculos.

 
hoz:

¿Por qué no creas también una matriz de errores? Está escrito en blanco y negro en la documentación que la variable _LastError almacena el número del último error. Y se restablece mediante la función ResetLastError(). Si no hay más errores entre las llamadas de _LastError, _LastError almacena el valor del último error. No hubo más errores en mi código. Bueno, esa no es la cuestión.

Estás absolutamente equivocado. El último error está bien restablecido en muchas funciones importantes. También funciona en WinAPI.

Por eso debes guardar el código de error en una variable local justo después de que se produzca y no intentar utilizarlo después de borrar esta variable del sistema diez veces en muchas de tus funciones intermedias.

 

Lo siento, SellLimit requiere dist:

no si (Nuevo_OOP<Oferta) continuar; sinosi (Nuevo_OOP-dist*Punto < Oferta) continuar;

 
hoz:

¿Cómo puedo deshacerme de este maldito error? Estoy harto. Estoy comprobando cada parámetro de entrada de la función. Para mí, en este momento, es así:

Es decir, si el parámetro no ha sido modificado, no es necesario cambiarlo. No lo he hecho antes, pero he decidido...

A continuación, los parámetros se pasan al método de modificación de la orden de la siguiente manera:

Nw salida en el registro:

Entonces, el diario nos notifica, como modificación: OK, pero luego un error. Ninguno de los parámetros ha cambiado.

La orden está pendiente. Así que podemos cambiar el precio de apertura, de parada y de toma. Y esto, según tengo entendido, no contradice la documentación.

¿Quién se ha encontrado con algo así? ¿Cómo solucionarlo?

Y no se intenta modificar las órdenes pendientes si no se modifica ninguno de los parámetros.