2,056 Strategy Tester runs: what survived, and the midnight bar trap

2,056 Strategy Tester runs: what survived, and the midnight bar trap

27 November 2026, 17:47
Anshaal Rehman
0
6

Over the last weeks I ran 2,056 backtests in the MetaTrader 5 Strategy Tester. The setup: 14 different indicator signals (moving average cross, RSI reversal, MACD divergence, Donchian, VWAP, Market Profile, Heikin Ashi, Supertrend, Bollinger squeeze, TD Sequential and more), 9 markets (XAUUSD, USDJPY, GBPJPY, EURJPY, EURUSD, GBPUSD, BTCUSD, US30, USTEC), H4 and H1, and three test windows: 2021-2025, 2023-2024 and 2024-2025. Every trade used a $10,000 deposit and a fixed risk per trade. The entry was always the indicator's own closed-bar signal, so only the exit rule changed.

Here are the five results I did not expect, plus the traps I hit when I turned the survivors into Expert Advisors. All numbers are past backtest results, not a forecast.

1. Most indicator signals lose money on their own

Of the 1,495 H4 runs, only 39% ended in profit, and the median profit factor was below 1.0. These were not bad indicators. They are popular, reasonable tools. An arrow on a chart is a description of what price did, not an edge by itself. If a signal has not been tested on your market and timeframe with fixed exit rules, you do not know yet whether it makes or loses money.

2. Tight stops were the worst exit rule

Same signals, four exit rules. A stop of 1 x ATR(14) with a 1.5R target ended in profit in only 30% of runs. Wider stops (1.5 to 2.5 x ATR) were profitable in 41-43% of runs, with lower median drawdown. With H4 entries on closed bars, a 1-ATR stop sits inside normal noise and gets hit before the idea has time to work.

Share of profitable runs by exit rule

3. A good 5-year backtest is not enough

I counted every combination of indicator, market and exit rule that was tested in all three windows: 487. Of those, 25 reached a profit factor of 1.2 or higher over the full 5 years. Only 21 of the 25 were still profitable in both 2-year windows, and only 9 kept a profit factor of 1.2 or higher in every window. So about 2% of what I tested passed a simple robustness check.

The test is cheap and you can run it today: take your settings, run 2021-2025, then run 2023-2024 and 2024-2025 separately without changing anything. If one window is flat or negative, the long result was carried by one lucky stretch.

How many settings survive a three-window test

4. The midnight bar trap: why your backtest may not match live trading

This one cost me a day. On FX pairs, many brokers have a short trading break at server midnight (the daily rollover). In the tester, the first tick of the new H4 or H1 bar at 00:00 often falls inside that break. An EA that opens a trade on a new bar gets the order rejected with retcode 10018 (TRADE_RETCODE_MARKET_CLOSED), and the backtest silently skips that signal.

Live, the first tick of the midnight bar arrives a minute later, after the market has reopened, so the same EA does take that trade. Your backtest and your live account are then trading two different strategies. When I made the EA wait for the market to open and trade those signals, results got much worse on every FX pair I tested. Skipping the midnight-bar signal on purpose brought them back. Spreads are at their widest in those minutes, which explains it.

Midnight bar signals traded vs skipped

Whatever you choose, choose it in code, so the tester and live trading behave the same. Two checks I now use:

// 1) only trade when the symbol's trading session is open bool MarketOpen() { MqlDateTime t; TimeToStruct(TimeCurrent(), t); uint now = (uint)(t.hour * 3600 + t.min * 60 + t.sec); datetime from, to; for(uint i = 0; i < 10 && SymbolInfoSessionTrade(_Symbol, (ENUM_DAY_OF_WEEK)t.day_of_week, i, from, to); i++) if(now >= (uint)from && now < (uint)to) return true; return false; } // 2) explicit rollover rule: drop the signal of the bar that opens at midnight (intraday charts only) MqlDateTime b; TimeToStruct(iTime(_Symbol, _Period, 0), b); bool rolloverBar = _Period < PERIOD_D1 && b.hour == 0 && b.min == 0;

Gold (XAUUSD) results did not change in my tests, so this is not universal. Check your own symbol's session times in the Specification window.

5. Half the risk is not half the profit

One moving average cross setup on USDJPY H1 made +1,743% over 2021-2025 at 2% risk per trade, with a 33% maximum drawdown. At 1% risk it made +387% with an 18% drawdown. Drawdown roughly halves, but the profit falls by about 4.5 times, because returns compound. Backtest headlines with huge numbers are often just high risk. Compare strategies at the same risk, and look at drawdown first.

Profit and drawdown at 2% and 1% risk

For EA developers: five traps from the Market validator and the tester

  • Freeze level. Closing or modifying a position whose stop or target is inside the freeze level fails with "Modification failed due to order or position being close to market". The automatic check uses large freeze levels. Check SYMBOL_TRADE_FREEZE_LEVEL before PositionClose and PositionModify, and let the stop or target do the work when you are inside it.
  • Minimum lot on small deposits. With a small deposit and a wide stop (for example XAUUSD D1), the minimum lot can risk far more than your risk setting and the test ends in a stop out. Calculate the real loss at the stop with OrderCalcProfit and skip the trade if even the minimum lot is too large for the balance.
  • MT4 tester and MODE_TRADEALLOWED. In my MT4 tester, MarketInfo(_Symbol, MODE_TRADEALLOWED) returned 0, so an EA that checks it never trades in a backtest. Only check it when IsTesting() is false.
  • MT4 history depth. MT4 brokers often send only about 2,048 bars per timeframe, so a 2025 test on H1 may have no data at all ("no history data" in the journal). Test MT4 builds on recent dates.
  • Buffer numbers can differ between MT4 and MT5. If your EA reads an indicator with iCustom, the signal buffer index can be different in the two versions, for example when MT5 uses a color index buffer. Read the index per platform instead of assuming they match.

Checklist

  • Test the signal with fixed exits before trusting it.
  • Start with stops of 1.5 to 2.5 x ATR on H1 and H4, not 1 x ATR.
  • Use the three-window test: full period, then two shorter periods with the same settings.
  • Decide in code what happens to signals at the daily rollover.
  • Compare strategies at the same risk, and read drawdown before profit.

If you have run similar tests on other markets, I would like to compare notes in the comments.