Closing out half lots. - page 4

 
DomGilberto:
I can't believe I am making these rookies errors... Annoys me! Yeah, I got it printing now and selecting the order. This is the code that is working in terms of the print - the lots are still not being closed out though? I have also pasted the journal messages below.

2013.07.31 11:13:52 2013.02.01 16:00 trendfishing_play_ground EURUSD,H1: Order Select returned the error of 0 // Not sure what is going on here?

if(OrderSelect(c,SELECT_BY_TICKET,MODE_TRADES)==true)

c is a POSITION not a ticket number . . .

 

(facepalm - I obviously need a break from it!) ok sorted that and it's now selecting the order. This is the journal print now - "Close_Half_Order" error = 0? Thats the actual OrderClose function failing. It has nothing to do with the number of "000" after the second decimal place on the "lots to close is" part, is it?

2013.07.31 11:28:49     2013.02.01 15:00  trendfishing_play_ground EURUSD,H1: Close_Half_Order Last Error = 0
2013.07.31 11:28:49     2013.02.01 15:00  trendfishing_play_ground EURUSD,H1: Order Lots Open = 0.18
2013.07.31 11:28:49     2013.02.01 15:00  trendfishing_play_ground EURUSD,H1: Order Ticker Number = 9
2013.07.31 11:28:49     2013.02.01 15:00  trendfishing_play_ground EURUSD,H1: The Lots to close is: 0.09000
2013.07.31 11:28:49     2013.02.01 15:00  trendfishing_play_ground EURUSD,H1: The Lotstep is: 0.01000
2013.07.31 11:28:49     2013.02.01 15:00  trendfishing_play_ground EURUSD,H1: The minimum lots are: 0.01000
2013.07.31 11:28:49     2013.02.01 15:00  trendfishing_play_ground EURUSD,H1: FirstTarget_Buy: 1.37931
 
DomGilberto:

(facepalm - I obviously need a break from it!) ok sorted that and it's now selecting the order. This is the journal print now - "Close_Half_Order" error = 0? Thats the actual OrderClose function failing. It has nothing to do with the number of "000" after the second decimal place on the "lots to close is" part, is it?

Braces, braces, braces . . . sometimes you need to use them, sometimes you don't.

The OrderClose() didn't fail . . .

            if(OrderMagicNumber()==MagicNumber)
              if(OrderSymbol()==Symbol())
                if(OrderType()==OP_BUY)
                  if(OpenOrdersThisPair(Symbol())==1)   //  if this is true . . . 

                bool Close_Half_Order = OrderClose(OrderTicket(),half,FirstTarget_Buy,3,CLR_NONE); // . . .  do this.

            if(Close_Half_Order!=TRUE)Print("Close_Half_Order Last Error = ", GetLastError());  //  do this whatever happens . . .

so if the OrderType() is not an OP_BUY the last line will still be executed, hence the error 0 . . . add braces like this:

            if(OrderMagicNumber() == MagicNumber)
              if(OrderSymbol() == Symbol())
                if(OrderType() == OP_BUY)
                  if(OpenOrdersThisPair(Symbol()) == 1) 
                     {
                     bool Close_Half_Order = OrderClose(OrderTicket(), half, FirstTarget_Buy, 3, CLR_NONE);
                     if(Close_Half_Order != TRUE) Print("Close_Half_Order Last Error = ", GetLastError() );  // only executed if the OrderClose() was also executed
                     } 
 
Consistent indenting also helps you see clearly what is going on
 
Hmmm, still does not want to close @ "Close_Half_Order" ? Not getting any error message either?
 
DomGilberto:
Hmmm, still does not want to close @ "Close_Half_Order" ? Not getting any error message either?
What is your Order Type ?
 
OP_BUY?

  if(OrderSelect(OrdersTotal(),SELECT_BY_TICKET,MODE_TRADES)==true && OpenOrdersThisPair(Symbol())==1){
         
         double FirstTarget_Buy = OrderOpenPrice() + ( ( OrderTakeProfit()-OrderOpenPrice() ) / 2 );{
           Print("FirstTarget_Buy: ", DoubleToStr( FirstTarget_Buy, Digits ));
         }
         
         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;
            }
            if(OrderMagicNumber()==MagicNumber)
              if(OrderSymbol()==Symbol())
                if(OrderType()==OP_BUY)
                  if(OpenOrdersThisPair(Symbol())==1){ 
                bool Close_Half_Order = OrderClose(OrderTicket(),half,FirstTarget_Buy,3,CLR_NONE);
                if(Close_Half_Order!=TRUE)Print("Close_Half_Order Last Error = ", GetLastError());
                }
      } 
   }
 
DomGilberto:
OP_BUY?


Is it though ? you talked before about pending orders, do you actually have an OP_BUY open when testing ? or do you have a pending order open ?
 

By the way, these braces do nothing other than confusing the situation . . .

         double FirstTarget_Buy = OrderOpenPrice() + ( ( OrderTakeProfit()-OrderOpenPrice() ) / 2 );  {  
           Print("FirstTarget_Buy: ", DoubleToStr( FirstTarget_Buy, Digits ));
         }  
         
         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 ));
                }  
 

I put in a pending order "OP_BUYSTOP" but I was under the impression that this would change when triggered to an "OP_BUY"?

I thought the order type would be "OP_BUY" if it had been triggered?

Afterall, I am only interested ONCE the order has been triggered?

Why are those braces confusing? Do you mean in terms of where the left parenthesis is? If so, it seems that is an individual thing, as I have been corrected on this multiple times?

Reason: