ROC Momentum EA MT5 — No Code

Build a Rate of Change momentum EA: Length 10, Source Close, EMA smoothing, compare against zero, all five condition types, export MQL5 and backtest.

📖 8 min read

📝 1,529 words

🏷️ MQL5 and Expert Advisors

Share this article:

ROC Momentum EA for MT5 — No Code

The Rate of Change indicator answers one question: is price higher or lower than it was N bars ago, and by what percentage? That makes it one of the simplest momentum rules you can turn into an Expert Advisor — and one of the easiest to get wrong, because the obvious version of the rule trades far too often.

This guide builds a ROC EA in Strategy Builder using the real ROC form, exports MQL5, and then shows why the naive version whipsaws and what to add so it does not.

Theory first, if you need it: ROC indicator guide.

Can I build a ROC EA for MT5 without coding?

Yes. ROC is a registered indicator in Strategy Builder with its own parameter and condition forms. You add it on Step 3, choose a condition type, review the strategy JSON on Step 6, and export MQL5 from Code Generator. You never open MetaEditor to write logic.


Tactix AI on this workflow

AlfaTactix includes Tactix AI: use Tactix Studio to describe your idea in plain language and draft timeframes, signals, filters, and risk into the same six-step Strategy Builder form — or open Tactix Guide on any step when you only need a field explained. Review every value, then export MQL5 or Pine Script from Code Generator (form-first — not untested prompt-to-code).

What the ROC zero line actually tells you

ROC is calculated as:

text
ROC = ((Close[0] - Close[N]) / Close[N]) * 100

So with Length 10 on H1, a ROC of +0.8 means price is 0.8% higher than it was ten hours ago. Three consequences matter for an EA:

  • Zero is the only meaningful fixed level. Above zero, price is higher than N bars ago; below zero, lower. Unlike RSI there is no natural 70/30 — ROC has no bounded range, so "overbought" is symbol-specific.
  • It is normalised, so it travels. Because the output is a percentage, a ROC threshold means roughly the same thing on EURUSD at 1.08 and on XAUUSD at 2400. Momentum, which returns raw price difference, does not have that property.
  • It says nothing about direction of trend, only about change. ROC can be positive while price is in a broad downtrend, if the last N bars happened to be up.

That last point is the whole reason a bare zero-cross EA disappoints, and we come back to it below.

ROC parameters in Strategy Builder

The ROC form exposes exactly these fields:

FieldDefaultRangeWhat it does
Length102-100How many bars back the comparison is made
SourceCloseClose / Open / High / LowWhich price the calculation uses
SmoothingNoneNone / SMA / EMA / WMA / SMMA / VWMAOptional average applied to the ROC line
Smoothing Length101-100Period of that average
Offset0-50 to 50Shifts the plotted line; leave at 0 for signals

Two notes that save a rebuild later:

Keep Source on Close. Using High or Low makes the reading depend on wick extremes, which is noisier and harder to reproduce in a backtest.

Smoothing is the quiet fix for over-trading. Setting Smoothing to EMA with Smoothing Length 5 removes a large share of the tiny zero-line flickers without pushing entries as late as a longer Length would. It costs you nothing at export time.

Leave Offset at 0. A non-zero offset shifts the line for visual comparison and will misalign your signal against the bar it was generated on.

ROC condition types explained

ROC supports five condition types. They are not interchangeable, and the right choice is the main decision in this build:

compare — Operator (>, <, >=, <=, ==, !=) and a Value. This is the zero-cross rule: ROC > 0 for buy, ROC < 0 for sell. Simplest, and the most signals.

breakout — Direction (Up / Down), Threshold, Period, Confirmation. Fires when ROC pushes through a threshold rather than merely sitting on the right side of it. Confirmation is the useful field: setting it to 2 requires the condition to hold for two bars before the signal counts.

slope — Direction, Period, Min Slope, plus its own Smoothing and Source. This asks whether ROC is rising, not whether it is positive. Momentum accelerating from -1.5 to -0.5 is still negative, and slope catches it while compare does not.

divergence — Divergence Type (Bullish / Bearish), Period, Lookback Period, Strength, Timeframe. Price makes a new low, ROC does not. Powerful and harder to test honestly; treat it as a second iteration, not your first EA.

pattern — chart-pattern detection (double top/bottom, head & shoulders, triangle, wedge). Available, but a pattern condition on a momentum oscillator is an unusual combination; skip it while you are learning the tool.

For a first build use compare. It is the rule most people mean by "ROC EA", and its weaknesses are instructive.

Build the ROC EA step by step

Step 1 — Strategy Info. Name: ROC Momentum H1 EURUSD. Give it a name you will still recognise after ten variations; the Strategy Tester report only shows the name.

Step 2 — Timeframes. H1 for a first build. ROC on M1 or M5 produces a signal count that is dominated by spread rather than momentum.

