Exponential Moving Average Indicator for MT4 and MT5

Written by Dominic Walsh · Published · Last updated

The exponential moving average gives recent prices more weight than old ones. The exponential moving average indicator draws a 21-bar EMA of the close and colours it by slope: green while it rises, red while it falls. A popup names each change of slope.

This build ships as a compiled .ex4 for MT4 and .ex5 for MT5; the screenshots below come from EURUSD H1.

Platforms MT4 (.ex4) + MT5 (.ex5)
Chart window Main price chart
Plots 3: EMA, EMA Rising, EMA Falling
Alerts popup
Inputs 3

Drawn output, plot by plot

One two-colour line on price.

`EMA` traces silver as the reference line.

`EMA Rising` overlays lime at width 2.

`EMA Falling` overlays red at width 2.

No marks are drawn.

`EmaShift` can move the line sideways.

  • EMA: line, silver, width 1
  • EMA Rising: line, lime, width 2
  • EMA Falling: line, red, width 2
exponential moving average indicator: 21-bar EMA coloured by slope, EURUSD H1.
21-bar EMA coloured by slope, EURUSD H1.

How it builds its numbers

Weighting

`EmaPeriod` `21` sets the weight on the newest close, 2 divided by 22, about nine percent. Older closes fade gradually.

Colour

Each bar compares the EMA with the bar before. Rising segments turn lime, falling ones red.

Flip popup

With `AlertOnFlip` on, a popup fires when the slope on the last closed bar differs from the bar before.

How to follow it

Lime means the average is rising.

Red means it is falling.

Colour flips come before crossovers.

Price far from the line is stretched.

`EmaShift` `0` keeps the line aligned.

Warm-up needs about twenty bars.

Alert channels in this build: popup, one message per closed bar.

Slope flips raise a popup naming the new direction. `AlertOnFlip` switches it on or off; there are no other routes.

Every Exponential Moving Average Indicator input

Core settings

Setting What it does Default
EmaPeriod EMA period. Average length, `21`. 21
EmaShift Horizontal shift (bars). Sideways shift in bars, `0`. 0

Alert settings

Setting What it does Default
AlertOnFlip Alert on slope flip. Popup on slope flips, `true`. on
exponential moving average indicator: Inputs panel, period, shift and the flip popup.
Inputs panel, period, shift and the flip popup.

Where it earns its keep

A 21-bar EMA is a common trend line on every timeframe. EURUSD H1 is the reference chart, where it covers about a day. On M15 it tracks the session. On D1 it covers a month.

Known limits

Slope flips flicker in flat markets.

An EMA still lags sharp turns.

Colour alone gives no entry level.

The popup is the only notice.

Copy the compiled Exponential Moving Average Indicator file into your MQL4/Indicators folder, and the MT5 build into MQL5/Indicators, then restart the terminal and drag it onto a chart. The step-by-step guide with screenshots is at how to install MT4 and MT5 indicators.

Related on forexmt4systems.com: Moving Average Crossover Strategy.

Download the Exponential Moving Average Indicator for MT4 and MT5

The zip holds the compiled Exponential Moving Average Indicator build for MT4 and MT5, plus a short README. Compiled files only, no source. Enter your email below and the download link arrives in your inbox.

Download this indicator free

Enter your email and the file is yours. You also get the full MT4 and MT5 library.

  • 1,380+ indicators
  • MT4 and MT5 files
  • No spam, unsubscribe any time

FAQ

Why does EmaPeriod 21 react faster than a 21-bar SMA?

The exponential weight puts about nine percent on the newest close and fades older ones gradually. A simple average weights all 21 bars equally, so it responds more slowly to fresh moves.

When does EMA Rising turn to red?

On the first bar where the average falls below its value on the bar before. The colour changes there, and the popup fires once that bar closes.

What does EmaShift do to the EMA line?

It moves the whole line forward or back by that many bars. At zero, each point lines up with the bar it was calculated on.

Does AlertOnFlip fire on the forming bar?

No. It compares the last closed bar with the two before it, so a flip only reports once the bar that caused it has closed.

Are results guaranteed?

No. Trading involves risk. Results are not guaranteed; past performance is not indicative of future results. Use the Exponential Moving Average Indicator as one input. Always backtest before trading live.

Category: this is part of our Trend collection. Also, truly, browse more Trend for MetaTrader, or explore every MT4 indicator and MT5 indicator on the site.

External references

Dominic Walsh - Forex trader and MT4/MT5 developer

About the author

Written by Dominic Walsh, a Forex trader and MT4/MT5 indicator, Expert Advisor and script developer. Every tool on forexmt4systems.com is tested on live charts before release and ships with ready-to-use compiled MT4 (.ex4) and MT5 (.ex5) files. Learn more about the trader and developer behind this site.

How we build, test and correct every tool: Editorial & Testing Policy. Trading carries risk; see the disclaimer.

Leave a Comment