On this page
Back to tutorials

Build a Moving Average Crossover EA for MT5 — No Code

Step-by-step Strategy Builder guide: SMA/EMA parameters, Golden Cross & Death Cross, export MQL5, compile, and backtest a classic MA crossover EA.

📖 16 min read

📝 3,200 words

🏷️ MQL5 & Expert Advisors

Share this article:

Want to build a no-code strategy right now?

Create your free account in seconds and start building immediately.


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:

SignalRule
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

SettingStarter valueNotes
MA typeSMA 10 / 20 or EMA 20 / 50Builder Golden Cross: one Period; slow = Period × 2
TimeframeH1 (forex majors)M15 = more signals; H4 = fewer, cleaner trends
SymbolEURUSD, GBPUSDLower spread helps any MA system
Confirmation1 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):

ParameterTypeRange / optionsDefaultWhat it does
LengthNumber2 – 20020Lookback periods for the MA line attached to this indicator instance
SourceSelectClose, Open, High, LowClosePrice series used in the calculation
OffsetNumber-500 – 5000Shifts 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).

FieldSMAEMA
Operator>, <, >=, <=, =>, <, >=, <=, ==, !=
ValueNumberNumber

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).

FieldOptions
TargetPrice, EMA, SMA, WMA — EMA also: VWAP
DirectionAbove (bullish cross) · Below (bearish cross)
LengthShown when Target = EMA/SMA/WMA/VWAP — period 1–200 (default 50)
Price ValueShown 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.

FieldRangeDefaultMeaning
Period1 – 10010Fast MA period
Confirmation1 – 10 bars1Bars 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.

FieldRange / options
DirectionUp · Down
ThresholdPrice level (e.g. 1.0850)
PeriodLookback 1 – 100 bars (default 10)
Confirmation1 – 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.

FieldSMAEMA
DirectionUp · DownRising · Falling
Period1 – 100 (compare current vs N bars ago)Same
Min SlopeNumber (0 = any slope)Min Slope (default 0.001 on EMA)
SmoothingNone, SMA, EMA, WMASame
Smoothing Length1 – 100 (if smoothing ≠ None)Same (EMA default 14 when enabled)
SourceClose, Open, High, LowSame

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.

FieldSMA optionsEMA options
Pattern TypeDouble Top, Double Bottom, Head & Shoulders, Inverse H&SSame + Triangle, Wedge
Min HeightNumber (e.g. 0.0050 = 50 pips on EURUSD)Same
Min WidthBars 1 – 100 (typical 5–10)Same
Volume ConfirmationNone · Above Average · HighSame

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)

  1. Open tab Buy.
  2. Select timeframe H1.
  3. Add indicatorSMA (Trend group).
  4. Parameters: Length 10, Source Close, Offset 0.
  5. Add conditionGolden Cross.
    • Period: 10 (slow MA 20 auto)
    • Confirmation: 1
  6. Open tab Sell.
  7. 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:

SettingSuggestion
Lot / risk %0.01 lot demo or 1% risk
Stop LossFixed pips or ATR-based
Take ProfitOptional; many cross EAs exit on opposite cross
One trade at a timeAvoid 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

  1. Open Code Generator → select your saved strategy → MQL5 → download .mq5.
  2. Copy to MQL5/Experts, compile (F7) in MetaEditor.
  3. Strategy Tester: Every tick, realistic spread, 6–12 months data.
  4. Forward test on Demo before live. Read Strategy Tester vs Live.

If OrderSend fails with 10016, see Invalid Stops.


Improvements: Filters and Risk

ProblemBuilder lever
Whipsaw in rangeConfirmation 2–3; Step 4 session filter
Spread eats profitStep 4 spread filter; test on ECN/low-spread symbol
Over-tradingStep 5 max trades; one position per symbol
Trend onlyStep 3 add Slope Up AND Golden Cross

Next Steps

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.

Build your no-code trading strategy now — free

Create your account and start building a complete no-code strategy right now. Add indicators, filters, and risk rules, then export MQL5 in minutes.

Frequently Asked Questions

Yes. In AlfaTactix Strategy Builder, add SMA or EMA on Step 3 (Signals), choose Golden Cross for buy and Death Cross for sell, set risk on Step 5, save, then export MQL5 from Code Generator. Compile once in MetaEditor and backtest in Strategy Tester.

Common starters: SMA or EMA 10/20 (fast/slow) on H1 for forex majors, or 20/50 for slower trends. In Strategy Builder, Golden Cross uses one Period field — slow length is Period × 2 (e.g. Period 10 → 10/20). For hand-coded EMA 20/50 see Build Your First EA.

Golden Cross: fast MA crosses above slow MA (bullish entry). Death Cross: fast crosses below slow (bearish entry). Each has Period (fast; slow = Period×2) and Confirmation (1–10 bars). UI labels: Golden Cross / Death Cross in the condition dropdown.

EMA reacts faster to recent price (common in tutorials). SMA is smoother. For the no-code Golden Cross condition, we recommend SMA first so fast and slow lines both use the same MA type in export. EMA works too — set indicator Length to match your Golden Cross Period.

You export .mq5 from Code Generator and compile once (F7) per MetaEditor help. You do not write crossover logic by hand — see Production-Ready MQL5 Without MetaEditor.

Add Step 4 filters (session, spread) or Step 5 stop loss / trailing stop. Use Confirmation 2–3 on Golden/Death Cross. Read Strategy Tester vs Live before going live.

Build your no-code strategy now — free

Create Free Account