Chiusura di mezzi lotti. - pagina 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());
                  }

         } 
   }
     
So che è un po' trasandato! Ci ho giocato un sacco - quindi rimettilo velocemente da dove stavamo parlando? Suppongo che tu intendessi tutta questa parte, giusto?
 
   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());   
               }
               }
Questa è la sezione Buy - sputa fuori solo un "OP_BUYSTOP"
 
DomGilberto:
So che è un po' trasandato! Ho giocato in giro con esso carichi - così rapidamente rimetterlo a posto da dove stavamo parlando? Suppongo che tu intendessi tutta questa parte, giusto?

Erm . . . devi fare un passo indietro, fare un respiro profondo e leggere attentamente il tuo codice, funzione per funzione, linea per linea . . . chiediti "cosa sto cercando di fare qui?" e poi controlla se il tuo codice lo farà . . . per esempio:

  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?
         
         }

Questo test if esegue un commento se è vero ? ? ? ? ignorando questo per un momento. . come fa OrdersTotal() ad essere un numero di biglietto? SELECT_BY_TICKET non è nemmeno una posizione valida se hai usato SELECT_BY_POS


Non credo che questo codice sia quello che ti sta dando il tuo problema . . anche se ha alcuni problemi.

 

Sì - buon punto, anche se questo non fa alcuna differenza materiale per essere onesti.

Hmmm....

 
DomGilberto:

Sì - buon punto, anche se questo non fa alcuna differenza materiale per essere onesti.

Hmmm....

No, non lo fa . . .

RaptorUK:


Non credo che questo codice sia quello che ti sta dando il tuo problema . . . anche se ha alcuni problemi.

Non credo che tu stia mostrando il codice che sta creando il problema ...

 
DomGilberto:
Questa è la sezione Buy - sputa fuori un "OP_BUYSTOP"

Questo . . .

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...? 

. . . è un problema di parentesi {}. . .

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...? 
   }

ordinate la vostra indentazione e "vedrete" rapidamente questi problemi.

 
Sì, ancora una volta, ho risolto alcuni dei problemi di indentazione... ma sono ancora bloccato con gli stessi problemi? Quale altro codice stai insinuando che potrebbe essere? Non potrei immaginare che provenga da un'altra parte del mio codice...?
 
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());
                  }
                   
       } 
   }
Sono bloccato - ho provato a spostare e cambiare molto e ora deve essere un caso di mancanza di qualcosa che non so esista... deve essere? OrderType()==OP_BUY non sembra funzionare? Vedi le note nel codice sopra - ho controllato l'indentazione... Questo è epico! haha...
 
DomGilberto:
Sì, ancora una volta, ho risolto alcuni dei problemi di indentazione... ma sono ancora bloccato con gli stessi problemi? Quale altro codice stai insinuando che potrebbe essere? Non potrei immaginare che provenga da un'altra parte del mio codice...?
LOL, non lo so, non ho visto tutto. . . ma qualcosa sta impedendo al codice che fa la stampa di funzionare quando hai 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

Questo viene stampato nel Journal durante il mio ciclo for, dove, nel caso di un ordine di acquisto pendente, se il 60 EMA è > dell'OrderStopLoss, chiuderà l'ordine pendente, ne aprirà uno nuovo con un nuovo SL (che è dietro il 60EMA), regolerà il take profit per ottenere la ricompensa 1:2, e cambierà i lotti relativi allo stop in punti e il mio profilo di rischio (diciamo 2%).

Quindi, quando tutto questo viene fatto, la variabile personalizzata "Current Lots" che è "LotSize" all'interno di OrderSend funziona, sta inviando una dimensione di lotto che non è corretta per il server a ricevere? "0.18215"? Potrebbe essere un problema, nonostante gli ordini vengano effettivamente inviati comunque - questa domanda è più in relazione a "potrebbe essere questa la ragione per cui non posso chiamare "OrderType==OP_BUY"?

Questo è un processo lungo lol...

Motivazione: