Possibly due to slippage.
Ie, the SL is calculated using the entry price, but due to slippage the actual entry price is slightly different.
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?
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?
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?
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.
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
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)