Ayuda actualizar Stop Loss

 

Hola, estoy intendando hacer un EA, pero estoy aprendiendo y me gustaria un poco de ayuda. La idea es que cuando el precio sea igual que "entry" abra 3 operaciones. 1- con tp1 y "stop", 2- con tp2 y "stop", 3 sin tp y "stop".

Ahora intento que cada vez los stop loss se actualizen al nuevo valor del parametro "stop" pero no lo consigo.


void OnTick()
  {

      double entry = iCustom(NULL,0,"entry",11,0);
      double stop = iCustom(NULL,0,"stop",1,0);
      double tp1 = iCustom(NULL,0,"tp1",7,0);
      double tp2 = iCustom(NULL,0,"tp2",9,0);
      
      if (Ask == entry && OrdersTotal() == 0)
      int buyticket = OrderSend
         (Symbol(), OP_BUY, 0.01, Ask, 3,stop,tp1, NULL, 0, 0, Green);
         
      if (Ask == entry && OrdersTotal() == 1)
      int buyticket2 = OrderSend
         (Symbol(), OP_BUY, 0.01, Ask, 3,stop,tp2, NULL, 0, 0, Green);   
      
      if (Ask == entry && OrdersTotal() == 2)
      int buyticket3 = OrderSend
         (Symbol(), OP_BUY, 0.01, Ask, 3,stop,0, NULL, 0, 0, Green);  
         

      for (int i = OrdersTotal() - 1; i >= 0; i--);
      {
      // Select an order by index i, selecting by position and from the pool of market trades.
      // If the selection is successful, proceed with the update.
      if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES))
          
         // Check if the order is for the current chart's currency pair.
         if (OrderSymbol() == Symbol())
            double OpenPrice = entry;
            double StopLossPrice = stop; //new stop loss
            
            
            // Order expiration is a required parameter, so pass the current value via OrderExpiration() function.
           if(OrdersTotal() > 0)
           OrderModify(OrderTicket(), OpenPrice, stop, 0, OrderExpiration())
        
        }
    }
Basic Principles - Trading Operations - MetaTrader 5 Help
Basic Principles - Trading Operations - MetaTrader 5 Help
  • www.metatrader5.com
Before you proceed to study the trade functions of the platform, you must have a clear understanding of the basic terms: order, deal and position...
 
prueba con esta "modificacion " de la ultima parte, y revisa lo que aparece en la pestaña experts:
for (int i = OrdersTotal() - 1; i >= 0; i--);
     {
      // Select an order by index i, selecting by position and from the pool of market trades.
      // If the selection is successful, proceed with the update.
      if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES))
        {
         // Check if the order is for the current chart's currency pair.
         if (OrderSymbol() == Symbol())
            double OpenPrice = entry;
         double StopLossPrice = NormalizeDouble(stop,Digits()); //new stop loss

         if(!OrderModify(OrderTicket(), OrderOpenPrice(), StopLossPrice, OrderTakeProfit(), OrderExpiration()))
           {
            Print("No se puede editar el SL de la orden ",OrderTicket(), " al precio ",StopLossPrice," por el error ",GetLastError());
           }
        }
     }
Saludos!!!
 
Miguel Antonio Rojas Martinez:
prueba con esta "modificacion " de la ultima parte, y revisa lo que aparece en la pestaña experts:
Saludos!!!

Aun asi no me modifica los Stop loss.


      double entry = iCustom(NULL,0,"entry",11,0);
      double stop = iCustom(NULL,0,"stop",1,0);
      double tp1 = iCustom(NULL,0,"tp1",7,0);
      double tp2 = iCustom(NULL,0,"tp2",9,0);

void OnTick()
  
{
      
      
      if (Ask == entry && OrdersTotal() == 0)
      int buyticket = OrderSend
         (Symbol(), OP_BUY, 0.01, Ask, 3,stop,tp1, NULL, 0, 0, Green);
         
      if (Ask == entry && OrdersTotal() == 1)
      int buyticket2 = OrderSend
         (Symbol(), OP_BUY, 0.01, Ask, 3,stop,tp2, NULL, 0, 0, Green);   
      
      if (Ask == entry && OrdersTotal() == 2)
      int buyticket3 = OrderSend
         (Symbol(), OP_BUY, 0.01, Ask, 3,stop,0, NULL, 0, 0, Green);  
         

      for (int i = OrdersTotal() - 1; i >= 0; i--);
     {
      // Select an order by index i, selecting by position and from the pool of market trades.
      // If the selection is successful, proceed with the update.
      if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES))
        {
         // Check if the order is for the current chart's currency pair.
         if (OrderSymbol() == Symbol())
            double OpenPrice = entry;
         double StopLossPrice = NormalizeDouble(stop,Digits()); //new stop loss

         if(!OrderModify(OrderTicket(), OrderOpenPrice(), StopLossPrice, OrderTakeProfit(), OrderExpiration()))
           {
            Print("No se puede editar el SL de la orden ",OrderTicket(), " al precio ",StopLossPrice," por el error ",GetLastError());
           }
        }
        }
        }
Archivos adjuntos:
 
iberhack:

Aun asi no me modifica los Stop loss.


Que error arroja? revisa la pestaña registros

 
Miguel Antonio Rojas Martinez:

Que error arroja? revisa la pestaña registros

Me pone el nombre del indicador usado en el icustom, simbolo, timeframe : Could not create a button (entry GBPUSD, M15 could not create a button). Pero creo que ese error no tiene que ver con modificar el stop loss ya que el indicador tiene un boton que crea en el grafico y supongo que se referira a eso. No me salta ningun otro error, pero no hay ninguna orden de modificar los stops.
 
en el codigo, CUANDO NO modifica el SL, muestra este mensaje:

 if(!OrderModify(OrderTicket(), OrderOpenPrice(), StopLossPrice, OrderTakeProfit(), OrderExpiration()))
           {
            Print("No se puede editar el SL de la orden ",OrderTicket(), " al precio ",StopLossPrice," por el error ",GetLastError());
           }
Es lo que tienes que buscar.
mas alla de eso no se puede ayudar. 
se debe hacer un backtest visual e identificar el momento en el que debia modificar y no lo hace,

Si no aparece, el error esta antes de ese tramo de codigo, asi que no se que decirte

Saludos!!!
Razón de la queja: