How to Develop an EA That Survives Outside the Strategy Tester

30 July 2026, 20:16
Robert Seamans
0
41
Developing an Expert Advisor is not mainly about converting an entry signal into MQL5 code. The hard part is creating a complete system that still behaves sensibly when spreads widen, execution is delayed, volatility changes, or the EA is moved to another broker.

Here is a practical development process for MT5 EAs.

1. DEFINE THE STRATEGY BEFORE CODING

Write exact rules for:
• Long and short entries
• Signal timing: current tick, new bar, or closed bar
• Stop Loss and Take Profit
• Position sizing
• Exit and invalidation conditions
• Conditions that forbid trading

If two developers could interpret a rule differently, it is not ready to automate.

2. SEPARATE THE EA INTO MODULES

Avoid putting everything inside OnTick(). Keep signal generation, market filters, sizing, execution, position management, and safety checks separate.

A simple control flow is:

Manage open positions
→ Check for a new decision event
→ Validate market conditions
→ Evaluate the signal
→ Calculate volume
→ Execute and log the result

This makes bugs easier to isolate and prevents changes in one component from silently affecting another.

3. TREAT EXECUTION AS PART OF THE STRATEGY

Before sending an order, check the current bid/ask, spread, volume limits, volume step, stop level, freeze level, available margin, and whether trading is allowed.

Never assume that every symbol has the same digits, tick value, contract size, or minimum lot. Read these properties through SymbolInfoDouble() and SymbolInfoInteger(). This is essential when supporting Forex, metals, and indices.

4. BUILD POSITION SIZING AROUND ACTUAL RISK

Start with:

Risk money = account equity × risk percentage

Then calculate volume from the actual Stop Loss distance, tick size, and tick value. Normalize the result to the broker's permitted volume step and cap it within the minimum and maximum volume.

If a required symbol property is invalid, skip the trade. Do not substitute an arbitrary lot size. A fixed-lot option is also useful for testing because it separates strategy behavior from compounding.

5. PREVENT DUPLICATE TRADES

OnTick() may execute many times during one candle. Depending on the strategy, use a new-bar check, last-traded-bar record, Magic Number, cooldown period, and existing-position/order checks.

A bar-close strategy normally should not submit several orders from the same candle. A true tick strategy needs different protection, but it still needs protection.

6. TEST THE WEAKEST ASSUMPTIONS

An attractive optimization result is not validation. A better sequence is:

• Use real ticks when possible
• Include realistic spread and commission
• Compare normal execution with random delay
• Reserve a later period that was not used to select settings
• Test neighboring parameter values
• Test different market regimes
• Repeat with the intended broker's specifications
• Run on demo before considering live use

For M1 systems, costs and latency can materially change the outcome. A broad stable parameter region is usually more credible than one isolated “perfect” combination.

7. DESIGN FOR LIVE OPERATION

A finished EA should handle terminal restarts, connection interruptions, rejected orders, positions already open at startup, invalid inputs, manual trades on the account, and netting versus hedging behavior.

It should also explain what it is doing. Messages such as “entry rejected: spread 35 > maximum 20” are far more useful than an EA that silently refuses to trade.

FINAL CHECKLIST

Before calling an EA finished, ask:
• Are the rules unambiguous?
• Are broker specifications read dynamically?
• Can one signal create duplicate orders?
• Are costs and delay included in testing?
• Is there a genuinely unseen forward period?
• Does the EA fail safely?
• Can the user understand why it acted or did not act?

HOW I APPLIED THIS PROCESS

I used this general approach while developing ApexFlow Universal EA, a fully automated MT5 system for short-term M1 trading. It evaluates price behavior, momentum, volatility, and current market conditions, then manages the trade from entry through exit. It supports long and short trading, fixed-lot or adjustable risk-based sizing, Stop Loss and Take Profit management, and market-condition filters.

Because broker conditions differ, every symbol should be tested separately. A free Strategy Tester demo is available here:


Start with default inputs, conservative sizing, realistic costs, random-delay testing, and an unseen forward period. Backtests are simulations—not guarantees of future performance.