Pending Order as Partial Take Profit on Hedging Mode?

 

Hi all, 

Is it possible to do this?

I'm opening a position with a order like this. 10 lots with stop loss and no take profit.

CTrade t_buy;
t_buy.OrderOpen(_Symbol, ORDER_TYPE_BUY_LIMIT, 10, 0, p, sl, 0, ORDER_TIME_DAY);


Now when the order gets in (creates a position) I want to have 5 partial take profits each with 2 lots. I've read on the manuals that you can do this by informing the position ticket on the request. So now I'm doing this:

ResetLastError();
   MqlTick             tick;    SymbolInfoTick(_Symbol,tick);
   MqlTradeRequest     request={0}; ZeroMemory(request);
   MqlTradeResult      result={0};  ZeroMemory(result);
   MqlTradeCheckResult check;   ZeroMemory(check);

   request.action       = TRADE_ACTION_DEAL;
   request.symbol       = _Symbol;
   request.volume       = 2;
   request.type         = ORDER_TYPE_SELL_LIMIT;
   request.price        = takeProfit; // variable that I define earlier based on entry price
   request.type_filling = ORDER_FILLING_FOK;
   request.deviation    = 0;
   request.sl           = 0;
   request.tp           = 0;
   request.magic        = Magic_Number;
   request.position     = t_buy.RequestPosition(); 

t_buy.OrderSend(request, result);

But I'm getting error 10013 with the message

2019.01.10 21:50:11.251 2018.09.03 09:45:40   CTrade::OrderSend: exchange sell limit 2.00 position #2 WIN$N [invalid request].

Can someone help me please?

Basic Principles - Trading Operations - MetaTrader 5
Basic Principles - Trading Operations - MetaTrader 5
  • www.metatrader5.com
is an instruction given to a broker to buy or sell a financial instrument. There are two main types of orders: Market and Pending. In addition, there are special Take Profit and Stop Loss levels. is the commercial exchange (buying or selling) of a financial security. Buying is executed at the demand price (Ask), and Sell is performed at the...
 
Documentation on MQL5: Constants, Enumerations and Structures / Trade Constants / Trade Operation Types
Documentation on MQL5: Constants, Enumerations and Structures / Trade Constants / Trade Operation Types
  • www.mql5.com
Trading is done by sending orders to open positions using the OrderSend() function, as well as to place, modify or delete pending orders. Each trade order refers to the type of the requested operation. Trading operations are described in the ENUM_TRADE_REQUEST_ACTIONS enumeration...
 

Hi,

I wasn't able to understand your reply... AFAIK the OP wanted to set a pending order opposite to the opened position to sell part of its volume as a partial take profit strategy, all this in hedging mode. But your reply linked to a way of using MqlTradeRequest, with TRADE_ACTION_CLOSE_BY, that is supposed to be used to close the position entirely - even the example of the provided link don't consider the value informed in .volume. 

Documentation on MQL5: Constants, Enumerations and Structures / Trade Constants / Trade Operation Types
Documentation on MQL5: Constants, Enumerations and Structures / Trade Constants / Trade Operation Types
  • www.mql5.com
Trading is done by sending orders to open positions using the OrderSend() function, as well as to place, modify or delete pending orders. Each trade order refers to the type of the requested operation. Trading operations are described in the ENUM_TRADE_REQUEST_ACTIONS enumeration...
Reason: