P
PipsGrowth
Trend FollowingOpen Source – Free

Pipsgrowth EX18035 TrendFollow

MT5 Expert Advisor (Open Source) · XAUUSD · M5

Pipsgrowth.com EX18035 EX30 — Alligator/AMA/Momentum TrendFollow EA, broker-portable, capital-capped, fully managed.

Overview

Pipsgrowth EX18035 TrendFollow is an MT5 expert advisor built around Bill Williams' Alligator concept, rebuilt from SMMA primitives on the M5 timeframe, with an AMA slope filter and a Momentum(14) confirmation. The signature idea is that entries do not fire the moment the Alligator mouth opens; instead, the EA waits for a closed-bar pullback to the Lips line (period 5) and then takes the trade when the bar's close prints back above (long) or below (short) Lips and the prior bar's Lips. The setup requires three independent confirmations aligned in the same direction: the mouth ordering (Lips > Teeth > Jaw for longs, the inverse for shorts), the AMA(14) slope pointing the same way, and Momentum(14) sitting above 100 for longs or below 100 for shorts. ComputeSignal() returns a 0/1/2/3 score and a directional vote, and the EA also blocks any signal whose confidence is below 33/100 so weak mouth openings are skipped.

Regime is the second filter. DetectRegime() reads ADX(14), ATR(14), and Bollinger Bands(20, 2.0) and produces a 5-state label: STRONG_TREND (ADX >= 30 and ATR in the upper 40% of the last 50 bars), WEAK_TREND (ADX >= 22), COMPRESS (Bollinger width below 75% of the 50-bar average), RANGE (ADX < 18), and CHOPPY (default). The closed-bar Lips retest is only meaningful in TREND states, and the NoTrade() gate adds a hard CHOPPY block plus a session gate, a spread cap of 50 points, a capital floor of 50 account-currency units, daily and weekly realized-loss limits, weekend and Friday-22 closeouts, and a 3-strike cooldown.

Once a valid signal arrives, ConfirmLong() / ConfirmShort() require a higher-timeframe Alligator on H1 (SMMA(13) vs SMMA(5) using median price) to be aligned, an ATR-to-close ratio of at least 0.0005 to ensure the bar has range, and a session check that the server hour is between 7 and 20 — the live window where XAUUSD sees both London and New York participation. If everything passes, position sizing uses 0.5% of effective capital and SL = 2.0 x ATR(14), TP = 3.0 x ATR(14), a 1:1.5 reward-to-risk. The 1R break-even ratchets the stop to open + stops-level as soon as price travels one full R in profit, and a 50% partial close triggers at +1.5R so that the runner is technically free.

Management runs on every tick while a position is open: ATR(14) trailing at 2.5x with a forward-only rule (the stop can only move toward price, never away from it), regime-change close (CHOPPY or RANGE flatten the position), opposite-signal close (the ComputeSignal() output flipping against the open trade), a hard time exit at 240 bars on M5 (roughly 20 hours), and a session-close exit at server hour 21. Pyramiding is compiled in (up to 3 levels, with checks that the existing position is in profit and its stop is at or above open), but InpUsePyramid defaults to false, so the EA behaves as a single-position-per-direction system out of the box. Order retry logic runs 3 attempts on REQUOTE, TIMEOUT, PRICE_OFF, and PRICE_CHANGED responses, sleeping 100–200 ms between attempts; filling mode is auto-detected from the broker's SYMBOL_FILLING_MODE flag.

A capital allocation layer sits above the risk-percentage sizing. The InpCapitalCapAmount input is a real-money equity cap in account currency; the input row carrying the enable flag was removed in v2.00, so the cap is effectively controlled by setting the amount to 0 (off) or a positive number. EffectiveCapital() returns min(equity, cap) minus realized P&L for the day, and every lot calculation in CalcLot() uses that effective figure. A hard 50 account-currency floor also blocks new entries if effective capital drops below it. This is unusual: most EAs in the same TrendFollow family expose only risk percentage and ignore the cash side of the account.

The OnTester() criterion is (netProfit * profitFactor) / (1 + |maxBalanceDD|) with a 30-trade floor, which ranks parameter sets by profit and PF while still penalising deep drawdowns. The comment hardcoded to every order is "Psgrowth.com Expert_18035", magic is 22218035, and the EA defaults to InpDryRun = true, meaning the first run on a new symbol will not place real orders — turn that off in the inputs before going live.

What to expect in backtest: the EA is tuned for XAUUSD on M5. The closed-bar Lips pullback tends to fire on the 1–3 candles that follow the initial mouth open, so trade frequency is higher than the EMA-cross TrendFollow variants in the same family. A broker that quotes XAUUSD with sub-30-point spreads is required; the 50-point spread cap is the soft cut, but anything above 30 will start eroding the 1.5R target. The H1 Alligator filter cuts the trade count further on days where the bigger picture disagrees with the M5 mouth, which is what keeps the win rate from collapsing on trend-day reversals. The capital cap input is the cleanest single dial to swing the system between a small-lot "learn the EA" run and a larger allocation once you have validated the configuration on your own broker's data.

