Pipsgrowth EX18088 TrendFollow
MT5 Expert Advisor (Open Source) · XAUUSD · M5, H1
Pipsgrowth.com EX18088 ExpertMAPSARSizeOptimized — MA+PSAR with size-optimized money, full 12-layer stack.
Overview
EX18088 is a deliberately small MQL5 Expert Advisor that, instead of carrying its own indicator stack, wires three modules out of the MQL5 standard library onto the CExpert base class. A trader who opens the .mq5 will see the entire trading decision laid out in a single OnInit: a CSignalMA signal object is constructed and tuned to a 12-period Simple Moving Average with a 6-bar shift along the time axis, applied to close; a CTrailingPSAR trailing object is built and configured with step 0.02 and maximum 0.2 (the Wilder defaults); and a CMoneySizeOptimized money manager is attached with Percent=10.0 and DecreaseFactor=3.0. OnTick is one line — ExtExpert.OnTick() — and the standard library takes over from there, doing indicator reads, signal evaluation, order placement, and SAR-driven trailing modifications on its own. The only piece of code the author wrote themselves, beyond the wiring, is three CTrade retry wrappers (TryClose_EX18088, TryClosePartial_EX18088, TryModify_EX18088) that attempt each operation up to three times with a 200ms or 100ms sleep when the broker returns REQUOTE, TIMEOUT, PRICE_OFF, or PRICE_CHANGED. There are no custom indicator handles, no regime classifier, no news filter, no time window, no multi-timeframe confirm, no partial-close logic in the body, and no drawdown breaker — every behavioral rule lives inside the three library modules.
The signal half is the easiest to describe because it is the unmodified CSignalMA. The standard library's MA signal does not fire on a simple cross of price through the moving average; it fires when the moving average itself is sloping in the right direction AND price is on the correct side of the average. A long requires the 12-bar SMA at bar-shift 6 to be higher than the same SMA one bar earlier (slope up) and the close at bar 1 to be above that shifted MA value. A short is the mirror. The 6-bar shift is unusual — most MA signals read at shift 0 — and it is the most consequential single number in the input set. By the time the slope check fires, the SMA has had six completed bars to settle, so the cross is filtering for established directional moves rather than reacting to bar-zero noise. The flip side is the lag: this EA will give back part of every move before it enters, and it will exit late when a trend reverses. That tradeoff is the design, not a bug.
The trailing half is the unmodified CTrailingPSAR. The Parabolic SAR is calculated by the standard library on every tick from the same step (0.02) and maximum (0.2) that Wilder originally specified, and the trailing object ratchets the position's stop-loss to the SAR value whenever the SAR dot advances in the trade's favor. There is no fixed take-profit set at entry, so the position is held until the SAR flips to the opposite side of price, at which point CTrailingPSAR closes it. An opposite-direction MA cross on the signal object also forces a close of the existing position before the new entry fires, which means the MA cross itself doubles as a reversal exit. The two exits are not identical — the SAR flip can close a position that the MA slope still agrees with (a sharp pullback that bends the dot), and the MA cross can close a position that the SAR has not yet flipped on (a slow drift that bends the slope first). In practice, the SAR tends to fire first on sharp XAUUSD pullbacks and the MA cross tends to fire first on slow grinds.
The money half is what most distinguishes EX18088 from a vanilla MA-cross EA. CMoneySizeOptimized does not use a fixed risk percentage of the account balance. Instead, it computes the lot as 10% of free margin (the Percent input), but it remembers whether the previous closed deal was profitable or losing. After a loss, it reduces the next lot by the DecreaseFactor, which is 3.0. The reduction compounds: two losses in a row cut the lot further, three losses cut it again, and so on, until a winning trade resets the sizing to the base Percent value. The intent is a loss-adaptive anti-martingale — losing streaks shrink subsequent positions instead of doubling them, so a rough patch cannot escalate exposure. The cost is that a single win after several losses will trade a much smaller lot than the equity implies, which slows recovery. There is no risk-percent stop in this EA, so position sizing is governed entirely by the SizeOptimized module and the broker's free margin.
Because the file is a thin wrapper, there is very little to configure. The signal section exposes PeriodMA, Shift, Method (default MODE_SMA), and the applied-price code; the trailing section exposes the SAR Step and Maximum; the money section exposes DecreaseFactor and Percent. The magic number is 22218088 and the trade comment is 'Psgrowth.com Expert_18088', so multiple instances of this EA on the same account can coexist as long as they run on different symbols or timeframes. There is no OnTester fitness function, no optimization log, and no information panel on the chart. Three-retry close and three-retry modify wrappers handle the broker's volatile-return codes so that a single requote does not orphan a position.
What to expect in a backtest is the standard MA-cross-and-PSAR profile: a moderate number of trades, long hold times relative to the period, an equity curve that runs in long flat sections punctuated by sudden trend extensions, and drawdowns that reflect the fact that the 6-bar shift gives back roughly 30 minutes of move on M5 before it confirms. The SizeOptimized money means the worst streaks in the backtest will visibly shrink the lot size trade by trade, and the recovery from those streaks will be slower than a fixed-percent EA on the same account. The most useful knob to tune first is the MA shift — lowering it from 6 to 2 or 3 produces more trades and tighter risk per trade at the cost of more false crosses, and raising it produces the opposite.
Strategy Deep Dive
On every tick, ExtExpert.OnTick() runs the entire pipeline inside the MQL5 standard library: CSignalMA reads the 12-period SMA buffer with a 6-bar shift on close prices and emits a long when the SMA slope at shift 6 is positive and the close of bar 1 sits above that SMA, a short in the mirror case. The CTrailingPSAR trailing object then modifies the position's stop to the current SAR value whenever the SAR advances in the trade's favor, and a SAR flip closes the position. The CMoneySizeOptimized money manager sizes each new lot to 10% of free margin (Percent=10.0) and reduces that lot by DecreaseFactor=3.0 after each losing deal, compounding the reduction across consecutive losses until a winning trade resets the sizing. The only code outside the library is the three CTrade retry wrappers TryClose_EX18088, TryClosePartial_EX18088, and TryModify_EX18088, which attempt each operation up to three times with 200ms or 100ms sleep on requote, timeout, price-off, and price-changed return codes.
Entries fire on the standard library CSignalMA module: a long requires the 12-period SMA with a 6-bar shift to be sloping up (its value at bar+6 above its value at bar+7) AND the close of bar 1 to be above that shifted SMA. A short is the strict mirror. There is no additional filter — no ADX gate, no ATR gate, no spread cap, no session window, and no regime classifier — the library MA cross alone opens the trade.
Exits are owned by the CTrailingPSAR trailing object — there is no fixed take-profit at entry. When the SAR dot flips to the opposite side of price, the standard library closes the position. An opposite-direction MA cross on CSignalMA also forces a close of the existing position before the new reversal entry fires, so the signal itself doubles as a reversal exit; on sharp XAUUSD pullbacks the SAR tends to fire first, and on slow grinds the MA cross tends to fire first.
There is no fixed stop-loss set at entry. The Parabolic SAR trail (step 0.02, maximum 0.2 — the classic Wilder pair) acts as the protective stop and ratchets behind price as the trend extends; a SAR flip to the opposite side of price closes the position rather than a fixed-pip stop firing.
There is no fixed take-profit at entry. The position is held until Parabolic SAR flips to the opposite side of price — the design is built to ride extended XAUUSD trends rather than to lock in a fixed reward, and a winning position's exit is governed entirely by the SAR dot advance or the MA reversal cross, whichever comes first.
Minimum recommended balance is $100 on a low-spread ECN or RAW-spread account — the PSAR trail ratchets on every favorable tick, so spread cost compounds on XAUUSD and the trail works best where spread is small. Run on XAUUSD M5 or H1; the listing also suggests FX majors and metals, where the same MA-cross-plus-SAR profile behaves predictably. The 12/6 MA shift and the loss-adaptive SizeOptimized money (10% of free margin, 3.0 loss reduction) make this a slow hold-through-pullback trend follower rather than a fast cross scalper, and drawdowns will visibly shrink subsequent lots rather than escalating exposure — a better fit for accounts that want a defensive, anti-martingale trend wrapper than for accounts chasing aggressive recovery.
Strategy Logic
Pipsgrowth EX18088 TrendFollow — Strategy Logic Analysis (from .mq5 source)
Family: TrendFollow
Magic: 22218088
Version: 2.00
BRIEF:
MA signal with Parabolic SAR trailing and SizeOptimized money management (decreases lot after losses). Trend-follow. 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_EX18088()TryClosePartial_EX18088()TryModify_EX18088()
INTERNAL CONSTANTS (0 total):
INPUT PARAMETERS (4 total across 4 groups):
- [=== Identity ===] Expert_MagicNumber =
22218088// 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(ParabolicSAR) ===] Inp_Trailing_ParabolicSAR_Maximum =0.2// --- inputs for money - [===
Money(Size Optimized) ===] Inp_Money_SizeOptimized_Percent =10.0// +------------------------------------------------------------------+
// Pipsgrowth EX18088 TrendFollow — Execution Flow (from source analysis)
// Family: TrendFollow
// MA signal with Parabolic SAR trailing and SizeOptimized money management (decreases lot after losses). Trend-follow. 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 | 22218088 | 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_ParabolicSAR_Maximum | 0.2 | --- inputs for money |
| Inp_Money_SizeOptimized_Percent | 10.0 | +------------------------------------------------------------------+ |
#property copyright "Pipsgrowth.com"
#property link "https://pipsgrowth.com"
#property version "2.00"
#property strict
#property description "Pipsgrowth.com EX18088 ExpertMAPSARSizeOptimized — MA+PSAR with size-optimized money, full 12-layer stack."
//+------------------------------------------------------------------+
//| Include |
//+------------------------------------------------------------------+
#include <Expert\Expert.mqh>
#include <Expert\Signal\SignalMA.mqh>
#include <Expert\Trailing\TrailingParabolicSAR.mqh>
#include <Expert\Money\MoneySizeOptimized.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;
input group "=== Identity ==="
input string Inp_Expert_Title ="Pipsgrowth.com Expert_18088";
input string InpTradeComment ="Psgrowth.com Expert_18088";
input long Expert_MagicNumber =22218088; // 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;
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 trailing
ENUM_APPLIED_PRICE MapAppliedPriceInt(int ap)
{Full 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.