Moving Average Indicator for MT4 and MT5

Written by Dominic Walsh · Published · Last updated

One line, read two ways. The moving average indicator draws a single 50-bar average and colours it by direction: blue while it rises, tomato while it falls. The bar where the colour flips gets a mark, so you see turns in the trend without a second line to cross.

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 4: MA Up, MA Down, Buy, Sell
Alerts popup, push notification, email, sound
Inputs 13

What the build actually draws

One two-colour line plus two marks.

`MA Up` traces dodger blue while the line rises.

`MA Down` traces tomato while it falls.

`Buy` prints lime at a turn up.

`Sell` prints red at a turn down.

`ArrowOffsetPts` `30` sets the mark gap.

  • MA Up: line, dodger blue, width 2
  • MA Down: line, tomato, width 2
  • Buy: arrow, lime, width 2, arrow code 233
  • Sell: arrow, red, width 2, arrow code 234
moving average indicator: The two-colour line with flip marks, EURUSD H1.
The two-colour line with flip marks, EURUSD H1.

How the Moving Average Indicator calculates its values

The line

`MA_Period` `50` with `MA_Method` `MA_EMA` builds it. Simple and Hull versions are also available, and `MA_Shift` `0` keeps it aligned with the candles.

The price

`AppliedPrice` `PRICE_CLOSE` feeds it by default. Median, typical and weighted prices are there if you want the whole bar to count.

The colour

Each value is compared with the one before. Rising or flat paints blue, falling paints tomato, and `ColorFlip` can turn the two-colour display off.

How to use what it draws

Blue means the average is climbing.

Tomato means it is falling.

A mark sits on the bar where the colour flips.

`ShowArrows` hides marks and keeps the line.

Fifty bars turns slowly on purpose.

Warm-up needs about fifty bars.

Alert channels in this build: popup, push notification, email and sound, one message per closed bar.

A slope flip on a closed bar is what reports. `EnableAlerts` is the master enable; the popup and the speaker playing `SoundFile` both ship on, while email and push stay off.

Every Moving Average Indicator input

Core settings

Setting What it does Default
MA_Period Period (lookback). Bars in the average, `50`. 50
MA_Method Method (SMA / EMA / HMA). Averaging recipe, `MA_EMA`. MA_EMA
MA_Shift Horizontal shift (bars). Bars the line is displaced, `0`. 0
AppliedPrice Applied price. Price the line reads, `PRICE_CLOSE`. PRICE_CLOSE

Display settings

Setting What it does Default
ColorFlip Color flip on direction change. Two-colour display, `true`. on
ShowArrows Draw direction-flip arrows. Mark each flip, `true`. on
ArrowOffsetPts Arrow offset (points). Mark gap in points, `30`. 30

Alert settings

Setting What it does Default
EnableAlerts Master alerts enable. Master enable for flip news, `true`. on
EnablePopup Popup alert. Popup, `true`. on
EnableSound Sound alert. Speaker, ships on, `true`. on
SoundFile (see inputs panel) alert.wav
EnableEmail Email alert. off
EnablePushNotify Push notification. off
moving average indicator: Inputs panel, period and recipe above the display switches.
Inputs panel, period and recipe above the display switches.

Matching chart to settings

A 50-bar line on hourly bars flips a few times a week. EURUSD H1 is the reference chart. On M15 flips become frequent and shallow. On D1 each flip frames a trend of weeks.

The catch

A flat line can flip colour on a single bar.

Slope turns late compared with price.

One line gives no confirmation from a second.

The speaker route ships on.

Copy the compiled 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 Moving Average Indicator for MT4 and MT5

The zip holds the compiled 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

When does MA Up hand the line to MA Down?

On the first bar where the average falls below its previous value. The line changes colour there and, with marks enabled, a sell arrow appears.

Is MA_EMA the only recipe MA_Method allows?

No. Simple and Hull are there as well. Exponential ships as the default; Hull turns much faster, which means more flips and earlier ones, while simple turns the slowest.

Does MA_Shift move the flip marks?

It displaces the drawn line by that many bars. Leave it at zero if you want the colour and the marks to line up with the candles that caused them.

Why does MA Up flip colour rather than cross?

A slope change on one line turns earlier than a cross of two lines, and it keeps the chart cleaner. The trade-off is more flips when the market goes flat.

Are results guaranteed?

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

Category: this is part of our Trend collection. 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