The custom moving average indicator exists so you can stop reinstalling different averages. One line, one period, and two dropdowns: pick the smoothing method and pick which price feeds it. The line colours itself by direction, and when price crosses it the bar gets an arrow. It replaces four separate indicators with one set of inputs.
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 |
| Inputs | 4 |
What the Custom Moving Average Indicator draws on the chart
MA Up and MA Down carry the same average, split into two buffers so the line changes colour with its direction.
Buy drops a lime arrow under a bar whose close moved above the average.
Sell places a red arrow above the bar on the downward cross.
Arrows sit just 2 points from the candle, a spacing fixed in the code.
- MA Up: line, lime, width 2
- MA Down: line, red, width 2
- Buy: arrow, lime, width 2, arrow code 233
- Sell: arrow, red, width 2, arrow code 234

How the Custom Moving Average Indicator calculates its values
One call, four methods
Everything runs through a single iMA call taking `MaPeriod`, `MaMethod` and `AppliedPx`. MetaTrader handles the smoothing internally, so choosing MODE_SMA, MODE_EMA, MODE_SMMA or MODE_LWMA changes the maths without changing anything else. ma_prev reads the same average one bar back for the comparison.
Why two buffers hold one value
MaUp[i] and MaDn[i] both receive ma_now. That looks redundant until you consider how MetaTrader colours a line: a single buffer can only carry one colour. Writing the value into both and letting the plot rules decide which is visible gives a continuous line that changes colour without breaking where the direction turns.
Detecting the price cross
c_now and c_prev hold the current and previous closes. A buy needs c_prev at or below ma_prev with c_now above ma_now, so both sides of the comparison move together bar by bar. BuyArr lands at low[i] minus 2.0 * _Point and SellArr at high[i] plus the same. The recalculation range stops at rates_total minus `MaPeriod` minus 2, keeping the loop clear of bars the average cannot cover.
How to read the signals
Colour tells you the average’s own direction; the arrow tells you price changed sides. They are separate facts.
A cross against the line colour is the interesting case, since price and trend disagree at that moment.
LWMA reacts fastest and produces the most crosses. SMMA is the smoothest and the slowest of the four.
Because the arrow gap is only 2 points, markers sit very close to the candle on most instruments.
Alert channels in this build: popup, one message per closed bar.
Notification means a terminal popup and nothing else, controlled by `AlertOn` at its `true` default. It follows a completed bar crossing the average, with the guard allowing one message per closed bar so a candle that wavers across the line stays quiet.
Every Custom Moving Average Indicator input
Core settings
| Setting | What it does | Default |
|---|---|---|
MaPeriod |
MA period. Length of the average, default `50`. This matters more than the method for how the line behaves. | 50 |
MaMethod |
MA method (SMA/EMA/SMMA/LWMA). Smoothing choice, default `MODE_EMA`. SMMA suits a slow baseline, LWMA a responsive one. | MODE_EMA |
AppliedPx |
Applied price. Which price feeds the average, default `PRICE_CLOSE`. Median or typical price calms instruments with erratic opens. | PRICE_CLOSE |
Alert settings
| Setting | What it does | Default |
|---|---|---|
AlertOn |
Alerts on signal. Ships `true` and drives the popup described below. | on |

Settings that fit your chart
A 50 period average is a general purpose trend reference and works across the majors, metals and indices. EURUSD H1 is the reference chart, where 50 bars covers roughly two days. Traders on M15 often shorten it, while daily chart users tend to leave it alone. The method choice matters more on fast timeframes, where LWMA and SMMA behave very differently around a turn.
When the Custom Moving Average Indicator fails
Price crossing a single average is a weak signal on its own, and in a range it happens over and over.
The 2 point arrow gap is tuned for a 5-digit forex pair. On gold or an index the arrows overlap the candles.
Switching methods changes the crossing points, so a setting that looked good in review may behave differently once you change the smoothing.
Copy the compiled Custom 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 Custom Moving Average Indicator for MT4 and MT5
The zip holds the compiled Custom 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.
FAQ
Which MaMethod should I choose?
MODE_EMA is the default and the usual compromise. MODE_SMA weighs every bar equally and lags most predictably. MODE_SMMA smooths hardest, which suits a slow baseline. MODE_LWMA weights recent bars heavily and turns fastest, at the cost of more crosses. All four use the same `MaPeriod`, so switching changes the shape without changing the length.
Why do MA Up and MA Down hold the same value?
A MetaTrader line buffer carries one colour, so a single buffer cannot change colour mid-line. Writing ma_now into both buffers lets the plot show whichever matches the current direction while keeping the line continuous. Without that trick the line would break every time the trend turned.
What does AppliedPx change?
Which price the average is built from. `PRICE_CLOSE` is the default. PRICE_MEDIAN averages high and low, PRICE_TYPICAL adds the close, and PRICE_WEIGHTED counts the close twice. On instruments that gap or spike at the open, the range-based options give a steadier line than close alone.
Should I raise MaPeriod above 50?
It depends on what the line is for. As a trend backdrop, 100 or 200 gives a steadier reference and far fewer crosses. As a nearer guide for intraday work, 20 or 21 keeps the line closer to price. The default `50` sits between the two and works as a general purpose setting.
Are results guaranteed?
No. Trading involves risk. Results are not guaranteed; past performance is not indicative of future results. Use the Custom Moving Average Indicator as one input. Always backtest before trading live.
Category: this is part of our Trend collection. Also, browse more Trend for MetaTrader, or explore every MT4 indicator and MT5 indicator on the site.
External references
- Learn more about the underlying method in Triple Exponential Moving Average TEMA at StockCharts ChartSchool.
- For wider market background, see Market moving information on Wikipedia.
