Closing out half lots. - page 2

 

I need to read up on MathFloor and your link there - this is all new to me and am struggling to understand it. Ill tackle it tomorrow.

Thanks guys!

 
         if(Bid == btp-OrderOpenPrice()/2+OrderOpenPrice()){ // need to double check this.
               
               
         double  minLot  = MarketInfo(Symbol(), MODE_MINLOT),
                 lotStep = MarketInfo(Symbol(), MODE_LOTSTEP),
                 Lots    = OrderLots(),
                 half_close = MathFloor(Lots/2/lotStep)*lotStep;
                 
                    
               
         for(int q=OrdersTotal()-1; q >=0; q--)
         {
            if(OrderSelect(q,SELECT_BY_POS,MODE_TRADES)==true){
              Print(" Stop loss value for the order is ", OrderStopLoss());
              Print("lots for the order ",OrderLots());
            }
            else if(OrderSelect(q,SELECT_BY_POS,MODE_TRADES)==false){
              Print(" OrderSelect failed error code is ",GetLastError());
            }
            if(OrderMagicNumber()==MagicNumber)
             if(OrderSymbol()==Symbol())
              if(OrderType()==OP_BUYSTOP)
               if (half_close > minLot)

                
               CloseHalfLong = OrderClose(OrderTicket(),half_close,Bid,3,CLR_NONE);
               if(CloseHalfLong!=TRUE)Print("LastError = ", GetLastError());
         }
         } 
Could someone give me a little guidance on where it is I am going wrong? Just started to have a look at this now. Apart from the line where I have written a note, could someone point me in the right direction?
 
Any ideas?
 
DomGilberto:
Any ideas?
You want to close half of OrderLots() ? but how can you use OrderLots() before you have selected an Order ?
 
Whoops - yea sorted that lol. That hasnt changed anything though?

Am I missing something?
 
DomGilberto:
Whoops - yea sorted that lol. That hasnt changed anything though?

Am I missing something?

Why are you doing the following even if your OrderSelect() has failed ?

if(OrderMagicNumber()==MagicNumber)
             if(OrderSymbol()==Symbol())
              if(OrderType()==OP_BUYSTOP)
               if (half_close > minLot)

You don't close a pending Order, what did your error reporting tell you ?

 

I believe that you are attempting to select the same trade twice

shouldn't this just be "else"?

else if(OrderSelect(q,SELECT_BY_POS,MODE_TRADES)==false){

you may get conflicting messages if the first time you try to select the trade, it fails, but succeeds the 2nd time.

 
I am not getting any error...

I'm getting a little frustrated with it... I keep getting "OrderModify error 1" - but I will look into that later. Other than that, nothing!
            if(OrderSelect(NewOrder,SELECT_BY_TICKET,MODE_TRADES)==true){
              Print(" Stop loss value for the order is ", OrderStopLoss());
              Print("lots for the order ",OrderLots());
            }
            else if(OrderSelect(NewOrder,SELECT_BY_TICKET,MODE_TRADES)==false){
              Print(" OrderSelect failed error code is ",GetLastError());
            }
            
            double  minLot = MarketInfo(Symbol(), MODE_MINLOT),
            lotStep     = MarketInfo(Symbol(), MODE_LOTSTEP),
            sizeCurr    = OrderLots(),
            sizeClose   = MathFloor(sizeCurr/lotStep)*lotStep/2,
            sizeRem     = sizeCurr - sizeClose;
           //if (sizeClose < minLot)                                     return(false);
            //if (sizeRem   < minLot){ sizeClose = sizeCurr;
                 
           if(OrderTakeProfit()-OrderOpenPrice()/2+OrderOpenPrice() == Bid) // Does this make sense? I am wanting this "if" statement to be true, if price (bid) reaches the price in this comparison statement?

             if(OpenOrdersThisPair(Symbol())==1)
               
               CloseHalfLong = OrderClose(OrderTicket(),sizeClose,Bid,3,CLR_NONE);
                
                if(CloseHalfLong!=TRUE)Print("Last Error = ", GetLastError());
         
         } 
I was under the impression that MathFloor just rounds the answer to whole number? So I am not sure if MathFloor is correct? The brokers I am using will use 0.01 as a lot-step... (IBFX to start with on the forward testing - so nano size)
 
DomGilberto:
I am not getting any error...

I'm getting a little frustrated with it... I keep getting "OrderModify error 1" - but I will look into that later. Other than that, nothing! I was under the impression that MathFloor just rounds the answer to whole number? So I am not sure if MathFloor is correct? The brokers I am using will use 0.01 as a lot-step... (IBFX to start with on the forward testing - so nano size)

I gave you code that will work, why aren't you using it ? why aren't you printing your variables to see what is happening ? you don't have an OrderModify() in the code you posted, how is it relevant ? as I already said . . . why are you calling trading functions that rely on OrderSelect() if the OrderSelect() has failed ?

Stop coding, look at your code, read through it line by line, understand what it is actually doing and if it's not what you intended then you have an issue you need to fix.

 

Does MathFloor round decimal places DOWN to the nearest WHOLE number?

Does FirstTarget make sense as a custom parameter within "OrderClose()" - Assuming "sizeClose" was correct? (see quoted code)

Your code did not help - sorry.

Can you print custom variables? If so, I must be doing it wrong as it is not showing up in the journal.

OrderModify is not relevant, you are right.

           double FirstTarget = OrderTakeProfit()-OrderOpenPrice()/2+OrderOpenPrice();
              CloseHalfLong = OrderClose(OrderTicket(),sizeClose,FirstTarget,3,CLR_NONE);
Reason: