Moving Average Trend Indicator: Slope Sets The Colour

Written by Dominic Walsh · Published · Last updated

The moving average trend indicator paints one line in two colours. `MAPeriod` `50` sets the window and `MAMethod` picks the type. Whether the value rose or fell against the previous bar decides which buffer receives it.

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 10

What the Moving average trend Indicator draws on the chart

`MA Up` carries the line in dodger blue while it rises.

`MA Down` carries it in crimson while it falls.

`Buy` uses arrow 233 and `Sell` uses 234 at each turn.

Marks sit `ArrowOffsetPts` `12` points from the candle.

  • MA Up: line, dodger blue, width 2
  • MA Down: line, crimson, width 2
  • Buy: arrow, lime, width 2, arrow code 233
  • Sell: arrow, red, width 2, arrow code 234
Moving average trend indicator coloured line and turn arrows on EURUSD H1.
Moving average trend indicator coloured line and turn arrows on EURUSD H1.

How the Moving average trend Indicator calculates its values

One average, built in the file

The code fills a source array from `AppliedPrice`, then runs the average itself. `MAMethod` defaults to `M_EMA`, so recent bars weigh more than older ones.

Slope decides the colour

Comparing this bar’s value with the previous one gives the direction. The rising buffer or the falling buffer then takes the value. Both buffers also receive the previous bar, which bridges the join so the line stays unbroken.

A turn fills an arrow

The code checks whether the previous bar rose while this one falls, or the reverse. That flip is the only event it marks. No price condition takes part.

How to read the signals

Colour is a statement about the line, not about price.

A turn arrives one bar after the change it describes.

A choppy stretch produces alternating colours and paired marks.

`MAPeriod` `50` is long enough that turns stay reasonably rare.

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

`EnableAlerts` gates the set and starts true, and `EnableSound` also ships on with `SoundFile` naming the clip. `EnablePopup` gives the terminal dialog. `EnablePushNotify` and `EnableEmail` begin false. One message per closed bar.

Every Moving average trend Indicator input

Core settings

Setting What it does Default
MAPeriod Period. Bars in the average, default `50`. 50
MAMethod Method. Type of average, default `M_EMA`. M_EMA
AppliedPrice Applied price (0=close,1=open,2=high,3=low,4=median,5=typical,6=weighted). Price feeding the average, default `PRICE_CLOSE`. PRICE_CLOSE

Display settings

Setting What it does Default
ArrowOffsetPts Arrow offset (points). How far a mark sits from its candle, in points, default `12`. 12

Alert settings

Setting What it does Default
EnableAlerts Master alert switch. Top-level switch for turn alerts, default `true`. on
EnablePopup Popup alert. Pop-up window in the terminal, default `true`. on
EnablePushNotify Mobile push notification. Push straight to your phone, default `false`. off
EnableEmail Email alert. Outgoing mail from MetaTrader, default `false`. off
EnableSound Sound alert. Audio playback on a turn, default `true`. on
SoundFile Sound file. Which audio file plays, default `”alert.wav”`. alert.wav
Moving average trend indicator inputs panel with MAPeriod, MAMethod and AppliedPrice.
Moving average trend indicator inputs panel with MAPeriod, MAMethod and AppliedPrice.

Settings that fit your chart

A fifty-bar average wants a chart with room to move. EURUSD H1 is the reference chart, where `MAPeriod` `50` covers two days. On M5 the colour flips several times a session. Daily bars leave it steady for months.

When the Moving average trend Indicator fails

Slope turns late, because an average follows price rather than leading it.

A sideways market produces colour flips that mean nothing.

Nothing checks where price sits, so a turn can print far from the line.

Copy the compiled Moving average trend 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.

Download the Moving average trend Indicator for MT4 and MT5

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

What does MAPeriod 50 change?

How many bars feed the average. Fifty is long enough to smooth out single candles while still turning inside a trend. Shorten it and the colour flips far more often. Lengthen it and turns become rare events.

Why do MA Up and MA Down share a bar?

So the line has no gap at a colour change. The code writes the previous value into both the rising and the falling buffer. Without that bridge the two coloured segments would sit apart on screen.

Does AppliedPrice affect the arrows?

Indirectly, yes. It decides which price feeds the average, and the average decides the slope. Switching from close to median or typical shifts the line slightly, which can move a turn by a bar.

What does ArrowOffsetPts 12 do?

It sets the gap between a mark and the candle in points, fixed rather than scaled. Twelve suits a five-digit currency pair. An instrument with a very different point size will want a different number.

Are results guaranteed?

No. Trading involves risk. Results are not guaranteed; past performance is not indicative of future results. Use the Moving average trend 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