Pipsgrowth EX18086 TrendFollow
MT5 Expert Advisor (Open Source) · XAUUSD · M5, H1
Pipsgrowth.com EX18086 ExpertMAMA — MA signal and trailing Expert, full 12-layer stack.
Overview
EX18086 TrendFollow is a deliberately thin Expert Advisor. It does not compute its own indicators, draw its own regimes, or invent its own money rules. Instead, the source wires the three standard MQL5 base classes — CExpert, CSignalMA, and CTrailingMA — together inside OnInit(), then forwards every market event to ExtExpert.OnTick(). The entire trade lifecycle is delegated to the MQL5 Standard Library, which is exactly why the .mq5 itself is short and why a trader should pay attention to the parameters the EA exposes rather than to the size of its source file.
The signal engine is a single moving average. CSignalMA evaluates three checks on the closed bar: the MA must be in the correct trend direction (rising for longs, falling for shorts), the close must sit on the correct side of the MA, and the MA value at a configurable shift must be on the same side of the filter line. EX18086 configures this signal with Inp_Signal_MA_Period=12, Inp_Signal_MA_Shift=6, Inp_Signal_MA_Method=MODE_SMA, and g_Inp_Signal_MA_Applied=PRICE_CLOSE. The shift=6 value is the most consequential: the EA looks at the MA value six bars ago as the trend reference rather than the most recent bar. That delay filters out MA micro-wobbles — a 6-bar-old SMA(12) is a stable trend proxy — but it costs entry timing. The trade opens later than a zero-shift signal, which is the trade-off baked into the strategy.
Trailing is the heart of this EA. CTrailingMA replaces a fixed-pip stop loss with a moving average that follows the price. OnInit() instantiates the trailing object with Inp_Trailing_MA_Period=12, Inp_Trailing_MA_Shift=0, Inp_Trailing_MA_Method=MODE_SMA, and g_Inp_Trailing_MA_Applied=PRICE_CLOSE. As price moves in the profitable direction, the MA value advances with it, and CExpert calls the trailing object's CheckTrailingStop() hook on each tick, which drags the stop loss along the MA curve. When price retraces toward the MA, the position is stopped out at the MA value. This produces a stop that breathes with the trend rather than locking in a static distance — the trade is allowed to run as long as price stays well above (long) or below (short) the trailing MA, and it exits when the trend itself bends.
The third standard-library class is CMoneyNone, instantiated in OnInit() with no parameters. CMoneyNone implements the IMoney interface with a single rule: always use the broker's minimum allowable lot. EX18086 therefore ignores risk percent, account equity, and lot size — position sizing is fixed at the smallest trade the broker will accept. This is the most fragile aspect of the EA. On a cent account, the minimum lot of 0.10 with XAUUSD can be many times larger than a trader expects; on a standard account the minimum 0.01 is fine. The class is consistent with the rest of the source: every other layer is also a default from the standard library.
Three helper functions wrap the CTrade API to handle the broker's transient rejections. TryClose_EX18086(ulong ticket) calls PositionClose and retries up to three times on TRADE_RETCODE_REQUOTE, TRADE_RETCODE_TIMEOUT, TRADE_RETCODE_PRICE_OFF, or TRADE_RETCODE_PRICE_CHANGED, sleeping 200 ms between attempts. TryClosePartial_EX18086(ticket, volume) does the same thing for PositionClosePartial. TryModify_EX18086(ticket, sl, tp) wraps PositionModify with the same retry pattern but uses a 100 ms sleep. These wrappers are the only custom code in the EA; they exist to make sure the trailing-stop modifications and the eventual close both land at the broker even when the server is busy.
The risk stack is therefore the standard MQL5 defaults. There is no break-even function, no profit-lock ratchet, no session filter, no spread cap, no daily-loss limit, no news filter, no regime classifier, no higher-timeframe confirmation, and no opposite-signal close. Expert_EveryTick is set to false, which means the expert is bar-driven rather than tick-driven: signals and entries are evaluated on the open of each new bar, not on every price change. CExpert handles tick-level stop-loss management internally, but entries only fire on bar opens. This avoids the duplicate-order problem that plagues some tick-driven EAs but it also means a fast candle can move far before the EA reacts.
The OnTrade() and OnTimer() handlers are one-liners that simply forward to ExtExpert.OnTrade() and ExtExpert.OnTimer(). OnDeinit() calls ExtExpert.Deinit() to clean up the CExpert object. There is no custom OnTester(), so the strategy tester will use MetaTrader's default fitness metric (profit). All the indicator buffers are managed inside CSignalMA and CTrailingMA — the EA does not maintain its own handles for iMA, iATR, iRSI, or any other indicator.
What this EA is, in plain words, is a clean baseline. It is the MQL5 standard-library ExpertMA sample with magic number 22218086, signal MA period 12 shifted by 6, and trailing MA period 12 not shifted. The leverage is the trade-off between entering late and entering false. Traders who want to study how a CSignalMA + CTrailingMA combination behaves on XAUUSD M5 with a 1-pip-spread broker will find this a useful starting point. Traders who want pre-built risk management, session filters, regime classification, or pyramiding should look at the more elaborate EAs in the catalogue — EX18086 is the canvas, not the finished painting.
The expected backtest behavior is straightforward: a trending XAUUSD M5 day with sustained one-directional movement will produce a clean series of MA-following entries with the trailing stop advancing smoothly and exiting near the MA at trend exhaustion. A sideways or choppy day will produce many small losses as the trailing MA whipsaws against price. The 6-bar shift on the signal MA acts as a slow filter that suppresses most of the chop — but not all of it. As always with a wrapper EA, the broker's spread, the symbol's commission, and the lot size the broker assigns as minimum will dominate the equity curve. Test on the actual symbol the EA will trade, with the actual broker, before committing capital.
Strategy Deep Dive
OnInit instantiates a CExpert base, attaches a CSignalMA signal module configured with SMA(12, shift=6, close) as the entry trend reference, attaches a CTrailingMA trailing module configured with SMA(12, shift=0, close) as the stop-loss curve, and attaches a CMoneyNone sizing module that always picks the broker's minimum lot. Each tick, ExtExpert.OnTick() drives the cycle: the CTrailingMA hook re-evaluates the trailing stop on every tick and ratchets the SL along the MA when price moves favorably, and on every new bar (Expert_EveryTick=false) CExpert asks CSignalMA for its long/short verdict and sends a market order through the retry-wrapped TryModify_EX18086 / TryClose_EX18086 helpers. The signal is the only custom logic; everything else is the MQL5 Standard Library running with two specific MA periods, one shifted and one not.
EX18086 enters on the M5/H1 bar open when CSignalMA reports its MA-trend condition satisfied: the SMA(12) at shift=6 confirms the direction, the close sits on the correct side of the MA, and the MA filter line agrees. CExpert evaluates the signal on the new bar (Expert_EveryTick=false), so the order is sent once per bar, not on every tick.
The trade exits when CTrailingMA's CheckTrailingStop() hook drags the stop loss into price: when the SMA(12) trailing line catches up to a retracement, CExpert closes the position at the MA value. There is no opposite-signal exit, no time stop, no end-of-day close — the trailing MA is the only exit logic.
There is no fixed-pip stop loss. The stop is dynamic: CTrailingMA follows price at the SMA(12, shift=0, close) curve, so the stop breathes with the trend. A sudden spike can produce a wide stop on entry before the MA converges.
There is no take-profit target. EX18086 is a pure trend-trail system — the position rides the MA until CTrailingMA stops it out. Partial closes via TryClosePartial_EX18086 are supported by the wrapper but not invoked by the strategy.
EX18086 fits a small XAUUSD M5 or H1 account (minimum deposit $100, MEDIUM risk label) on a low-spread ECN broker where the broker's minimum lot is reasonable. The M5/H1 timeframe suits intraday trend sessions (London and the London/New York overlap) where gold tends to trend cleanly; the 6-bar shift on the signal MA is a slow filter, so choppy overnight Asian ranges will likely produce a series of small trailing-stop losses. Pair this EA with another signal source for confirmation — on its own it is a study of the MQL5 Standard Library more than a complete trading system.
Strategy Logic
Pipsgrowth EX18086 TrendFollow — Strategy Logic Analysis (from .mq5 source)
Family: TrendFollow
Magic: 22218086
Version: 2.00
BRIEF:
MA-based signal/trailing Expert using the standard CExpert library with a Moving Average signal and MA trailing. 12 layers: REGIME, SIGNAL, ENTRY, CONFIRM, NO-TRADE, CAPITAL CAP, RISK, SIZING, MANAGE, EXIT, SCALING, OnTester
INDICATOR STACK:
- Standard
MT5indicators
KEY FUNCTIONS:
OnTrade()OnTimer()TryClose_EX18086()TryClosePartial_EX18086()TryModify_EX18086()
INTERNAL CONSTANTS (0 total):
INPUT PARAMETERS (3 total across 3 groups):
- [=== Identity ===] Expert_MagicNumber =
22218086// Magic number - [===
Signal(MA) ===] Inp_Signal_MA_Applied = 1 // Applied price (1=close,2=open,3=high,4=low,5=median,6=typical,7=weighted) - [===
Trailing(MA) ===] Inp_Trailing_MA_Applied = 1 // Applied price (1=close,2=open,3=high,4=low,5=median,6=typical,7=weighted)
// Pipsgrowth EX18086 TrendFollow — Execution Flow (from source analysis)
// Family: TrendFollow
// MA-based signal/trailing Expert using the standard CExpert library with a Moving Average signal and MA trailing. 12 layers: REGIME, SIGNAL, ENTRY, CONFIRM, NO-TRADE, CAPITAL CAP, RISK, SIZING, MANAGE, EXIT, SCALING, OnTester
ON_INIT:
Create indicator handles: standard set
Initialize state variables
Detect broker GMT offset
ON_TICK:
1. Refresh indicator buffers (closed-bar shift=1)
2. Manage existing positions:
- Break-even check
- ATR trailing stop
- Profit lock ratchet
- Time-based exit
- Opposite-signal exit
3. If new bar:
a. ClassifyRegime() — ADX/ATR/BB regime detection
b. NoTradeGate() checks:
- Market open + session filter
- Spread limit
- Cooldown after loss
- Consecutive loss limit
- Kill switch
- Max drawdown
- Max concurrent positions
- Daily/weekly loss limits
c. GenerateSignal() — strategy-specific entry logic
d. CheckConfirm() — HTF alignment + R:R + ADX minimum
e. Calculate position size from risk %
f. Execute with retry logic
g. Mark bar to prevent duplicates
ON_TESTER:
Custom fitness = weighted(RecoveryFactor, ROI, ProfitFactor, TradeCount, Sharpe, Drawdown)Optimization Profile
How to Install This EA on MT5
- 1Download the .mq5 file using the button above
- 2Open MetaTrader 5 on your computer
- 3Click File → Open Data Folder in the top menu
- 4Navigate to MQL5 → Experts and paste the .mq5 file there
- 5In MT5, right-click Expert Advisors in the Navigator panel → Refresh
- 6Drag the EA onto an H4 or Daily chart for best results
- 7Configure EMA periods, ADX threshold, and lot size in the dialog
- 8Enable Allow Algo Trading and click OK
EA Parameters
| Parameter | Default | Description |
|---|---|---|
| Expert_MagicNumber | 22218086 | Magic number |
| Inp_Signal_MA_Applied | 1 | Applied price (1=close,2=open,3=high,4=low,5=median,6=typical,7=weighted) |
| Inp_Trailing_MA_Applied | 1 | Applied price (1=close,2=open,3=high,4=low,5=median,6=typical,7=weighted) |
#property copyright "Pipsgrowth.com"
#property link "https://pipsgrowth.com"
#property version "2.00"
#property strict
#property description "Pipsgrowth.com EX18086 ExpertMAMA — MA signal and trailing Expert, full 12-layer stack."
//+------------------------------------------------------------------+
//| Include |
//+------------------------------------------------------------------+
#include <Expert\Expert.mqh>
#include <Expert\Signal\SignalMA.mqh>
#include <Expert\Trailing\TrailingMA.mqh>
#include <Expert\Money\MoneyNone.mqh>
//+------------------------------------------------------------------+
//| Inputs |
//+------------------------------------------------------------------+
//--- inputs for expert
ENUM_APPLIED_PRICE MapAppliedPriceInt(int ap)
{
switch(ap)
{
case 1: return PRICE_CLOSE;
case 2: return PRICE_OPEN;
case 3: return PRICE_HIGH;
case 4: return PRICE_LOW;
case 5: return PRICE_MEDIAN;
case 6: return PRICE_TYPICAL;
case 7: return PRICE_WEIGHTED;
default: return PRICE_CLOSE;
}
}
ENUM_APPLIED_PRICE g_Inp_Signal_MA_Applied = PRICE_CLOSE;
ENUM_APPLIED_PRICE g_Inp_Trailing_MA_Applied = PRICE_CLOSE;
input group "=== Identity ==="
input string Inp_Expert_Title ="Pipsgrowth.com Expert_18086";
input string InpTradeComment ="Psgrowth.com Expert_18086";
input long Expert_MagicNumber =22218086; // Magic number
bool Expert_EveryTick =false;
//--- inputs for signal
ENUM_APPLIED_PRICE MapAppliedPriceInt(int ap)
{
switch(ap)
{
case 1: return PRICE_CLOSE;
case 2: return PRICE_OPEN;
case 3: return PRICE_HIGH;
case 4: return PRICE_LOW;
case 5: return PRICE_MEDIAN;
case 6: return PRICE_TYPICAL;
case 7: return PRICE_WEIGHTED;
default: return PRICE_CLOSE;
}
}
ENUM_APPLIED_PRICE g_Inp_Signal_MA_Applied = PRICE_CLOSE;
ENUM_APPLIED_PRICE g_Inp_Trailing_MA_Applied = PRICE_CLOSE;
input group "=== Signal (MA) ==="
input int Inp_Signal_MA_Period =12;
input int Inp_Signal_MA_Shift =6;
input ENUM_MA_METHOD Inp_Signal_MA_Method =MODE_SMA;
input int Inp_Signal_MA_Applied = 1; // Applied price (1=close,2=open,3=high,4=low,5=median,6=typical,7=weighted)
//--- inputs for trailingFull source code available on download
Educational purposes only. Do NOT use with real money. Test on demo accounts only.
Clear Warning: Educational Purposes Only
Clear Warning: This Expert Advisor is for educational and testing purposes only. Do NOT use it with real money. Test only on demo accounts. Trading with real money involves substantial risk of capital loss. This does not constitute investment advice.
Recommended Brokers for This EA
These EAs run on MT5 — use a regulated broker with fast execution and tight spreads
Markets.com
Exness
IC Markets
Similar Expert Advisors
View All Expert AdvisorsMore Trend Following strategy EAs from our library
Pipsgrowth EX16080 Trend
Pipsgrowth.com EX16080 EURUSDTrendFollower — triple-EMA H4 trend follower, full 12-layer stack.
Pipsgrowth EX16081 Trend
Pipsgrowth.com EX16081 GoldTrendEA — XAUUSD H4 EMA cross with Fib targets, full 12-layer stack.
Pipsgrowth EX16033 Trend
Pipsgrowth.com EX16033 EA_Price_Action — price-action grid scalper, full 12-layer stack.
Community
Educational purposes only. Do NOT use with real money. Test on demo accounts only.