issue with partial order close mt4

 

Hey guys,

 I have a small issue with this part of code.

I need to close partially an order which is opened manually (so no magic)...

The problem is that the code doesn't stop to execute, so any order after will be resized as the first one till will go to 0. Ie. starting from 1 lot, will go to 0.5, 0.25 etc. but I just need to split it once.

I even added the datetime function but this didn't help... 

  if ((PartClosePercent>0)  && (Order_total>0)) {

      
       {
            
            for(int b=OrdersTotal()-1; b >= 0; b--)
               {       
               if(OrderSelect(b,SELECT_BY_POS,MODE_TRADES))
               if (OrderSymbol()==Symbol() )
               if(OrderOpenTime() != partclosedonce)
          //     if ((OrderMagicNumber() == (Magic_loop) || MagicNumber))
          //     if (OrderMagicNumber() == MagicNumber)
                    if(OrderType()==OP_BUY)
                    
                        if(Bid-OrderOpenPrice()>TP*Point) //---this is the condition, the price must be higher than TP value
                        {  
                        OrderClose(OrderTicket(),NormalizeLots(OrderSymbol(),OrderLots() *(PartClosePercent/100)), MarketInfo(OrderSymbol(),MODE_BID), 5000, Blue);
                        }partclosedonce = OrderOpenTime();
                       
                        
               }
            } 
 

if the code doesnt stop to execute it can only be because of

 if ((PartClosePercent>0)  && (Order_total>0)) 

 condition is still true.

 
Marco vd Heijden:

if the code doesnt stop to execute it can only be because of

 condition is still true.

right, how can avoid this and run it once per order? Any suggestion?

Thanks 

 
it depends on your platform.
Reason: