Problem with slippage of TP and SL

 

Hello,

I am using MT4 and I've got a problem with my expert adviser. When I want to open a trade automatically through my expert adviser, there is slippage of the TPs and SLs of the open order. So what I am trying to explain- lets say I want to open an order on the current price, which is 11896.22. When my adviser opens it it goes to a pending order, and naturally there are a few pips of slippage. So the order would be opened at a price of something like 11900.32, per say. However my code currently sets the stops and the take profits, through the initial price, before the slippage and before it gets pending. So in this case SL = 11896.22+ 15 pips (let's say). Now because of the slippage, the new price will be 11900.32, but the SL and TP will remain constant, causing errors to my strategy. Is there a way to set SL and TP at the exact moment of the newly open trade (after it has left pending orders), at the eventual price.

Thank you for helping in advance.

Basic Principles - Trading Operations - MetaTrader 5 Help
Basic Principles - Trading Operations - MetaTrader 5 Help
  • 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...
 

robotfuture:

I am using MP4

When I want to open a trade automatically through my expert adviser, there is slippage of the TPs and SLs of the open order.

So what I am trying to explain- lets say I want to open an order on the current price, which is 11896.22. When my adviser opens it it goes to a pending order,

and naturally there are a few pips of slippage. So the order would be opened at a price of something like 11900.32, per say.

However my code currently sets the stops and the take profits, through the initial price, before the slippage and before it gets pending.Is there a way to set SL and TP at the exact moment of the newly open trade (after it has left pending orders), at the eventual price.

  1. You're using music (MP4?) Why did you post your MT4 question in the Root / MT5 EA section instead of the MQL4 section, (bottom of the Root page?)
              General rules and best pratices of the Forum. - General - MQL5 programming forum
    Next time post in the correct place. The moderators will likely move this thread there soon have moved this thread.

  2. TP/SL are pending orders. There is no slippage until they trigger.

  3. You can't open at the current price with a pending order.

  4. A few PIPs of slippage is huge. You probably mean points. PIP, Point, or Tick are all different in general.
              What is a TICK? - MQL4 programming forum

  5. So wait for the order to open and then either set the stops or move them by modifying the position.
 
robotfuture:


Implement virtual stop and TP functions inside the code , ex:

if(Bid<=OrderOpenPrice()-VirtualStop*Point)
               {
               Close open Buy order
              
               }

 if(Ask>=OrderOpenPrice()+VirtualStop*Point)
                {
               Close open Sell order
              
                }  
 
William Roeder:
  1. You're using music (MP4?) Why did you post your MT4 question in the Root / MT5 EA section instead of the MQL4 section, (bottom of the Root page?)
              General rules and best pratices of the Forum. - General - MQL5 programming forum
    Next time post in the correct place. The moderators will likely move this thread there soon have moved this thread.

  2. TP/SL are pending orders. There is no slippage until they trigger.

  3. You can't open at the current price with a pending order.

  4. A few PIPs of slippage is huge. You probably mean points. PIP, Point, or Tick are all different in general.
              What is a TICK? - MQL4 programming forum

  5. So wait for the order to open and then either set the stops or move them by modifying the position.

1. It was technical error/

2. I've got problem with this, because the robot put them as market execution and from there came the slippage

4. and yes it was huge several pips, that was reason to ask for help

5. Modifying position work great/ at least for my robot/

Many thanks with the help

Reason: