DEV Community

Cover image for Is your MT5 EA losing on its entries or its exits? A free report analyser
Tomozo / HAWK Backtester
Tomozo / HAWK Backtester

Posted on

Is your MT5 EA losing on its entries or its exits? A free report analyser

The MT5 Strategy Tester gives you a lot of numbers: profit factor, drawdown, win rate, consecutive losses. What it doesn't tell you is which part of the EA to change. A profit factor of 0.58 says the EA is losing. It doesn't say whether the entries are wrong or the exits are.

So I made a small free tool that reads the Strategy Tester's HTML report and answers that question. It runs in the browser, needs no account, and the report never leaves your machine.

https://app.hawk-backtester.com/en/tools/mt5-report/?utm_source=devto&utm_medium=article&utm_campaign=mt5

The analyser on the sample report

Two kinds of losing trade

Every losing trade belongs somewhere on a line between two cases.

  • It was in profit first. The price moved your way, then came back and hit the stop. The entry was fine; the exit gave it away. Work on the take profit, a trailing stop or moving the stop to break even.
  • It went wrong right away. The price never moved your way. No exit rule would have saved it. Work on the entry: the signal itself, or the market conditions you enter in.

To tell them apart you need each trade's best open profit (MFE) and worst open loss (MAE). The MT5 report doesn't have those, so the tool asks for one more file: a bar CSV exported from MT5 for the same symbol and period. With the bars it walks every trade from entry to exit and records how far it went each way.

On the sample report (a breakout EA on synthetic EURUSD M15 data), 90 of 136 trades lost:

  • 31 had been in profit first, by 0.00204 on average, before losing. Exit problem.
  • 30 were barely ever in profit. Entry problem.
  • 29 were somewhere in between.

That is an even split, which is itself useful: changing only the take profit would address a third of the losses at most.

Is the stop wider than it needs to be?

The tool also looks at the winners. In the sample, 90% of winning trades never went more than 0.00218 against you, and the median stop was 0.00250, so the stop is not wider than winners needed. If it were 0.00500, you would be paying for room no winner used.

This check can't tell you a stop is too tight, though. A trade that needed more room was stopped out and counts as a loser, so it never shows up among the winners. (Updated after a reader pointed this out in the comments.)

Where it makes and loses money

With the bars, each trade also gets the market regime just before entry: uptrend, downtrend or range, from ADX(14) on hourly bars. In the sample, ranging markets accounted for 93 trades and -685 of the -965 total. For a breakout EA, that points to a filter rather than a new exit rule.

There are also tables by exit reason, holding time and hour of day, and every finding links to the trades behind it.

How it works

  • The report is UTF-16 HTML with labels in whatever language your terminal uses. The parser finds the deals table by its shape (13 columns, buy/sell and in/out values) rather than by header names, so a Japanese or German report works the same as an English one.
  • Deals are rebuilt into trades first in, first out, so partial closes and reversals become separate trades.
  • The order of prices inside a bar is unknown, so MFE and MAE use the highs and lows of bars that lie entirely between entry and exit. A trade opened mid-bar would otherwise be credited with moves from before it existed, so for the entry and exit bars only the fill prices count. That errs low; M1 or M5 bars recover more of the path. (Also changed after the same comment.)
  • Everything runs in plain JavaScript in the page. Nothing is uploaded unless you sign in and choose to save.

Comparing two versions of an EA

If you sign in (free), you can save reports and compare two of them. Trades are matched by side and entry time, so you can see which trades a change actually affected: which ones it saved, which ones it broke, and which were new. When you tweak an EA, the total usually moves a little; the per-trade view shows whether that came from the change you meant to make.

Limits

  • MT5 Strategy Tester HTML reports only. MT4 is not supported yet.
  • Without the bar CSV you get the basic statistics and exit reasons, but not MFE/MAE or regimes.

If you build EAs, I would like to know whether this matches how you debug them, and whether MT4 support would matter to you.

This tool is part of Hawk Backtester, a backtester built around the question of why a rule won or lost. The ideas behind the split are in the guide on MFE and MAE.

Top comments (5)

Collapse
 
arhancanli profile image
Arhan Canli •

Two things I'd check in the MFE/MAE step, since the "in profit first" versus "wrong right away" split depends on them.

First, the entry bar. A trade opened mid-bar sees only the part of that bar's high and low that came after the fill, but a bar-level walk from entry takes the whole bar. On M15 that can credit a trade with a favourable move that happened before it existed, and push a loss into the "exit problem" bucket when it was an entry problem. Do you start the walk at the entry bar's close, or clip it to the entry price?

Second, the stop-size check. The MAE of winners is truncated by the stop you already have: a trade that would have won with a wider stop was stopped out and sits in the losers, so it never shows up in the winners' distribution. "90% of winners never went more than 0.00218 against you" shows the stop is not clearly too wide, but it can't show it is too tight. The only evidence for too tight is losers that later reached the target, which needs bars after the exit. Does the tool look past the exit bar?

With 31 / 30 / 29 trades per bucket, I'd also be careful reading a split from one 136-trade run; resampling the trades would show how far those counts move.

Collapse
 
hawkbtcommander profile image
Tomozo / HAWK Backtester •

Thank you for reading it this closely. You were right about the entry bar, and it was a real bug: a mid-bar entry could be credited with a move that happened before the fill. I've fixed it so only bars fully inside the trade are used, and the entry and exit bars count only the fill prices. MFE now tends to come out slightly low instead, so M1 bars give the best results.

You're also right about the stop check. Winners alone can't show that a stop is too tight, because those trades end up as losers, so I've removed that part. Checking whether stopped-out losers later reached the target is a good suggestion, and I'd like to add it.

I agree that 31 vs 30 is within the noise at this sample size. Thanks again for taking the time to write this up.

Collapse
 
hawkbtcommander profile image
Tomozo / HAWK Backtester • • Edited

Also, I took your point about the sample size and added a resampled range. It reshuffles the losing trades 1,000 times and shows how much each share moves. On the sample that's 27 to 43% for exit problems and 24 to 41% for entry problems, so it now says it can't tell which one is more common.

I've also added the check you suggested, looking past the exit. For each stopped-out trade it checks whether price reached the EA's usual target within the typical winner's holding time, which is where a stop that is too tight would show up. On the sample none of the 90 did, so the stop looks fine there.

Collapse
 
sinarezaei profile image
Sina Rezaei •

One thing Iโ€™d be curious to see in the entry-vs-exit breakdown is how sensitive the classification is to execution costs. For example, a breakout EA on EURUSD M15 might show a decent MFE before closing at a loss, but after spread, commission and slippage, that move may never have been tradable at the reported size.

It could be useful to compare the same trade-level analysis under different cost assumptions, rather than treating the price excursion as the whole story. That would help distinguish an exit rule that genuinely gives back profits from a strategy whose apparent edge disappears once execution costs are included.

Collapse
 
hawkbtcommander profile image
Tomozo / HAWK Backtester •

That's a good point, thank you. The split was using the raw price move, so a loser that was only up by less than the spread and commission still counted as having been in profit. I've added a cost setting, and a move now only counts once it has covered the round-trip cost. On the sample it barely matters at half a pip, but at 3 pips the split shifts clearly toward entry problems, which is the kind of thing you were describing.

Some comments may only be visible to logged-in visitors. Sign in to view all comments.