Download MetaTrader 5
To add comments, please log in or register
Join MQL5 Cloud Network. Start earning money!
Miroslav Popov
Miroslav Popov 2016.06.27 00:23 


 I want my experts to trade on Hedging mode in the same way as in Netting mode. To do so, the expert must add, reduce, close or reverse a single position.

I'm trying to set this by setting the currently open position Ticket to the  MqlTradeRequest but it works only on reduction. 


How to set the trade request in order to make it Add, Reduce, close and Reverse a single position?

I catch the corresponding cases with the "if" blocks below:



            MqlTick tick;
            SymbolInfoTick(_Symbol, tick);

            double orderLots       = NormalizeEntrySize(lots);

            MqlTradeRequest request;
            MqlTradeResult result;
            MqlTradeCheckResult check;

            request.action       = TRADE_ACTION_DEAL;
            request.symbol       = _Symbol;
            request.volume       = orderLots;
            request.type_filling = ORDER_FILLING_FOK;
            request.type         = (type == OP_BUY) ? ORDER_TYPE_BUY : ORDER_TYPE_SELL;
            request.price        = (type == OP_BUY) ? : tick.ask;
            request.deviation    = 10;
            if (PositionSelect(_Symbol))
               ulong  posType = PositionGetInteger(POSITION_TYPE);
               ulong  ticket  = PositionGetInteger(POSITION_TICKET);
               double volume  = PositionGetDouble(POSITION_VOLUME);

               if ((posType == OP_BUY  && type == OP_BUY ) ||
                   (posType == OP_SELL && type == OP_SELL))
                    request.position = ticket; // Adding
               else if ((posType == OP_BUY  && type == OP_SELL) ||
                        (posType == OP_SELL && type == OP_BUY ))
                  if (volume == orderLots)
                      request.position = ticket; // Close
                  else if (volume > orderLots)
                      request.position = ticket; // Reducing
                  else if (volume < orderLots)
                      request.position = ticket; // Reverse
            bool isOrderCheck = OrderCheck(request, check);
            if (isOrderCheck)
                isOrderSend = OrderSend(request, result);


Can I reverse a position in Hedging mode as in  the Netting mode or I have to close it first and than to open it in the opposite direction?

To add comments, please log in or register