Step 3 — Entry Signals. Add ROC. Parameters: Length 10, Source Close, Smoothing EMA, Smoothing Length 5, Offset 0.

  • Buy condition: type compare, Operator >, Value 0
  • Sell condition: type compare, Operator <, Value 0

Step 4 — Market Filters. Add a spread filter. Momentum entries cluster around the moments when spread widens, and an EA that ignores spread will show a backtest that live trading does not reproduce. A session filter helps too — see market filters.

Step 5 — Risk Management. Fixed fractional sizing, one stop, one target. An ATR-based stop suits ROC better than a fixed pip stop, because ROC signals arrive in both quiet and volatile conditions; see ATR and EA risk management.

Step 6 — Summary. Read the JSON. Confirm the buy condition says operator > against value 0 and the sell says <. This is the step where a mis-set condition is cheap to fix; after export it is not.

Export, compile and backtest

Open Code Generator, select MQL5, export, and drop the .mq5 file into MQL5/Experts. Compile in MetaEditor (F7) — the generated code is standard MQL5 and should compile without edits. If it does not, see common MQL5 EA errors.

In the Strategy Tester use Every tick modelling for the first run. "Open prices only" will make almost any momentum EA look better than it is, because it hides the intrabar path. Full guide: backtest an EA in the MT5 Strategy Tester.

Expect a high trade count and an unimpressive equity curve. That is the correct result for this configuration, and the next section is why.

Why a raw zero cross whipsaws

ROC oscillates around zero, and in a ranging market it crosses zero repeatedly without price going anywhere. Each crossing is a signal, each signal is a spread payment, and the strategy pays the spread far more often than it captures a move.

The specific failure is that zero-cross frequency is highest exactly when the move size is smallest. In a strong trend ROC stays on one side for a long time and produces few signals; in a chop it crosses constantly. So the rule generates its heaviest trading in the conditions least able to pay for it.

Three ways to address it, in order of how much they usually help:

  1. Require distance from zero, not just sign. Switch to the breakout condition with Threshold 0.5 and Confirmation 2. You enter later and less often, and skip the cluster of signals that live right on the zero line.
  2. Add a trend filter so ROC only trades with the larger move. Add an EMA on Step 3 and accept buys only while price is above it. This directly fixes the "ROC is positive inside a downtrend" problem from earlier.
  3. Use slope instead of level. The slope condition with Direction Up asks whether momentum is building, which fires earlier in a turn and is less tied to the zero line.

Test these one at a time. Changing three things at once and seeing a better curve tells you nothing about which change earned it.

Filters and risk controls

Momentum rules are unusually sensitive to execution cost, so the filters matter more here than in a slower strategy:

  • Spread — non-negotiable for this strategy, as above.
  • Session — ROC on FX behaves differently in the London and Asian sessions; restricting to one makes results far more interpretable. See time and session filters.
  • Volatility regime — an ATR condition keeps the EA out of dead markets where the zero line is crossed by noise alone.
  • News — momentum entries and scheduled releases overlap badly; see news filter.

On risk: size from account percentage rather than fixed lots, and let the stop come from ATR rather than a round pip number. A strategy with many small trades is dominated by cost and sizing, not by signal quality.

Next steps

Run the plain compare version first so you have a baseline, then add one filter at a time and compare in the Strategy Tester. Related builds worth reading next:

Building the same idea for TradingView instead? The same six steps produce Pine Script v6 from Code Generator.

Frequently Asked Questions

Yes. Add ROC on Step 3 in Strategy Builder, use the compare condition with Operator > and Value 0 for buy and Operator < with Value 0 for sell, set Length 10 and Source Close, then export MQL5 from Code Generator and backtest in the MT5 Strategy Tester with Every tick.

Length 10 is the common default and is what the builder starts with. Shorter lengths (5-9) react sooner and produce more signals and more false ones; longer lengths (14-21) lag more but survive noise better. Pick the length in the Strategy Tester on your own symbol and timeframe rather than copying a number.

They measure the same thing differently. Momentum is the price difference over N bars; ROC expresses that difference as a percentage of the older price. Because ROC is normalised it is comparable across symbols and across price levels, which is why it travels better between instruments.

Zero is the neutral line — above it price is higher than N bars ago. Requiring a threshold away from zero (for example the breakout condition with Threshold 0.5) filters out the small oscillations around zero that cause most of the false entries, at the cost of entering later.

Code Generator emits standard MQL5, so the ROC buffer comes from iCustom or an inline calculation depending on the configuration, read with CopyBuffer on the previous closed bar. You do not write or edit this — you review the JSON on Step 6 and export.

Yes, and it is usually the difference between a demo-only EA and one worth testing. Add a moving average on Step 3 and only take ROC buy signals while price is above it, or use Step 4 market filters for session and spread. See the filters section below.