Strategy Deep Dive

Every tick, the EA reads 10 indicator handles (8 on M5 plus 2 on H1): three SMMA primitives for the Alligator Jaw/Teeth/Lips on median price, an AMA(14) for slope, Momentum(14), ADX(14), ATR(14), Bollinger Bands(20, 2.0) for width, plus H1 SMMA(13) and SMMA(5) for the higher-timeframe trend filter. ComputeSignal() scores mouth ordering, AMA slope, and Momentum versus 100 to produce a directional vote with a 0/100 confidence; CheckEntryTrigger() then looks at the prior bar's low/high vs Lips to detect a pullback-and-recover; ConfirmLong/Short() gates the result on H1 alignment, volatility floor, R/R config, and session hour 7–20 server. ManageOpenPositions() runs the entire open-trade loop on every tick: 1R break-even ratchet, 50% partial at +1.5R, 2.5x ATR forward-only trail, regime-change close, opposite-signal close, 240-bar time exit, and 21:00 session close. The capital-cap layer sits above the lot calculation, so CalcLot() divides risk cash by per-lot stop distance using min(account equity, InpCapitalCapAmount) minus today's realized P&L, and InpCapitalCapFloor enforces a hard $50 stop on new entries.

Entry Signal

Long entry fires on a closed M5 bar whose low dipped into the SMMA(5) Lips and whose close printed back above Lips and above the prior bar's Lips, provided the Alligator mouth is bullishly fanned (Lips > Teeth > Jaw) on SMMA(13/8/5), the AMA(14) slope is up, Momentum(14) is above 100, the H1 SMMA(5) > H1 SMMA(13) higher-timeframe confirmation passes, ATR(14)/close >= 0.0005, the regime is not CHOPPY, and the server hour is between 7 and 20. Short entry mirrors these conditions on the bearish side. Signal confidence is computed as a 0/1/2/3 score (out of three confirmations) and any reading below 33/100 is rejected.

Exit Signal

Exits run on every tick while a position is open: regime-change close when the 5-state regime falls into CHOPPY or RANGE, opposite-signal close when the Alligator/AMA/Momentum consensus flips against the open trade, hard time exit at 240 M5 bars (around 20 hours), and session-close exit at server hour 21. A forward-only ATR(14) trailing stop at 2.5x ATR runs continuously; once price reaches +1R the stop ratchets to open + stops-level (one-shot break-even), and a 50% partial close fires at +1.5R.

Stop Loss

Per-trade stop loss is set at 2.0 x ATR(14) price distance from entry on both buy and sell orders, snapped to the symbol's stops-level and rounded to the symbol's digits. The break-even rule then moves the SL to open + stops-level (one-shot) the first time price reaches +1R in profit, and a 2.5x ATR(14) forward-only trailing stop ratchets behind the trade from that point forward.

Take Profit

Initial take profit is 3.0 x ATR(14) price distance from entry, which produces a 1:1.5 reward-to-risk against the 2.0 x ATR(14) stop. A 50% partial close fires at +1.5R (50% of the way to TP) so the remaining half is technically running on a free position, and the trailing stop takes over management of the runner after break-even.

Best For

Best for traders running XAUUSD on M5 with a sub-30-point-spread broker (ECN or RAW recommended) and a $100 starting balance; the 0.5% per-trade risk and 50-unit capital floor match the EA's small-account sizing. The 7–20 server-hour gate targets the London and New York overlap, so brokers whose server clock sits on UTC or UTC+2 are ideal. Set InpCapitalCapAmount to your actual starting balance to engage the cap, leave InpUsePyramid false until you have validated the configuration, and turn InpDryRun off only after a successful backtest on your broker's data.

Strategy Logic

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

Family: TrendFollow Magic: 22218035 Version: 2.00

BRIEF: Alligator mouth (Jaw<Teeth<Lips) from SMMA primitives + AMA slope + Momentum>100 signal. ADX + ATR-percentile + BB- width regime state machine. Entry on closed-bar pullback to Lips (retest); HTF(H1) Alligator confirms. ATR-based SL/TP, break-even at 1R, 50% partial at TP1, ATR trail, regime-change, opposite-signal, max-bars, session-close exits. Capital allocation cap governs all risk; pyramid OFF by default. 12 layers: REGIME, SIGNAL, ENTRY, CONFIRM, NO-TRADE, CAPITAL CAP, RISK, SIZING, MANAGE, EXIT, SCALING, OnTester

