TP and SL on Pending Orders >> Major Problem when orders are slipped.

 

Hello MQL5 community,

I have started developing my own MT4 EAs in 2015 and today I just realized a major MT4 problem.

The problem can be harmless in normal conditions, but when slippage occurs on entries, it might be very annoying actually.

Many times I get slippage on activation of pending orders. When that happens the original TP and SL levels set up, are not adjusted accordingly. Because they were based on the original Pending Order and not on the OrderOpenPrice() value.

Instead they actually stay on the same place as they were set to be, no matter the slippage.

 

The only turn around would be to never use Pending Orders, and setting the SL and TP accordingly to the real price marked by OrderOpenPrice(). And not the opening price we originally set (without slippage).

For same case scenarios like News Trading (news straddling and so on) it makes the usage of SL and TP on Pending Orders extremely counter productive since order will very probably get a lot slipped.

I am trying to code a function that will adjust the SL and TP to the right levels in case of slippage.

But if anyone has already developed something like that. It would be great to know.

 

Regards,

 
Pedro:

Hello MQL5 community,

I have started developing my own MT4 EAs in 2015 and today I just realized a major MT4 problem.

The problem can be harmless in normal conditions, but when slippage occurs on entries, it might be very annoying actually.

Many times I get slippage on activation of pending orders. When that happens the original TP and SL levels set up, are not adjusted accordingly. Because they were based on the original Pending Order and not on the OrderOpenPrice() value.

Instead they actually stay on the same place as they were set to be, no matter the slippage.

 

The only turn around would be to never use Pending Orders, and setting the SL and TP accordingly to the real price marked by OrderOpenPrice(). And not the opening price we originally set (without slippage).

For same case scenarios like News Trading (news straddling and so on) it makes the usage of SL and TP on Pending Orders extremely counter productive since order will very probably get a lot slipped.

I am trying to code a function that will adjust the SL and TP to the right levels in case of slippage.

But if anyone has already developed something like that. It would be great to know.

 

Regards,

Forget about it guys. I already coded my solution.

Check the function out:

 

void CheckSlippedOrder( ){

   bool wasmodified = false;

   int tip;

   int par_ticket;

   double openprice;

   orderBuyTP = NormalizeDouble(OrderOpenPrice()+TakeProfit*Point,Digits);

   orderBuySL = NormalizeDouble(OrderOpenPrice()-StopLoss*Point,Digits);

   orderSellTP = NormalizeDouble(OrderOpenPrice()-TakeProfit*Point,Digits);

   orderSellSL = NormalizeDouble(OrderOpenPrice()+StopLoss*Point,Digits);

   for (int i=0; i<OrdersTotal(); i++)

         { 

          if (OrderSelect(i,SELECT_BY_POS,MODE_TRADES)==true)

            {

             if (OrderSymbol()!=Symbol()||OrderMagicNumber()!=OrderMagic) continue;

             tip=OrderType();

             par_ticket=OrderTicket();

             openprice = OrderOpenPrice();

             //Buy Orders

             if (tip==0)

               {

               // Modify order TsP and SLs in case  Open Order got slipped

               if (buystop != openprice ) // if this condition happens it means activation price is different from 

               wasmodified = OrderModify( par_ticket, 0, orderBuySL, orderBuyTP, 0, Blue ); 

               #OriginalEntryPrice = OrderOpenPrice(); // so as the EA will not keep on sending the mdofication request

               }

             //Sell Orders

             if (tip==1)

               {

               // Modify order TsP and SLs in case  Open Order got slipped

               if (sellstop != openprice ) // if this condition happens it means activation price is different from 

               wasmodified = OrderModify( par_ticket, 0, orderSellSL, orderSellTP, 0, Blue ); 

               #OriginalEntryPrice = OrderOpenPrice(); // so as the EA will not keep on sending the mdofication request

               }

            }

      }

Reason: