Download MetaTrader 5
To add comments, please log in or register
The entire MQL5.community history on a single page!
Mahfoud Allali
324
Mahfoud Allali 2015.12.07 00:12 

example

open buy 0.10 lots

and i want to close just 0.05lots

Biantoro Kunarto
14806
Biantoro Kunarto 2015.12.07 02:17  
Please use this script
Files:
Rudy Sani
140
Rudy Sani 2015.12.07 02:52  
you can change it in "volume" section..
Ahmed Soliman
15712
Ahmed Soliman 2015.12.07 03:50  
int   TriesCount  = 5; 
int   _Pause      = 500;

bool CloseOrder(int TradeTicket, double lot=0, int slippage=5)
{   
   if(!OrderSelect(TradeTicket,SELECT_BY_TICKET,MODE_TRADES)) return(false);
   
   bool result=false;
   int cnt;
  
   if(OrderType()==OP_BUY)
   {
      for(cnt=0; cnt<TriesCount; cnt++)
      {
         RefreshRates();
         if(lot==0) result = OrderClose(OrderTicket(),OrderLots(),nd(MarketInfo(OrderSymbol(),MODE_BID),OrderSymbol()),slippage,Violet);
         else result = OrderClose(OrderTicket(),lot,nd(MarketInfo(OrderSymbol(),MODE_BID),OrderSymbol()),slippage,Violet);
         if(result) break; 
         else
         {
            Sleep(_Pause);               
         }
      }
   }
   if(OrderType()==OP_SELL)
   {
      for(cnt=0; cnt<TriesCount; cnt++)
      {
         RefreshRates();
         if(lot==0) result = OrderClose(OrderTicket(),OrderLots(),nd(MarketInfo(OrderSymbol(),MODE_ASK),OrderSymbol()),slippage,Violet);
         else result = OrderClose(OrderTicket(),lot,nd(MarketInfo(OrderSymbol(),MODE_ASK),OrderSymbol()),slippage,Violet);
         if(result) break; 
         else
         {
            Sleep(_Pause);               
         }
      }
   }
   if(OrderType()>OP_SELL)
   {
      for(cnt=0; cnt<TriesCount; cnt++)
      {
         result = OrderDelete(OrderTicket(),Violet);
         if(result) break; 
         else Sleep(_Pause);
      }
   }
   
   return(result);
}

//To Close Half of the Order Lots use:

CloseOrder(Ticket,OrderLots()*0.5);
Mahfoud Allali
324
Mahfoud Allali 2015.12.08 22:06  

biantoro kunarto:
Please use this script

 

Thank you, my friend really liked it because it is simple 


Mahfoud Allali
324
Mahfoud Allali 2015.12.08 22:06  
Ahmed Soliman:
Thank you, my friend :D
/
To add comments, please log in or register