Build a Moving Average Crossover EA for MT5 — No Code
Quick Answer: MA Crossover EA Without Code
Quick answer: Add SMA (or EMA) on Step 3 — Signals in AlfaTactix Strategy Builder, set Golden Cross for Buy and Death Cross for Sell, choose Period 10 (fast MA 10, slow MA 20 automatically), add Stop Loss / lot size on Step 5, Save, export MQL5 from Code Generator, compile once in MetaEditor, and backtest on H1 EURUSD with Every tick in the Strategy Tester.
Disclosure: This tutorial uses AlfaTactix Strategy Builder. For the same strategy written in MQL5 by hand (EMA 20/50), see Build Your First EA — MA Crossover. For the full no-code platform overview, see Build EA Without Coding.
Related guides: Create/Edit MT5 EA · EA Risk Management · Backtest in Strategy Tester
What Is a Moving Average Crossover EA?
A moving average crossover Expert Advisor automates one of the oldest rule-based systems in trading:
| Signal | Rule |
|---|---|
| Buy (long) | Fast MA crosses above slow MA — Golden Cross |
| Sell (short) | Fast MA crosses below slow MA — Death Cross |
The EA runs on every tick or bar in MetaTrader 5 via OnTick(). You do not need to watch charts manually — the platform executes when the cross fires.
Why traders search for this: It is the most common “first EA” strategy. Most tutorials show MQL5 code only. This guide shows the same logic in Strategy Builder with every parameter and condition the product exposes for SMA and EMA.
Classic Settings and When It Works
| Setting | Starter value | Notes |
|---|---|---|
| MA type | SMA 10 / 20 or EMA 20 / 50 | Builder Golden Cross: one Period; slow = Period × 2 |
| Timeframe | H1 (forex majors) | M15 = more signals; H4 = fewer, cleaner trends |
| Symbol | EURUSD, GBPUSD | Lower spread helps any MA system |
| Confirmation | 1 bar (default) | 2–3 bars reduces whipsaw in ranges |
Works best: Trending markets and liquid sessions (London / New York).
Struggles in: Tight ranges — fast MA crosses back and forth. Mitigate with Step 4 spread/session filters or Step 5 stop loss.
SMA and EMA Parameters in Strategy Builder
When you add SMA or EMA on Step 3 — Signals, the Parameters panel shows three fields (same for both indicators):
| Parameter | Type | Range / options | Default | What it does |
|---|---|---|---|---|
| Length | Number | 2 – 200 | 20 | Lookback periods for the MA line attached to this indicator instance |
| Source | Select | Close, Open, High, Low | Close | Price series used in the calculation |
| Offset | Number | -500 – 500 | 0 | Shifts the MA forward/backward in bars (advanced; leave 0 for crossover EAs) |
Tip for crossover EAs: Set Length equal to your Golden Cross / Death Cross Period (e.g. Length 10 + Golden Cross Period 10) so the plotted MA matches the fast line used in the cross condition.
SMA and EMA Condition Types Explained
Open an indicator on Step 3 → Add condition. The dropdown lists seven condition types for both SMA and EMA. Below is every field the UI exposes.
1. Compare
Compare the MA value to a fixed number (or current price when value is empty/zero).
| Field | SMA | EMA |
|---|---|---|
| Operator | >, <, >=, <=, = | >, <, >=, <=, ==, != |
| Value | Number | Number |
Value helper text: Leave 0 or empty to compare with current Close. Or enter a fixed price (e.g. 1.0850 on EURUSD).
Use case: “Only buy when EMA(20) > 1.0800” or “SMA above yesterday’s level.”
2. Crossover
Detect when the MA crosses a target (price or another MA type).
| Field | Options |
|---|---|
| Target | Price, EMA, SMA, WMA — EMA also: VWAP |
| Direction | Above (bullish cross) · Below (bearish cross) |
| Length | Shown when Target = EMA/SMA/WMA/VWAP — period 1–200 (default 50) |
| Price Value | Shown when Target = Price — empty = current Close; or fixed price |
Use case: “SMA(20) crosses above price” or “EMA crosses below SMA(50).”
Note: For a classic two-MA crossover EA, Golden Cross / Death Cross (below) is simpler than wiring two separate crossover conditions.
3. Golden Cross (buy signal)
Fast MA crosses above slow MA.
| Field | Range | Default | Meaning |
|---|---|---|---|
| Period | 1 – 100 | 10 | Fast MA period |
| Confirmation | 1 – 10 bars | 1 | Bars to confirm the cross |
Important (product behaviour): When you set Period = 10, the builder stores Fast = 10 and Slow = 20 (slow is Period × 2). Example UI hint: “Fast SMA period (Slow will be period×2). Example: 10 → SMA(10) crosses SMA(20).”
On EMA, the hint reads “Fast EMA period (Slow will be period×2).”
For a 25/50 style cross: set Period = 25 → fast 25, slow 50.
4. Death Cross (sell signal)
Fast MA crosses below slow MA. Same fields as Golden Cross (Period, Confirmation).
Use on the Sell tab in Step 3 for a symmetric long/short EA, or only on Buy and manage exits in Step 5.
5. Breakout
Price breaks through a level relative to the MA context.
| Field | Range / options |
|---|---|
| Direction | Up · Down |
| Threshold | Price level (e.g. 1.0850) |
| Period | Lookback 1 – 100 bars (default 10) |
| Confirmation | 1 – 10 bars |
Use case: Breakout systems combined with MA trend filter (add as a second condition with AND).
6. Slope
Require the MA to be rising or falling by a minimum amount.
| Field | SMA | EMA |
|---|---|---|
| Direction | Up · Down | Rising · Falling |
| Period | 1 – 100 (compare current vs N bars ago) | Same |
| Min Slope | Number (0 = any slope) | Min Slope (default 0.001 on EMA) |
| Smoothing | None, SMA, EMA, WMA | Same |
| Smoothing Length | 1 – 100 (if smoothing ≠ None) | Same (EMA default 14 when enabled) |
| Source | Close, Open, High, Low | Same |
Use case: “Buy Golden Cross only if SMA slope is Up” — combine conditions with AND in Step 3.
7. Pattern
Chart pattern detection on the MA series.
| Field | SMA options | EMA options |
|---|---|---|
| Pattern Type | Double Top, Double Bottom, Head & Shoulders, Inverse H&S | Same + Triangle, Wedge |
| Min Height | Number (e.g. 0.0050 = 50 pips on EURUSD) | Same |
| Min Width | Bars 1 – 100 (typical 5–10) | Same |
| Volume Confirmation | None · Above Average · High | Same |
Use case: Advanced entries; most MA crossover EAs use Golden/Death Cross only.
Logical combinations on Step 3
You can combine indicators and conditions with AND, OR, NOT, parentheses, and groups — same as described in Build EA Without Coding. Example: (Golden Cross AND Slope Up).
Build the Crossover EA Step by Step
Workflow: six steps in Strategy Builder demo. We only detail what matters for SMA 10/20 crossover.
Step 1 — Strategy information
- Name: e.g.
MA Crossover H1 EURUSD - Description: optional
Step 2 — Timeframes
- Enable one trading timeframe, e.g. H1 (matches tab tf0 on Step 3).
- Optional: add a higher timeframe later for trend filter (Advanced MTF Filters).
Step 3 — Signals (core)
- Open tab Buy.
- Select timeframe H1.
- Add indicator → SMA (Trend group).
- Parameters: Length 10, Source Close, Offset 0.
- Add condition → Golden Cross.
- Period: 10 (slow MA 20 auto)
- Confirmation: 1
- Open tab Sell.
- Add SMA again (or mirror rule): Death Cross, Period 10, Confirmation 1.
Alternative — EMA: Add EMA, Length 25, condition Golden Cross Period 25 (→ 25/50 cross). Keep Length and Period aligned.
Step 4 — Filters (optional)
Examples: market session (London/NY), spread cap, ATR filter. See Advanced EA MTF & Filters.
Step 5 — Risk management
Minimum for a testable EA:
| Setting | Suggestion |
|---|---|
| Lot / risk % | 0.01 lot demo or 1% risk |
| Stop Loss | Fixed pips or ATR-based |
| Take Profit | Optional; many cross EAs exit on opposite cross |
| One trade at a time | Avoid overlapping positions |
Full reference: EA Risk Management.
Step 6 — Preview and Save
Review Buy/Sell rules → Save strategy to your account.
Export, Compile, and Backtest
- Open Code Generator → select your saved strategy → MQL5 → download
.mq5. - Copy to
MQL5/Experts, compile (F7) in MetaEditor. - Strategy Tester: Every tick, realistic spread, 6–12 months data.
- Forward test on Demo before live. Read Strategy Tester vs Live.
If OrderSend fails with 10016, see Invalid Stops.
Improvements: Filters and Risk
| Problem | Builder lever |
|---|---|
| Whipsaw in range | Confirmation 2–3; Step 4 session filter |
| Spread eats profit | Step 4 spread filter; test on ECN/low-spread symbol |
| Over-trading | Step 5 max trades; one position per symbol |
| Trend only | Step 3 add Slope Up AND Golden Cross |
Next Steps
- Build Your First EA (hand-coded MA crossover) — EMA 20/50 MQL5 walkthrough
- Build EA Without Coding — full six-step builder tour
- Production-Ready MQL5 Without MetaEditor — export workflow
- Scalping EA (M1 MA example) — faster timeframe variant
Try it: Strategy Builder demo — build the SMA 10/20 Golden Cross EA in one session, export, and backtest.
References: MQL5 iMA, MetaTrader 5 Strategy Tester.