Download MetaTrader 5

issue with partial order close mt4

To add comments, please log in or register
Simone Gargano
9292
Simone Gargano 2015.08.27 08:53 

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();
                       
                        
               }
            } 
Marco vd Heijden
Moderator
4733
Marco vd Heijden 2015.08.27 10:52  

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

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

 condition is still true.

Simone Gargano
9292
Simone Gargano 2015.08.27 17:42  
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 

Marco vd Heijden
Moderator
4733
Marco vd Heijden 2015.08.27 18:13  
it depends on your platform.
To add comments, please log in or register