Partial close in MQL5...?

 
Hi, How to achieve partial close in MQL5...?
 
BHUVANESH S:
Hi, How to achieve partial close in MQL5...?
Using code or manually?
 
honest_knave:
Using code or manually?
Using code...!
 
BHUVANESH S:
Using code...!

Never done it in MT5, but I surmise you just change the volume in the MqlTradeRequest structure:

MqlTradeRequest request;

... 

...
request.volume =

...

...


Perhaps someone who knows will be along soon to help. 

 
BHUVANESH S:
Using code...!
Please show your attempt.
 
honest_knave:

Never done it in MT5, but I surmise you just change the volume in the MqlTradeRequest structure:

MqlTradeRequest request;

... 

...
request.volume =

...

...


Perhaps someone who knows will be along soon to help. 

Thankyou... It helps...!
 
Alain Verleyen:
Please show your attempt.

Try this one...! 

void ClosePartial(string symbol,int type,double lots,int ticket)
  {
      MqlTradeRequest request={0};
      MqlTradeResult  result={0};
      request.action   =TRADE_ACTION_DEAL;        
      request.position =ticket;          
      request.symbol   =symbol;          
      request.volume   =lots;                  
      request.deviation=5;
      double price=0;
      if(type==0)
      {
         request.type=ORDER_TYPE_SELL;
         request.price=SymbolInfoDouble(symbol,SYMBOL_BID);
      }
      else if(type==1)
      {                  
         request.type=ORDER_TYPE_BUY;
         request.price=SymbolInfoDouble(symbol,SYMBOL_ASK);
      }
      //request.magic    =111222;             // MagicNumber of the position      
      if(!OrderSend(request,result))
         Alert("OrderSend error "+GetLastError());
      else
         Alert("Success");
  }

 

 
BHUVANESH S:

Try this one...! 

void ClosePartial(string symbol,int type,double lots,int ticket)
  {
      MqlTradeRequest request={0};
      MqlTradeResult  result={0};
      request.action   =TRADE_ACTION_DEAL;        
      request.position =ticket;          
      request.symbol   =symbol;          
      request.volume   =lots;                  
      request.deviation=5;
      double price=0;
      if(type==0)
      {
         request.type=ORDER_TYPE_SELL;
         request.price=SymbolInfoDouble(symbol,SYMBOL_BID);
      }
      else if(type==1)
      {                  
         request.type=ORDER_TYPE_BUY;
         request.price=SymbolInfoDouble(symbol,SYMBOL_ASK);
      }
      //request.magic    =111222;             // MagicNumber of the position      
      if(!OrderSend(request,result))
         Alert("OrderSend error "+GetLastError());
      else
         Alert("Success");
  }

 

So ? What is the question/problem ?
 
Alain Verleyen #:
So ? What is the question/problem ?

How can this be automated to send a close partial order before the price target is reached. So that you don't have to wait to send a market order request?

 

Look at your pc:  ...\MQL5\Include\Trade\Trade.mqh

search for partial close to see how it works.