Price above the line is one direction, below it is the other. No complex interpretation needed.
What is a moving average (MA)?
The base indicator of almost every trend system: it flattens price so you can see the real direction.
What is Moving Average?
Smooths price with the average of the last N candles, filtering noise and showing the direction of the trend.
Illustrative signals of the rule on simulated data — not a trading recommendation.
Rule: EMA(14) crosses above SMA(14): buy; crosses below: sell. Entry = close of the signal candle; SL = entry ∓ 1.5 × ATR(14); TP1/TP2/TP3 = 1R/2R/3R.
Where this indicator is strong
Three reasons Moving Average is still used after decades.
Put it in front of another system to remove trades that go against the main trend.
There is only the period to adjust, so it is very hard to over-optimize it into uselessness.
How to read Moving Average signals
How Moving Average (SMA / EMA) produces its number, and what each shape on the chart means.
Formula and how it works
SMA takes the simple arithmetic average of the close over N periods, with every candle weighted equally. EMA gives more weight to recent candles through the factor k = 2/(N+1), so it reacts faster to price moves. Price above the MA usually signals an uptrend, and the opposite for a downtrend.
Use it as a trend filter: only buy when price is above the MA, only sell when price is below it. A crossover of two MAs (fast/slow) is the classic entry signal.
The market trends long enough for price to move clearly away from the average.
The market moves sideways in a narrow range. Price keeps crossing back and forth over the MA, and every cross is a false signal and another fee.
Shortening the period to get earlier signals. That only increases how often the lines cross, not how often they cross correctly.
Recommended MT5 parameters for Moving Average
Default values of the sample file; test them for your market and timeframe.
| Parameter | Description |
|---|---|
| InpPeriod | Number of candles used for the average (default 14). |
| InpMethod | Calculation type: MODE_SMA (simple) or MODE_EMA (exponential). |
Put the indicator into MetaTrader 5
Four steps, no software needed besides MT5.
Click the download button above; the file saves to your computer under the indicator's name.
In MetaTrader 5 choose File → Open Data Folder, then go to MQL5/Indicators.
Open the file in MetaEditor and click Compile. No errors means the indicator is ready.
Go back to MT5, refresh the Navigator and drag the indicator onto the price chart.
DinexSpace wrote this file from the indicator's public formula, not from any commercial source. You are free to edit and reuse it.
How it differs from MetaTrader 5's built-in indicator
The short answer: the formula is not different. What differs is what you can do with it.
Moving Average here gives exactly the same number as MetaTrader 5's built-in version — on purpose. The four points below are what differs, and all four can be read from the very moving_average.mq5 you download.
- Calls a built-in indicator
- No — the calculation sits in
OnCalculateand can be copied straight into an EA - External libraries
- Not a single #import declaration
- Code length
- 52 lines · 2
inputparameters - How it draws
- Drawn over the price chart · calculated incrementally, does not redraw the past
Why this library promises no secret formula — read the full explanation on the library page.
Which indicators to pair Moving Average with, and what you gain
Each indicator only answers one question. Pairing well means covering the right weakness, not stacking more.
- What you gain
- An on/off filter. The MA gives the direction, ADX says whether that direction has enough strength to continue — only follow MA signals when ADX is above 25.
- Note
- This pair fixes the MA's biggest weakness: the run of false signals during sideways phases.
- What you gain
- Enter with the trend on pullbacks. The MA sets the allowed direction, RSI shows the pullback into the oversold zone within an uptrend.
- Note
- Only take RSI signals in the MA's direction. In this pair, an RSI signal against the trend should be ignored.
- What you gain
- A stop-loss distance that flexes with the market. The MA decides whether to enter, ATR decides how far away the stop goes.
- Note
- ATR gives no signal at all; it only sets size. Do not wait for ATR to say buy or sell.
Frequently asked questions about Moving Average
Should I use SMA or EMA?
EMA reacts faster because it weights recent candles more, which suits short timeframes. SMA is smoother with fewer false signals, which suits higher timeframes. The sample file has an InpMethod parameter to switch between the two without editing the code.
What MA period is best?
There is no ready-made best number. 20 and 50 are a common pair for medium-term trends, 200 is the long-term trend mark. More important than the number is keeping it long enough to evaluate, instead of changing it after a few losing trades.
Does Moving Average on this page use real or simulated data?
The chart on this page uses a deterministic simulated candle series; it is not market prices or trading results.
Using Moving Average in an EA, and further reading
State the candle-close condition, parameters and server time clearly when you put the rule into an EA. See the EAs available on the marketplace to compare options, or read how to read MT5 backtest results before judging any EA.
Other trend indicators
Indicators in the same trend group, often used instead of or alongside Moving Average.
An indicator draws signals, but when to enter, where to stop out and how much to risk are still your set of rules. Send those rules and DinexSpace builds them into an EA.