Expert Advisors • Indicators • Scripts • Libraries

MQL.RobotFX.org is the biggest collection of MetaTrader expert advisors (MT5 & MT4), indicators, scripts and libraries that can be used to improve trading results, minimize risks or simply automate trading tasks

Metatrader 5 Expert Advisor | Restart-Safe EA Template - no duplicate entries after a restart | MetaTrader …

RobotFX curates the best open-source MetaTrader code to inspire your trading automation.

Restart-Safe EA Template is a clean Expert Advisor skeleton that shows execution practices many EAs miss. The most common problem it solves: after MetaTrader or the VPS restarts, the EA sees the same signal again and opens a duplicate trade.

  • Signals are evaluated only on closed bars and only once per bar.
  • The last processed bar is stored in a terminal global variable, so a restart never repeats a signal.
  • One position per symbol and magic number, recognised again after a restart.
  • Spread filter, broker stop-level check and volume normalisation.
  • Every decision (entry sent, signal skipped and why, broker retcode) is written to the Experts log.

The included signal is a simple moving-average cross for demonstration only: replace the GetSignal() function with your own rules. This is an educational template, not a profitable strategy. Suggested for testing: EURUSD M15.

Inputs

Smooth out market noise with the Heiken Ashi Expert Advisor for MT4 and MT5. Reliable trend-following automation. Details here.

  • Fast and slow MA periods and MA method (demo signal).
  • Lot size, stop loss and take profit in points (0 = none).
  • Maximum spread in points, magic number and maximum deviation.

Screenshot: Experts log in the Strategy Tester showing entries and skipped signals with their reason.

Image for Restart-Safe EA Template - no duplicate entries after a restart

Level up your trading with professional RobotFX expert advisors and indicators. Visit robotfx.org for proven MT4/MT5 tools.

78715

Best MetaTrader Indicators + Profitable Expert Advisors