Cierre de medios lotes. - página 7

 
  if(OrderSelect(OrdersTotal(),SELECT_BY_TICKET,MODE_TRADES)==true && OpenOrdersThisPair(Symbol())==1 && OrderType()==OP_BUY){ // Even though I am calling "OP_BUY" here, it doesn't seem to work?
         
         }
         double minLot  = MarketInfo(Symbol(), MODE_MINLOT);
                {
                Print("The minimum lots are: ", DoubleToStr( minLot, Digits ));
                }
                        
         double lotStep = MarketInfo(Symbol(), MODE_LOTSTEP);
                {
                Print("The Lotstep is: ", DoubleToStr( lotStep, Digits ));
                }
                
         double half    = MathCeil(OrderLots()/2/lotStep)*lotStep;
                {
                Print("The Lots to close is: ", DoubleToStr( half, Digits ));
                }
      
      for( int c=OrdersTotal()-1; c >=0; c-- )
      {
         if(OrderSelect(c,SELECT_BY_POS,MODE_TRADES)==true)
            {
            Print("Order Ticker Number = ",OrderTicket());
            Print("Order Lots Open = ", OrderLots());
            } 
         else{
           Print("Order Select returned the error of ", GetLastError()); // Order Select does not seem to want to work?
            continue;
            }
            
           double FirstTarget_Buy = OrderOpenPrice() + ( ( OrderTakeProfit()-OrderOpenPrice() ) / 2 );
           {
           Print("FirstTarget_Buy: ", DoubleToStr( FirstTarget_Buy, Digits ));
           }
            if(OrderMagicNumber()==MagicNumber)
              if(OrderSymbol()==Symbol())
                
               Print("Current Bid: ", DoubleToStr(Bid, Digits), " FirstTarget_Buy: ", DoubleToStr(FirstTarget_Buy, Digits)  );
                if(OrderType()==OP_BUY && Bid >= FirstTarget_Buy +(Point / 2))
                  {
                  Print("Bid >= FirstTarget_Buy - Current Bid: ", DoubleToStr(Bid, Digits), " FirstTarget_Buy: ", DoubleToStr(FirstTarget_Buy, Digits)  );
                  bool Close_Half_Order_Buy = OrderClose(OrderTicket(),half,Bid,3,CLR_NONE);
                  if(Close_Half_Order_Buy!=TRUE)Print("Close_Half_Order_Buy Last Error = ", GetLastError());
                  }

         } 
   }
     
¡Sé que está un poco desaliñado! He estado jugando mucho con él, así que rápidamente lo puse en el lugar desde el que estábamos hablando. Supongo que te referías a toda esta parte, ¿no?
 
   if (direction==0){ //--Buy--//
      
      double bsl=buy_stop_price;
      double btp=buy_takeprofit_price;
      LotSize = (RiskedAmount/(pips_to_bsl/pips))/10;
      
      if(OpenOrdersThisPair(Symbol())==0){
         int BuyTicketOrder = OrderSend(Symbol(),OP_BUYSTOP,LotSize,buyPrice,3,bsl,btp,NULL,MagicNumber,0,Green); // This puts out the initial order.
      }
      
         if(OrderStopLoss()<iMA(NULL,0,MA_Period,0,1,0,0)-MA_PadAmount*pips){// This triggers the For loop if the pending order needs adjusting relative to where the MA is.
         
               for(int b=OrdersTotal()-1; b >=0; b--) 
                  {
    
                     if(OrderSelect(b,SELECT_BY_POS,MODE_TRADES)==true){
                     Print(" Stop loss value for the order is ", OrderStopLoss());
                     }
    
                     else if(OrderSelect(b,SELECT_BY_POS,MODE_TRADES)==false){
                     Print(" OrderSelect failed error code is ",GetLastError());
                     }
                     if(OrderMagicNumber()==MagicNumber)
                        if(OrderSymbol()==Symbol())
                           if(OrderType()==OP_BUYSTOP)
                              if(OrderStopLoss()<iMA(NULL,0,MA_Period,0,1,0,0)-MA_PadAmount*pips)
                                if(OpenOrdersThisPair(Symbol())==1) 
                                 DeleteOrder = OrderDelete(OrderTicket());
                                    if(DeleteOrder!=TRUE)Print("DeleteOrder Last Error = ", GetLastError());
                                  
                                 if(OpenOrdersThisPair(Symbol())==0) 
                                  NewBuyOrder = OrderSend(Symbol(),OP_BUYSTOP,LotSize,buyPrice,3,bsl,btp,NULL,MagicNumber,0,Green); // New Pending order with calibrated stops, lots and targets.
                                   if(NewBuyOrder!=TRUE)Print("New Buy Order Last Error = ", GetLastError());  // This is giving me an "Error 0", despite the trade ACTUALLY being placed correctly...?   

                  }
                 } 
             
               if(NewBuyOrder == true){
               Print("New Buy Order Placed #", NewBuyOrder);
               }
               else{
               Print("New Buy Order Send Failed, error # ", GetLastError());   
               }
               }