INDICATOR STACK:

  • Standard MT5 indicators

KEY FUNCTIONS:

  • NormPrice()
  • StopsLevelPrice()
  • FreezeLevelPrice()
  • ClampVolume()
  • EffectiveCapital()
  • RealizedPnLToday()
  • RealizedPnLSince()
  • RegimeName()
  • ComputeSignal()
  • CheckEntryTrigger()
  • ConfirmLong()
  • ConfirmShort()
  • ...and 13 more

INTERNAL CONSTANTS (0 total):

INPUT PARAMETERS (25 total across 5 groups):

  • [=== Capital & Risk ===] InpCapitalCapAmount = 0.0 // Real-money equity cap (account currency)
  • [=== Capital & Risk ===] InpCapitalCapFloor = 50.0 // Floor below which new entries are blocked
  • [=== Capital & Risk ===] InpRiskPercent = 0.5 // Risk per trade, % of effective_capital
  • [=== Capital & Risk ===] InpDailyLossLimitPct = 3.0 // Max daily loss, % of effective_capital
  • [=== Capital & Risk ===] InpWeeklyLossLimitPct = 6.0 // Max weekly loss, % of effective_capital
  • [=== Capital & Risk ===] InpMaxOpenTrades = 3 // Max concurrent trades (this magic)
  • [=== Capital & Risk ===] InpCooldownLosses = 3 // Cooldown after N consecutive losses (bars)
  • [=== Signal (Alligator/AMA/Momentum) ===] InpJawPeriod = 13 // Alligator Jaw period (bars)
  • [=== Signal (Alligator/AMA/Momentum) ===] InpTeethPeriod = 8 // Alligator Teeth period (bars)
  • [=== Signal (Alligator/AMA/Momentum) ===] InpLipsPeriod = 5 // Alligator Lips period (bars)
  • [=== Signal (Alligator/AMA/Momentum) ===] InpMomPeriod = 14 // Momentum period (bars)
  • [=== Signal (Alligator/AMA/Momentum) ===] InpAmaPeriod = 14 // AMA period for slope filter (bars)
  • [=== Regime / SL / TP ===] InpAdxPeriod = 14 // ADX period (regime)
  • [=== Regime / SL / TP ===] InpAtrPeriod = 14 // ATR period (SL/TP/trail)
  • [=== Regime / SL / TP ===] InpSlAtrMult = 2.0 // SL = ATR * mult (price)
  • [=== Regime / SL / TP ===] InpTpAtrMult = 3.0 // TP = ATR * mult (price)
  • [=== Regime / SL / TP ===] InpTrailAtrMult = 2.5 // ATR trailing distance (x ATR)
  • [=== Manage / Exec ===] InpMaxSpreadPts = 50.0 // Max allowed spread (points)
  • [=== Manage / Exec ===] InpMaxBarsInTrade = 240 // Hard time exit (bars)
  • [=== Manage / Exec ===] InpUsePyramid = false // Pyramid after break-even (default OFF)
  • [=== Manage / Exec ===] InpMaxPyramidLevels = 3 // Max pyramid levels (hard cap)
  • [=== Safety ===] InpDryRun = true // Dry-run: no real order sends
  • [=== Safety ===] InpKillSwitch = false // Kill switch (halts everything)
  • [=== Safety ===] InpMagic = 22218035 // Magic number
  • [=== Safety ===] InpTradeComment = "Psgrowth.com Expert_18035" // Order comment
Pseudocode
// Pipsgrowth EX18035 TrendFollow — Execution Flow (from source analysis)
// Family: TrendFollow
// Alligator mouth (Jaw<Teeth<Lips) from SMMA primitives + AMA slope + Momentum>100 signal. ADX + ATR-percentile + BB- width regime state machine. Entry on closed-bar pullback to Lips (retest); HTF(H1) Alligator confirms. ATR-based SL/TP, break-even at 1R, 50% partial at TP1, ATR trail, regime-change, opposite-signal, max-bars, session-close exits. Capital allocation cap governs all risk; pyramid OFF by default. 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
InpCapitalCapAmount0.0Real-money equity cap (account currency)
InpCapitalCapFloor50.0Floor below which new entries are blocked
InpRiskPercent0.5Risk per trade, % of effective_capital
InpDailyLossLimitPct3.0Max daily loss, % of effective_capital
InpWeeklyLossLimitPct6.0Max weekly loss, % of effective_capital
InpMaxOpenTrades3Max concurrent trades (this magic)
InpCooldownLosses3Cooldown after N consecutive losses (bars)
InpJawPeriod13Alligator Jaw period (bars)
InpTeethPeriod8Alligator Teeth period (bars)
InpLipsPeriod5Alligator Lips period (bars)
InpMomPeriod14Momentum period (bars)
InpAmaPeriod14AMA period for slope filter (bars)
InpAdxPeriod14ADX period (regime)
InpAtrPeriod14ATR period (SL/TP/trail)
InpSlAtrMult2.0SL = ATR * mult (price)
InpTpAtrMult3.0TP = ATR * mult (price)
InpTrailAtrMult2.5ATR trailing distance (x ATR)
InpMaxSpreadPts50.0Max allowed spread (points)
InpMaxBarsInTrade240Hard time exit (bars)
InpUsePyramidfalsePyramid after break-even (default OFF)
InpMaxPyramidLevels3Max pyramid levels (hard cap)
InpDryRuntrueDry-run: no real order sends
InpKillSwitchfalseKill switch (halts everything)
InpMagic22218035Magic number
InpTradeComment"Psgrowth.com Expert_18035"Order comment
Source Code (.mq5)Open Source
Pipsgrowth_com_EX18035.mq5
#property copyright "Pipsgrowth.com"
#property link      "https://pipsgrowth.com"
#property version   "2.00"
#property strict
#property description "Pipsgrowth.com EX18035 EX30 — Alligator/AMA/Momentum TrendFollow EA, broker-portable, capital-capped, fully managed."

#include <Trade/Trade.mqh>
#include <Trade/PositionInfo.mqh>
#include <Trade/SymbolInfo.mqh>
#include <Trade/AccountInfo.mqh>
#include <Trade/OrderInfo.mqh>
#include <Trade/DealInfo.mqh>

//+------------------------------------------------------------------+
//| INPUTS (20 total, grouped)                                        |
//+------------------------------------------------------------------+
input group "=== Capital & Risk ==="
// InpCapitalCapEnabled removed — use InpCapitalCapAmount=0 to disable     // Enable capital allocation cap
input double   InpCapitalCapAmount  = 0.0;    // Real-money equity cap (account currency)
input double   InpCapitalCapFloor   = 50.0;     // Floor below which new entries are blocked
input double   InpRiskPercent       = 0.5;      // Risk per trade, % of effective_capital
input double   InpDailyLossLimitPct = 3.0;      // Max daily loss, % of effective_capital
input double   InpWeeklyLossLimitPct= 6.0;      // Max weekly loss, % of effective_capital
input int      InpMaxOpenTrades     = 3;        // Max concurrent trades (this magic)
input int      InpCooldownLosses    = 3;        // Cooldown after N consecutive losses (bars)

input group "=== Signal (Alligator/AMA/Momentum) ==="
input int      InpJawPeriod         = 13;       // Alligator Jaw period (bars)
input int      InpTeethPeriod       = 8;        // Alligator Teeth period (bars)
input int      InpLipsPeriod        = 5;        // Alligator Lips period (bars)
input int      InpMomPeriod         = 14;       // Momentum period (bars)
input int      InpAmaPeriod         = 14;       // AMA period for slope filter (bars)

input group "=== Regime / SL / TP ==="
input int      InpAdxPeriod         = 14;       // ADX period (regime)
input int      InpAtrPeriod         = 14;       // ATR period (SL/TP/trail)
input double   InpSlAtrMult         = 2.0;      // SL = ATR * mult (price)
input double   InpTpAtrMult         = 3.0;      // TP = ATR * mult (price)
input double   InpTrailAtrMult      = 2.5;      // ATR trailing distance (x ATR)

input group "=== Manage / Exec ==="
input double   InpMaxSpreadPts      = 50.0;     // Max allowed spread (points)
input int      InpMaxBarsInTrade    = 240;      // Hard time exit (bars)
input bool     InpUsePyramid        = false;    // Pyramid after break-even (default OFF)
input int      InpMaxPyramidLevels  = 3;        // Max pyramid levels (hard cap)

input group "=== Safety ==="
input bool     InpDryRun            = true;     // Dry-run: no real order sends
input bool     InpKillSwitch        = false;    // Kill switch (halts everything)
input int      InpMagic             = 22218035;   // Magic number
input string   InpTradeComment      = "Psgrowth.com Expert_18035"; // Order comment

//+------------------------------------------------------------------+
//| GLOBALS                                                           |
//+------------------------------------------------------------------+
CTrade         trade;
CPositionInfo  posInfo;
CSymbolInfo    symInfo;
CAccountInfo   accInfo;
COrderInfo     ordInfo;

Full source code available on download

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

Tags:ex18035trendfollowpipsgrowthfreemt5xauusd

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_EX18035.mq5
File Size35.4 KB
Versionv2.00
PlatformMetaTrader 5
File Type.mq5 Source
StrategyTrend Following
Risk LevelMedium Risk
Timeframes
M5
Currency Pairs
XAUUSD
Min. Deposit$100