Core MT4 Automation Building Blocks
MT4 robots (EAs) run primarily through OnInit(), OnDeinit(), and OnTick() event handlers. A production-grade EA typically separates logic into independent modules:
- Signal Engine: calculates entries/exits (indicators, patterns, regime detection).
- Risk Engine: position sizing, daily loss lock, max drawdown guard, exposure caps.
- Execution Layer: robust OrderSend()/OrderModify() flow, retries, slippage rules.
- Trade Manager: trailing stops, break-even, partial closes, scaling in/out.
- Filters: time/session windows, news blocks, spread/volatility constraints.
- State + Logging: trade state machine, persistent variables, debug modes.
Complex Strategy Automation (Real Examples)
“Complex” means the EA must survive real market conditions (spread spikes, gaps, requotes, partial fills) while enforcing strict risk rules. Common advanced components include:
- Multi-timeframe confirmation: e.g., H1 trend filter + M15 entry + M5 trigger alignment.
- Breakout logic: Donchian/ATR channels, range compression detection, session opens (London/NY).
- Mean reversion systems: Bollinger/Keltner bands, z-score, volatility contraction/expansion regimes.
- Market structure: swing high/low, BOS/CHOCH style rules, fractal pivots, liquidity sweeps.
- Basket/correlation filters: exposure control across correlated pairs (EURUSD vs GBPUSD, etc.).
- Adaptive stops & targets: ATR-based stops, volatility-scaled trailing, time-based exits.
- News/session filters: hard blocks, “no-trade minutes”, spread/volume guards.
Note: we can implement grid/martingale mechanics as code, but we strongly recommend professional constraints like max levels, equity stops, and strict drawdown locks for safety.
Custom Indicators We Commonly Automate
MT4 indicator work includes both “classic” studies and custom price-action tools:
Classic / Quant Indicators
- RSI, Stochastic, MACD, ADX, CCI
- Bollinger Bands, Keltner Channels, Donchian Channels
- ATR/StdDev volatility filters, VWAP (custom session VWAP)
- Ichimoku, SuperTrend, Heiken Ashi (custom smoothing)
Price Action / Structure Tools
- Swing/pivot detectors (ZigZag variants, fractal logic)
- Support/Resistance & supply/demand zone mapping
- Order blocks / imbalance markers (rule-based definitions)
- Session boxes (Asia range, London breakout levels)
Money Management & Risk Engines
The difference between “a bot” and “a tradable system” is usually the risk engine. Examples we implement:
- Fixed fractional sizing: risk X% per trade using stop distance + pip value math.
- ATR-based sizing: volatility-aware sizing where lot size adapts to ATR stop distance.
- Daily loss lock: stop trading after -$X or -Y% (prop-firm style).
- Equity guardrails: max drawdown cutoff, max open risk, max exposure per currency.
- Scaling rules: partial take profits, trailing by structure/ATR, anti-martingale pyramiding.
- Trade limits: max trades/day, cooldown after loss, skip after spread spikes.
Execution Quality: Handling MT4 Realities
MT4 execution can involve requotes, slippage, and broker constraints. Production-grade code typically includes:
- Slippage policies and spread filters (avoid trading during bad conditions).
- Retry & error handling for common trade errors (requotes, trade context busy).
- Magic number + comment tagging to isolate the EA’s positions reliably.
- Order normalization (digits, lot step, min/max volume).
- Break-even / trailing that does not spam OrderModify() on every tick.
Need a Technical MT4 EA Built from Your Rules?
Share your entry/exit rules, risk limits, and target broker constraints. We’ll translate them into clean, maintainable MQL4 code.
Request a Quote