Esta es la sección de compra - sólo escupe un "OP_BUYSTOP"
 
DomGilberto:
Sé que es un poco desordenado. He estado jugando con él un montón - así que rápidamente poner de nuevo a donde estábamos hablando de? Supongo que te referías a toda esta parte, ¿no?

Erm... necesitas dar un paso atrás, respirar profundamente y leer tu código cuidadosamente, función por función, línea por línea... pregúntate "¿qué estoy tratando de hacer aquí?" y luego comprueba si tu código va a hacer eso... por ejemplo:

  if(OrderSelect(OrdersTotal(), SELECT_BY_TICKET,   MODE_TRADES)==true && OpenOrdersThisPair(Symbol())==1 && OrderType()==OP_BUY)

         { // Even though I am calling "OP_BUY" here, it doesn't seem to work?
         
         }

¿Este test if ejecuta un comentario si es verdadero? ? ? ? Ignorando eso por un momento . . ¿cómo es OrdersTotal() un número de ticket? SELECT_BY_TICKET ni siquiera es una posición válida si se utiliza SELECT_BY_POS


No creo que este código sea el que te está dando tu problema. . . aunque tiene algunos problemas.

 

Sí - buen punto, aunque eso no hace ninguna diferencia material para ser honesto.

Hmmm....

 
DomGilberto:

Sí - buen punto, aunque eso no hace ninguna diferencia material para ser honesto.

Hmmm....

No, no lo hace...

RaptorUK:


No creo que este código es lo que está dando su problema ... a pesar de que tiene algunos problemas.

No creo que estés mostrando el código que está creando el problema...

 
DomGilberto:
Esta es la sección de compra - sólo escupe un "OP_BUYSTOP"

Esto...

if(OpenOrdersThisPair(Symbol())==0) 
   NewBuyOrder = OrderSend(Symbol(),OP_BUYSTOP,LotSize,buyPrice,3,bsl,btp,NULL,MagicNumber,0,Green); // New Pending order with calibrated stops, lots and targets.

if(NewBuyOrder!=TRUE)Print("New Buy Order Last Error = ", GetLastError());  // This is giving me an "Error 0", despite the trade ACTUALLY being placed correctly...? 

. . es un problema de llaves {}. . .

if(OpenOrdersThisPair(Symbol())==0) 
   {
   NewBuyOrder = OrderSend(Symbol(),OP_BUYSTOP,LotSize,buyPrice,3,bsl,btp,NULL,MagicNumber,0,Green); // New Pending order with calibrated stops, lots and targets.

   if(NewBuyOrder != TRUE)Print("New Buy Order Last Error = ", GetLastError());  // This is giving me an "Error 0", despite the trade ACTUALLY being placed correctly...? 
   }

ordena tu sangría y "verás" estos problemas rápidamente.

 
Sí, de nuevo un buen grito, he revisado y solucionado algunos de los problemas de sangría... sin embargo, ¿todavía está atascado con los mismos problemas? ¿Qué otro código estás insinuando que podría ser? No puedo imaginar que sea de cualquier otra parte de mi codificación...
 
