Ignored Stoploss During Backtest

 
My stoploss was ignored during the backtest, does anyone know why the price just went through the stoploss? thanks.
Files:
Capture.PNG  11 kb
 
Steven:
My stoploss was ignored during the backtest, does anyone know why the price just went through the stoploss? thanks.

I should imagine that you are using open prices only on the daily chart in your test.

 
Yes, so the stoploss should work correctly when im forward testing with a demo account?
 
Steven:
Yes, so the stoploss should work correctly when im forward testing with a demo account?

It should work reasonably correctly when testing with every tick.

 
Steven:
Yes, so the stoploss should work correctly when im forward testing with a demo account?

That is a not so very well-known terminal bug and it may happen not only in the tester but on demo servers too. It is documented here:

https://github.com/rosasurfer/mt4-mql/issues/10

There is also a workaround but unfortunately it requires manual coding. Surprisingly the bug is already more than 12 years old and until now nobody seems to have cared about it.

Tester & demo servers execute only one limit per ticket and tick · Issue #10 · rosasurfer/mt4-mql
Tester & demo servers execute only one limit per ticket and tick · Issue #10 · rosasurfer/mt4-mql
  • rosasurfer
  • github.com
New issue Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community. Already on GitHub? Sign in to your account
 

SL/TP are respected also if EA tested with open prices only mode.

You have a different issue, it's also so strange that order get executed and closed with loss in the same exact moment (2011.12.20 00:00)

 
Fabio Cavalloni:

SL/TP are respected also if EA tested with open prices only mode.

You have a different issue, it's also so strange that order get executed and closed with loss in the same exact moment (2011.12.20 00:00)

You are wrong. As it is described in the ticket: Only one limit per ticket and tick is executed.

(1) If a pending entry order has a SL atttached and both limits are triggered by the same tick the entry limit is executed and the SL is not (one limit check per tick only, the open position is invalid and this by itself is already a broken implementation).

(2) If the next tick doesn't trigger the SL the limit is not executed again (the open position stays invalid). Worse: By now the terminal has "forgotten" about the SL ever been hit.

(3) If it now happens that the market continous to go in the direction of the wrongly open position without hitting the SL a second time the position stays open until the end of the test. Of course the whole test is invalid.

That is exactly what OP observed.


Cause of the bug is the terminal only checking a single limit per ticket and tick. If more limits are triggered (max 2) the second is ignored and not executed.

Workaround: If you use pending orders with SL you have to manually monitor the ticket for execution. On the execution tick (only on that tick) you need to check whether the SL was triggered too (price comparison). If it was triggered you have to execute the SL manually by using OrderClose() as the terminal will not do it.

SL not executed

The screenshot shows a Buy Limit at 1439.27 with SL at 1438.17, both triggered by a single tick down to 1437.16 (a news spike). The position was opened but the SL was not executed because it happened during a single tick. The SL had to be executed manually.

The observed behaviour occures in tester in ControlPoint and EveryTick mode, and in live trading with demo accounts.
Reason: