Back test and demo account have different stop losses

 

My stop loss is 10 pips, and my EA runs perfecly while backtesting. But when I change it to the demo account to test it in real time, a small percentage of my operations set a wrong stop loss.

Normally it sets tio 8 pips and it simply doesn't make any sense for me.

Why it sets correctly backtesting and in the demo sets it wrong?

(Not all the operations have wrong stop losses, actually just a few, like 1 in 10 set it wrong)

 

Possibly due to slippage.

Ie, the SL is calculated using the entry price, but due to slippage the actual entry price is slightly different.

 
Keith Watford:

Possibly due to slippage.

Ie, the SL is calculated using the entry price, but due to slippage the actual entry price is slightly different.

I thought about that, so I created a function to try to prevent slippage from happening.

void confirmSLTP(){
   
   for (int i=PositionsTotal()-1; i >= 0; i--){
      
      ulong positionTicket = PositionGetInteger(POSITION_TICKET);
      
      double positionBuyPrice = PositionGetDouble(POSITION_PRICE_OPEN);

      double positionTakeProfit = trade.RequestTP();
      
      double positionType = PositionGetInteger(POSITION_TYPE);
      
      string symbol = PositionGetSymbol(i);
      
      if(Symbol() == symbol){
         if(positionType==POSITION_TYPE_BUY){
            trade.PositionModify(positionTicket, (positionBuyPrice - 100 * _Point), positionTakeProfit);
         }
         
         if(positionType==POSITION_TYPE_SELL){
            trade.PositionModify(positionTicket, (positionBuyPrice + 100 * _Point), positionTakeProfit);
         }
      }
   }
}

I call it everytime I open a trade, shouldn't it prevent slippage? Does it make sense for you?

 
Slippage is the variance introduced by the match making machine/algorithm that selects orders from the book to match and execute.

You will not be able to prevent slippage if you want reliable order execution.

If the order on the other side, which fills your order and this order is at slightly different price and bigger than yours, you will either not get executed or receive a requote if either slippage is to small.

Btw, your function processes open positions. At that point slippage has already taken place.


 
Dominik Egert:
Slippage is the variance introduced by the match making machine/algorithm that selects orders from the book to match and execute.

You will not be able to prevent slippage if you want reliable order execution.

If the order on the other side, which fills your order and this order is at slightly different price and bigger than yours, you will either not get executed or receive a requote if either slippage is to small.

Btw, your function processes open positions. At that point slippage has already taken place.


I'm not sure if I understand it.
In my head, this function should get the entry price (the real entry price), and set my stop loss again. Not preventing slippage, but fixing it.
For example:

Lets say hypothetically that I bought when the price was 2, but it executed on 3. So my stop loss would be shortened by 1.
But my function would get the 3 (since the order already happened) and set the SL again to the correct one this time.

Where am I getting it wrong?

 
Well, as far as I can tell, that is correct.

But it does not prevent slippage, it adjusts to slippage.

Right?
 
Dominik Egert:
Well, as far as I can tell, that is correct.

But it does not prevent slippage, it adjusts to slippage.

Right?

Exactly.
I expressed myself badly by saying "prevent" instead of "adjust".
So theoretically all my SL should be 10 pips right? Are there any other things rather than slippage that could cause these rare cases of lower than 10 pips?

 
Mateus Soraggi:

Exactly.
I expressed myself badly by saying "prevent" instead of "adjust".
So theoretically all my SL should be 10 pips right? Are there any other things rather than slippage that could cause these rare cases of lower than 10 pips?

Only thing I could think of would be a rejected modify-order from your broker.

Or a disconnect between your terminal and the brokers server.

Reason: