MT4 Strategy Tester produces strange order closes

 

I encountered a phenomenon I don't quite understand with MetaTrader4. I'm running an automated test of my expert advisor and Strategy Tester produces strange order closures. I try to explain and give you all necessary details.

My expert advisor works with prices of the last closed bar, so I run the tests with the "Open prices only" model, no need for "every tick". I run in on EURUSD on M15. I downloaded EURUSD M15 historical data from the broker (Activtrades).

On the "Results" sheet of the tester run I encounter the following trade:

# Time Type Order Size Price S/L T/P Profit Balance

225 2019.08.01 05:00 sell 110 0.10 1.10492 1.10792 1.07492 0.00 722.92

226 2019.08.01 05:15 close 110 0.10 1.10561 1.10792 1.07492 -6.90 716.02


It can be seen that order 110 is opene at 05:00 and is closed immediately in the next bar (05:15). It's a closure that MT4 tester initiated, not my expert - I checked it, since my expert logs all closes initiated by itself. It is clear that the S/L price is not reached, we are quite far from it. There are no margin issues, I have enough balance and the trade size is small.

I checked in History Center and the bar data are the following:

Time Open High Low Close Volume

2019.08.01 05:00 1.10492 1.10507 1.10468 1.10474 383

2019.08.01 05:15 1.10474 1.10498 1.10454 1.10474 452


It can be seen, that the closing price (1.10561) is NOT within the High/Low range of bar 05:15, so closing at this price should not happen normally.

I repeated the tests (even with a different version of the same expert) and it systematically produces this result. And which is worse, that it's not just this bar, but it produces the same phenomenon with many consecutive bars in this area.

I enclose a screenshot of the tester result graph, it can be clearly seen that a series of orders are closed at strange prices and none of these closes are expert initiated (even if they were expert initiated, it would be impossible to close at these prices).


What happened here?

 

Spread issue. A sell trade is closed at ASK price, you can't see it in OHLC. It's the WE, if you Spread setting is on "Current" it uses the current value which is probably very high.

Beside that, in Open Prices mode the reported price when a SL/TP is triggered is not correct.

 
Alain Verleyen:

Spread issue. A sell trade is closed at ASK price, you can't see it in OHLC. It's the WE, if you Spread setting is on "Current" it uses the current value which is probably very high.

Beside that, in Open Prices mode the reported price when a SL/TP is triggered is not correct.

Thanks Alain, that was the problem. Setting the spread to a fix value solved it. :-)

 
You buy at the Ask and sell at the Bid. So for buy orders you pay the spread on open. For sell orders you pay the spread on close.
  1. Your buy order's TP/SL (or Sell Stop's/Sell Limit's entry) are triggered when the Bid reaches it. Not the Ask. Your SL is shorter by the spread and your TP would be longer. Don't you want the same/specified amount for either direction?
  2. Your sell order's TP/SL (or Buy Stop's/Buy Limit's entry) will be triggered when the Ask reaches it. To trigger at a specific Bid price, add the average spread.
              MODE_SPREAD (Paul) - MQL4 programming forum - Page 3 #25
  3. The charts show Bid prices only. Turn on the Ask line to see how big the spread is (Tools → Options (control+O) → charts → Show ask line.)
Reason: