Stop loss not triggered timely


I am debugging an EA in strategy tester visual mode and found cases where stop loss (and also take profits( are not triggered timely.

As you can see in the attached screen capture:
  1- A sell order was executed on Jun 1srt, with a SL of  1.11285.   
  2- On the next day/candle,  the price  exceeded the SL value 
. 3- The price moved unfavourable during the next  two candles
 .4- The SL was triggered on the third.

I am using Metatrader 5 build 3550, Dec 16th 2022.

Any clues?

Thank you very much in advance.
MQL5SLTP.png  115 kb
Fernando Carreiro  

Forum on trading, automated trading systems and testing trading strategies

My position stopped unjustly

Fernando Carreiro, 2023.01.11 00:43

I will repeat ...

    • Buy positions open on the Ask price and close at the Bid price.
    • Sell positions open on the Bid price and close at the Ask price.

    Charts only show Bid prices, not Ask prices.

    So ask yourself, and find out, what the Spread and Ask price were at the time that the stop-loss was hit.



    Thank you very much for your answer. 

    Unfortunately, ASK prices are indeed greter than SL. I compiled a modified version which writes to the log, bid and ask prices of each tick (see attached image file). But in fact this is not neccesary as ASK PRICES SHOULD ALWAYS BE GRETER THAN BID ONES. So if bid prices which charts show are greter than the SL, ask prices also are.

    Am I wrong or missing something?

    MQL5SLTP2.png  150 kb
    Marzena Maria Szmit  

    As was mentioned above – the trades are closed on respective prices: sells are closed by Ask price and Buys are closed by Bid price. And charts are mostly displayed by Bid price - so the close price wont; be matching perfectly for Sell trades (it would be above the real chart price at that moment. You can see in the logs the prices are managed perfectly – sell is opened with SL 1.11285, and it’s closed a few days later on the same price (by Buy position).

    2020.06.01 00:00:00   CTrade::OrderSend: market sell 1.00 EURUSD sl: 1.11285 tp: 1.10285 [done at 1.11085]

    2020.06.08 00:00:00   stop loss triggered #18 sell 1 EURUSD 1.11085 sl: 1.11285 tp: 1.10285 [#19 buy 1 EURUSD at 1.11285]

    On the screenshot the arrow and trendline (trail of the position) seems to be moved earlier – but there might be possibility that on mq5 the objects on charts are not so precise – so just look to the prices. It’s important what is the real result not exactly how it look on the chart.


    I understand your point. But have you seen the last screenshot attached? I am  basing my argument on bid and ask prices received on each tick by OnTick procedure.

    And there you can see, that on 2020.06.02 the values are  bid=1.11349 ask=11374, both greter then SL (1.11285)

    Based on these values. SL should have been triggered on Jun 2nd, instead of Jun 8th, should't it?