Download MetaTrader 5

Is possible to close a position with a limit order in HEDGING system?

To add comments, please log in or register
Carry on your private correspondence in your profile. It is secure!
Rodrigo Pandini
531
Rodrigo Pandini 2016.10.07 17:25 

Hi,

I would like know if is possible to close a position (or invert it) with a limit order (TRADE_ACTION_PENDING) in HEDGING system?
Even when I set the order.position to the position id (ticket) that I would like to close, I'm getting the error 10013 "invalid request".
Since this error is vague, it don't help me to identify the real problem.
So I don't know if is possible and I'm set some other thing wrong or if is really impossible to close a position with a limit order in hedging system.
For now, I'm only able to close with a market order (TRADE_ACTION_DEAL).

MqlTradeRequest request = {0};
MqlTradeResult result = {0};
request.action = TRADE_ACTION_PENDING;
request.magic = m_magic;
request.symbol = m_symbol.Name();
request.sl = 0;
request.tp = 0;
request.deviation = 0;
request.type_time = ORDER_TIME_DAY;
request.type_filling = ORDER_FILLING_RETURN;
request.expiration = TimeLocal() + PeriodSeconds(PERIOD_D1);
request.volume = m_position.Volume();
request.comment = IntegerToString(m_magic);

request.position = positionId;

if(m_position.PositionType() == POSITION_TYPE_BUY) {            
  request.price = m_symbol.NormalizePrice(m_position.PriceOpen() + _distance);
  request.type = ORDER_TYPE_SELL_LIMIT;
}
else {
  request.price = m_symbol.NormalizePrice(m_position.PriceOpen() - _distance);
  request.type = ORDER_TYPE_BUY_LIMIT;
}
if(!OrderSend(request, result)) {
  Print(__FUNCTION__,":", result.comment, "-", result.retcode, "-", result.retcode_external); 
}
ZeroMemory(request);
ZeroMemory(result);
Alain Verleyen
Moderator
30714
Alain Verleyen 2016.10.07 17:54  
No, it's not possible.
Michael Maggi
1404
Michael Maggi 2016.10.08 05:45  
Look at Profit Targets and Trailing Stops for ways of closing any order.  There are also scripts that you can run to set these exits. 
Rodrigo Pandini
531
Rodrigo Pandini 2016.10.11 01:20  
Alain, you know why?
Thank you.
Alain Verleyen
Moderator
30714
Alain Verleyen 2016.10.11 08:01  
Rodrigo Pandini:
Alain, you know why?
Thank you.
Because in hedging system, a pending order will always result in a new position (or nothing if not triggered).
To add comments, please log in or register