Close my trader MqlTradeRequest

 

Hello,

I place a trade with MqlTradeRequest structure and i want close my trade (Order = 123456 example)

When i write it :

MqlTradeRequest request={0};
   request.action=TRADE_ACTION_MODIFY;        
   request.magic=mymagic_number;       
   request.symbol = mysymbol;            
   request.volume = myvolume;       
   request.order =123456;               
   request.sl=0;                 
   request.tp=0;               
   request.type= ORDER_TYPE_BUY_STOP;                  
   request.price=GetCurrentPrice(request.type);
   MqlTradeResult result={0};
   OrderSend(request,result); 

 my order is not close ? 

do you know why

 thank a lot

Benjamin 

Documentation on MQL5: Standard Constants, Enumerations and Structures / Data Structures / Trade Request Structure
  • www.mql5.com
Standard Constants, Enumerations and Structures / Data Structures / Trade Request Structure - Documentation on MQL5
 

I'm not sure about this, but you can change this


 

I'm not sure about this, but you can change this for 

closing buy position

request.action=TRADE_ACTION_DEAL; 
request.type= ORDER_TYPE_SELL;

closing sell position

request.action=TRADE_ACTION_DEAL; 
request.type= ORDER_TYPE_BUY; 

 
biantoro:

I'm not sure about this, but you can change this for 

closing buy position

closing sell position

This it's for placed order no?

For close my order i need write :  TRADE_ACTION_MODIFY?

In the doc it's not write how use MqlTradeRequest for close Order

Documentation on MQL5: Standard Constants, Enumerations and Structures / Data Structures / Trade Request Structure
  • www.mql5.com
Standard Constants, Enumerations and Structures / Data Structures / Trade Request Structure - Documentation on MQL5
 

It's working

For close Buy => Use Sell

For close Sell => Use Buy 

 

But how can i have two positions for the same Symbol?

example 1 volume Buy and 2 volume sell? 

 
snakzbenjy:

But how can i have two positions for the same Symbol?

example 1 volume Buy and 2 volume sell? 

In MQL5 you can't have 2 position (buy and sell). Only 1 position buy or sell..
 

Hello,


I'm facing the same problem and tried to do as you said, open a sell to close a buy and vice versa but didn't work. I keep just opening new positions instead of closing the old ones. Any idea what might be happening?

 
vinyoliver:

Hello,


I'm facing the same problem and tried to do as you said, open a sell to close a buy and vice versa but didn't work. I keep just opening new positions instead of closing the old ones. Any idea what might be happening?

You are using an hedge account, while the technique described here is for a netting account.

For an hedge account you always need to specify the ticket of the position you want to close.