if(OrderSelect(OrdersTotal(),SELECT_BY_POS,MODE_TRADES)==true && OpenOrdersThisPair(Symbol())==1) // If I put "OrderType() == OP_BUY" it won't work at all. This means that it could just grab a pending order - which is wrong.
  { 
         
         
         double minLot  = MarketInfo(Symbol(), MODE_MINLOT);
                {
                Print("The minimum lots are: ", DoubleToStr( minLot, Digits ));
                }
                        
         double lotStep = MarketInfo(Symbol(), MODE_LOTSTEP);
                {
                Print("The Lotstep is: ", DoubleToStr( lotStep, Digits ));
                }
                
         double half    = MathCeil(OrderLots()/2/lotStep)*lotStep;
                {
                Print("The Lots to close is: ", DoubleToStr( half, Digits ));
                }
      
    for( int c=OrdersTotal()-1; c >=0; c-- )
      {
         if(OrderSelect(c,SELECT_BY_POS,MODE_TRADES)==true)
            {
            Print("Order Ticker Number = ",OrderTicket());
            Print("Order Lots Open = ", OrderLots());
            } 
         else{
           Print("Order Select returned the error of ", GetLastError()); 
           continue;
           }

           double FirstTarget_Buy = OrderOpenPrice() + ( ( OrderTakeProfit()-OrderOpenPrice() ) / 2 );
           {
           Print("FirstTarget_Buy: ", DoubleToStr( FirstTarget_Buy, Digits ));
           }
            
            if(OrderMagicNumber()==MagicNumber)
              if(OrderSymbol()==Symbol())
                
               Print("Current Bid: ", DoubleToStr(Bid, Digits), " FirstTarget_Buy: ", DoubleToStr(FirstTarget_Buy, Digits)  );
                
                if(OrderType()==OP_BUY && Bid >= FirstTarget_Buy +(Point / 2)) // Does not go further than this. I do not get an error from OrderClose?
                  {
                  Print("Bid >= FirstTarget_Buy - Current Bid: ", DoubleToStr(Bid, Digits), " FirstTarget_Buy: ", DoubleToStr(FirstTarget_Buy, Digits)  );
                  bool Close_Half_Order_Buy = OrderClose(OrderTicket(),half,Bid,3,CLR_NONE);
                  if(Close_Half_Order_Buy!=TRUE)Print("Close_Half_Order_Buy Last Error = ", GetLastError());
                  }
                   
       } 
   }
Estoy atascado - He intentado cambiar y cambiar mucho y ahora debe ser un caso de falta de algo que no sé que existe ... tiene que ser? OrderType()==OP_BUY no parece funcionar? Ver notas en el código de arriba - He comprobado la sangría... Esto es épico! jaja...
 
DomGilberto:
Sí, de nuevo un buen grito, he revisado y solucionado algunos de los problemas de sangría... sin embargo, ¿todavía está atascado con los mismos problemas? ¿Qué otro código estás insinuando que podría ser? No puedo imaginar que sea de cualquier otra parte de mi codificación...?
LOL, no lo sé, no lo he visto todo... pero algo está impidiendo que el código que hace la impresión se ejecute cuando tienes un OP_BUY
 
2013.08.02 10:52:47	2013.02.01 15:00  trendfishing_play_ground EURUSD,H1: NEW BUY ORDER:-  Lots to open: 0.18215 Entry Price: 1.36790 Buy Stop Loss: 1.35649 Buy Take Profit: 1.39072 Magic Number is: 1234.00000

Esto se está imprimiendo en el Diario durante mi bucle for, donde, en el caso de una orden pendiente de Buy Stop, si el 60 EMA es > que el OrderStopLoss, se cerrará la orden pendiente, abrirá una nueva con nuevo SL (que está detrás de la 60EMA), ajustar la toma de beneficios para entretener a la recompensa de 1:2, y cambiar los lotes en relación con la parada en puntos y mi perfil de riesgo (digamos 2%).

Así que cuando se hace todo esto, el "Lotes actuales" que es "LotSize" variable personalizada dentro de OrderSend funciona, es el envío de un tamaño de lote que no es correcto para el servidor para recibir? "0.18215"? ¿Podría ser esto un problema, a pesar de que las órdenes se envían de todos modos - esta pregunta es más en relación con "podría ser la razón por la que no puedo llamar "OrderType==OP_BUY"?

Esto es un proceso largo lol...

Razón de la queja: