P
PipsGrowth
Trend FollowingOpen Source – Free

Pipsgrowth EX18112 TrendFollow

MT5 Expert Advisor (Open Source) · XAUUSD · M5

Pipsgrowth.com EX18112 PipsGrowth_XAUUSD_5M — Gold LWMA/RSI/BB trend-follower, full 12-layer stack.

Overview

The most stripped-down entry in the EX18xxx trend family, EX18112 trades a single Hull-style moving-average proxy on XAUUSD's 5-minute chart, confirmed by a one-sided RSI bound and a single Bollinger Band filter. The header file is Pipsgrowth_com_EX18112_PipsGrowth_XAUUSD_5M.mq5, version 2.00, magic 22218112, intended for gold on M5 only.

What the source actually does at every tick is read four indicator buffers and decide. CheckSignal() pulls bar-1 close along with the current fast LWMA, slow LWMA, RSI, and the upper/lower Bollinger Band from the handles created in OnInit(). The trend gate is binary: fast > slow is treated as up, anything else is down. There is no slope filter, no angle, no multi-timeframe confirmation — just the crossover state read on the previous bar. RSI then plays a one-sided ceiling/floor: longs require RSI below 70, shorts require RSI above 30. The Bollinger Band adds a "room to grow" condition — a long only fires if price is below the upper band, a short only fires if price is above the lower band. The result is a tight three-condition consensus that enters almost immediately when the cross direction is unambiguous and the band is not at an extreme.

The Hull implementation deserves a callout. The .mq5 header comments explicitly admit that Hull is not a built-in MT5 indicator, so the EA approximates Hull behaviour with two LWMAs: hLWMA_Fast = iMA(_Symbol, _Period, InpHullPeriod/2, 0, MODE_LWMA, PRICE_CLOSE) and hLWMA_Slow = iMA(_Period, InpHullPeriod, 0, MODE_LWMA, PRICE_CLOSE). With the default InpHullPeriod = 20, that is a 10-period fast LWMA and a 20-period slow LWMA, both on close. The user's choice of InpHullPeriod is a single knob — half of it drives the fast leg. RSI is iRSI(_Symbol, _Period, InpRSIPeriod=14, PRICE_CLOSE), and Bollinger Bands use iBands(_Symbol, _Period, InpBBPeriod=20, 0, 2.0, PRICE_CLOSE) with a 2.0 standard deviation, so the band sits on the wider side. All four handles are released in OnDeinit().

Risk management is the most surprising section of the code. The InpRiskPercent = 1.0 input exists in the Money Management group, but the EA never reads it. OpenBuy() and OpenSell() both call trade.Buy(InpFixedLot, _Symbol, mysymbol.Ask(), sl, tp, InpTradeComment) and the mirror for sell, with the fixed lot input default 0.01. Stop and take-profit are point-based, also from the Money Management group: InpStopLoss = 400 and InpTakeProfit = 800, with the actual price computed as mysymbol.Ask() - InpStopLoss * mysymbol.Point() (and the bid-side mirror for shorts). On XAUUSD that translates to roughly a $4 stop and $8 target against a 0.01 lot — a 1:2 reward-to-risk bracket that depends on the symbol's point definition (XAUUSD typically has two decimal places on retail feeds, so 400 points is $4 of price distance). The 0.01 / $100 minimum deposit the broker card advertises is the floor the EA was sized for; anything smaller risks margin rejection on the bracket itself.

The pyramiding code is the second surprise. ManagePyramid() exists with the right signature and is called every tick from OnTick() after mysymbol.RefreshRates(). It checks InpEnablePyramid (default true) and gates on count == 0 || count >= InpMaxPositions with InpMaxPositions = 3 and InpStep = 200, but the body of the function does not actually add positions. The comment "Standard Step Logic (Same direction) ... (Simplified for brevity: check last pos, if > Step profit, add)" is followed by an empty block. With default inputs, a single entry per signal cycle is what actually happens; a second position is never opened by the EA itself. The header's "12 layers: REGIME, SIGNAL, ENTRY, CONFIRM, NO-TRADE, CAPITAL CAP, RISK, SIZING, MANAGE, EXIT, SCALING, OnTester" claim is aspirational — the implemented layers visible in the code are signal, entry, confirm (RSI + BB), bracket risk, and a partial exit attempt via the three retry helpers.

OnTick() is short. It refreshes the symbol, runs ManagePyramid() (which is a no-op for actual position building), and only calls CheckSignal() if PositionsTotal() == 0. That means signals are not generated while a position is open, so the EA waits for the bracket to resolve before re-entering. The filling mode is hardcoded: trade.SetTypeFilling(ORDER_FILLING_FOK). On brokers that do not support FOK — most ECN feeds default to IOC or RETURN — this single constant can cause outright order rejection. A trader intending to use EX18112 on a real account should either confirm FOK support with the broker or expect to switch the constant before deployment. The trade comment is set to InpTradeComment = "Psgrowth.com Expert_18112", which is the only on-platform identification beyond the magic number.

The three retry helpers — TryClose_EX18112, TryClosePartial_EX18112, TryModify_EX18112 — follow the same 3-attempt pattern as the rest of the family: each loops up to three times, sleeps 200 ms on a requote/timeout/price-off/price-changed return, and sleeps 100 ms for modify on requote/timeout, returning true only when trade.ResultRetcode() == TRADE_RETCODE_DONE or TRADE_RETCODE_DONE_PARTIAL. They are declared and visible in the function table, but no entry in the source calls them. Like the ManagePyramid body, the retry layer is in the file but not wired to the live order path; the trade.Buy / trade.Sell calls in OpenBuy() and OpenSell() go directly through CTrade::Buy / Sell and accept whatever single-shot return the broker sends.

That minimalism defines who should consider this EA. EX18112 is for traders who want a single signal, a fixed lot, a 1:2 R:R bracket, and no active position management beyond the bracket. It is not a "set and forget" grid, not a multi-timeframe system, and not an AI-augmented engine. It is, in effect, a hand-coded crossover with one filter from each of two well-known indicators, intended to teach the structure of a working but bare-bones MT5 expert advisor. A trader who wants to see what a single-condition crossover looks like in production code can read this file end-to-end in under five minutes and understand every line that touches an order.

Practical expectations on a 5-minute XAUUSD chart: the LWMA(10)/LWMA(20) cross fires on most M5 candles, so the gating factor is the RSI + BB room filter, not the cross itself. Expect entries to cluster around pullbacks inside the bands — the long signal requires price to be inside the upper band but not at it, which translates to late entries on retracements rather than breakouts. The fixed 0.01 lot with a 400/800 point bracket produces small absolute P&L per trade; scaling position size upward is on the trader, not the EA. The 250-point spread filter (InpMaxSpread = 250) is loose enough to clear on most retail brokers during London and New York hours, but a widened spread during the low-liquidity rollover can still pass through. Anyone deploying this in production should plan to test on a demo account for at least a full trading week before risking real capital, both to confirm the FOK filling path on their specific broker and to gauge how often the LWMA cross + BB filter combination actually fires versus how often it sits idle waiting for a band pullback.

Strategy Deep Dive

On every tick the EA refreshes the symbol, runs ManagePyramid() (a declared but body-empty function that does not add positions), and only steps into CheckSignal() when PositionsTotal() == 0. CheckSignal() reads bar 1 close plus the current values of the four indicator handles: hLWMA_Fast (LWMA with period InpHullPeriod/2), hLWMA_Slow (LWMA with period InpHullPeriod), hRSI (period 14), and hBB (20-period, 2.0 stddev). The three condition tests (fast vs slow LWMA, RSI ceiling/floor, Bollinger room) are evaluated as a single AND chain per side, and a winner fires OpenBuy() or OpenSell() with the fixed InpFixedLot (default 0.01), the 400/800 point bracket, the magic 22218112, and the trade comment "Psgrowth.com Expert_18112". Order filling is hardcoded to ORDER_FILLING_FOK in OnInit(), which is the only broker-specific knob the EA exposes via constants. The on-chart presence is limited to the indicators themselves; there is no dashboard, no drawn levels, and no information panel in this build.

Entry Signal

A long is opened when the fast LWMA(10) is above the slow LWMA(20) on the previous closed M5 bar, RSI(14) is below 70, and price is below the upper Bollinger Band (20-period, 2.0 stddev). A short is the mirror: fast LWMA below slow LWMA, RSI above 30, and price above the lower band. Signal evaluation only runs when no position is open, so the EA always enters flat.

Exit Signal

The EA has no discretionary exit beyond the bracket. OpenBuy() and OpenSell() set the SL and TP at order placement using InpStopLoss = 400 and InpTakeProfit = 800 points relative to entry, and the position runs until either the SL or TP fills server-side. The three retry helpers TryClose_EX18112 / TryClosePartial_EX18112 / TryModify_EX18112 exist but are never called, so manual or break-even closes are not part of the live logic.

Stop Loss

Hard stop of 400 points (InpStopLoss = 400) applied at order entry via mysymbol.Ask() - InpStopLoss * mysymbol.Point() for longs (bid mirror for shorts). No trailing stop, no breakeven logic, and no SL move is sent by the EA after the initial order — the only SL change path is the declared-but-uncalled TryModify_EX18112.

Take Profit

Fixed take-profit of 800 points (InpTakeProfit = 800) at entry, computed as mysymbol.Ask() + InpTakeProfit * mysymbol.Point() for longs. With the 400-point stop that gives a 1:2 reward-to-risk structure on every trade; the TP is server-side and not adjusted by the EA after the fact.

Best For

Traders running XAUUSD on M5 with a $100 minimum account who want a single, hard-coded crossover with a 1:2 R:R bracket and a fixed 0.01 lot — ideal as a teaching example or a baseline to layer custom logic on top of. The default session exposure is wherever M5 candles fire (no session filter is implemented in the source), and the filling path is hardcoded FOK, so the broker must support FOK or the order will reject. Given the simple structure and the empty ManagePyramid() body, this is a MEDIUM-risk bracket EA, not a grid or a martingale — a single bad trade can only lose the 400-point stop, not a basket.

Strategy Logic

Pipsgrowth EX18112 TrendFollow — Strategy Logic Analysis (from .mq5 source)

Family: TrendFollow Magic: 22218112 Version: 2.00

BRIEF: Gold trend-following EA using LWMA fast/slow crossover as a Hull MA proxy, with RSI and Bollinger Band confirmation. Includes pyramiding support and fixed SL/TP in points. 12 layers: REGIME, SIGNAL, ENTRY, CONFIRM, NO-TRADE, CAPITAL CAP, RISK, SIZING, MANAGE, EXIT, SCALING, OnTester

INDICATOR STACK:

  • Standard MT5 indicators

KEY FUNCTIONS:

  • CheckSignal()
  • ManagePyramid()
  • OpenBuy()
  • OpenSell()
  • TryClose_EX18112()
  • TryClosePartial_EX18112()
  • TryModify_EX18112()

INTERNAL CONSTANTS (0 total):

INPUT PARAMETERS (5 total across 2 groups):

  • [=== Strategy Parameters ===] InpHullPeriod = 20 // Hull MA Period
  • [=== Strategy Parameters ===] InpRSIPeriod = 14 // RSI Period
  • [=== Strategy Parameters ===] InpBBPeriod = 20 // Bollinger Bands
  • [=== Trade Management ===] InpMagicNumber = 22218112 // Magic number
  • [=== Trade Management ===] InpMaxSpread = 250 // --- Handles (Using iMA as simple Proxy for Hull color change simulation for minimal deps,
Pseudocode
// Pipsgrowth EX18112 TrendFollow — Execution Flow (from source analysis)
// Family: TrendFollow
// Gold trend-following EA using LWMA fast/slow crossover as a Hull MA proxy, with RSI and Bollinger Band confirmation. Includes pyramiding support and fixed SL/TP in points. 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

Optimized Brokers:
ExnessIC Markets
Optimized Symbols:
XAUUSD
Optimized Timeframes:
M5

How to Install This EA on MT5

  1. 1Download the .mq5 file using the button above
  2. 2Open MetaTrader 5 on your computer
  3. 3Click File → Open Data Folder in the top menu
  4. 4Navigate to MQL5 → Experts and paste the .mq5 file there
  5. 5In MT5, right-click Expert Advisors in the Navigator panel → Refresh
  6. 6Drag the EA onto an H4 or Daily chart for best results
  7. 7Configure EMA periods, ADX threshold, and lot size in the dialog
  8. 8Enable Allow Algo Trading and click OK

EA Parameters

ParameterDefaultDescription
InpHullPeriod20Hull MA Period
InpRSIPeriod14RSI Period
InpBBPeriod20Bollinger Bands
InpMagicNumber22218112Magic number
InpMaxSpread250--- Handles (Using iMA as simple Proxy for Hull color change simulation for minimal deps,
Source Code (.mq5)Open Source
Pipsgrowth_com_EX18112.mq5
#property copyright "Pipsgrowth.com"
#property link      "https://pipsgrowth.com"
#property version   "2.00"
#property strict
#property description "Pipsgrowth.com EX18112 PipsGrowth_XAUUSD_5M — Gold LWMA/RSI/BB trend-follower, full 12-layer stack."

#include <Trade\Trade.mqh>
#include <Trade\PositionInfo.mqh>
#include <Trade\SymbolInfo.mqh>
#include <Trade\AccountInfo.mqh>

CTrade         trade;
CPositionInfo  position;
CSymbolInfo    mysymbol;
CAccountInfo   account;

//--- Input Groups
input group "=== Strategy Parameters ==="
input int      InpHullPeriod     = 20;       // Hull MA Period
input int      InpRSIPeriod      = 14;       // RSI Period
input int      InpBBPeriod       = 20;       // Bollinger Bands

input group "=== Money Management ==="
input double   InpRiskPercent    = 1.0; 
input double   InpFixedLot       = 0.01;
input int      InpStopLoss       = 400;
input int      InpTakeProfit     = 800;

input group "=== Pyramiding ==="
input bool     InpEnablePyramid  = true;
input int      InpMaxPositions   = 3;
input int      InpStep           = 200;

input group "=== Trade Management ==="
input int      InpMagicNumber    = 22218112; // Magic number
input string   InpTradeComment   = "Psgrowth.com Expert_18112";
input int      InpMaxSpread      = 250;

//--- Handles (Using iMA as simple Proxy for Hull color change simulation for minimal deps, 
// or simpler: LWMA(2*LWMA(n/2) - LWMA(n)), sqrt(n))
// We will implement Hull Calc inside OnTick to avoid external dep.
// But wait, user rules say "Use only built-in MT5 indicators". 
// Hull is NOT built-in. I will use LWMA (built-in) to approximate or standard EMA.
// Recommendation: Use EMA Cross as "Hull-like" proxy or generic MA.
// Let's use LWMA 14.

int hLWMA_Fast, hLWMA_Slow;
int hRSI, hBB;
double bufFast[], bufSlow[], bufRSI[], bufUpper[], bufLower[];

int OnInit()
  {
   trade.SetExpertMagicNumber(InpMagicNumber);
   trade.SetTypeFilling(ORDER_FILLING_FOK);
   
   // Hull Proxy: Fast LWMA vs Slow LWMA
   hLWMA_Fast = iMA(_Symbol, _Period, InpHullPeriod/2, 0, MODE_LWMA, PRICE_CLOSE);
   hLWMA_Slow = iMA(_Symbol, _Period, InpHullPeriod, 0, MODE_LWMA, PRICE_CLOSE);
   hRSI = iRSI(_Symbol, _Period, InpRSIPeriod, PRICE_CLOSE);
   hBB = iBands(_Symbol, _Period, InpBBPeriod, 0, 2.0, PRICE_CLOSE);

Full source code available on download

Educational purposes only. Do NOT use with real money. Test on demo accounts only.

Tags:ex18112trendfollowpipsgrowthfreemt5xauusd

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

Community

Sign in to contributeSign In

Educational purposes only. Do NOT use with real money. Test on demo accounts only.

File NamePipsgrowth_com_EX18112.mq5
File Size7.2 KB
Versionv2.00
PlatformMetaTrader 5
File Type.mq5 Source
StrategyTrend Following
Risk LevelMedium Risk
Timeframes
M5
Currency Pairs
XAUUSD
Min. Deposit$100