P
PipsGrowth
Trend FollowingOpen Source – Free

Pipsgrowth EX18085 TrendFollow

MT5 Expert Advisor (Open Source) · XAUUSD · M5, H1

Pipsgrowth.com EX18085 XAUUSD_M5_ZeroLagTrend_EA — Zero Lag T3 + Candle Color + Ultra Trend, full 12-layer stack.

Overview

Pipsgrowth EX18085 is a self-contained, no-iCustom trend system for XAUUSD on the M5 timeframe. It blends a Tillson T3 smoothing chain with a custom Zero-Lag EMA stack and an EMA-driven candle color filter, requiring all three to vote in the same direction before opening a position. Every indicator value is rebuilt from raw MqlRates buffers inside the EA — there are no external indicator handles, no iCustom calls, and no dependency on sidecar files. The result is a single MQ5 file that compiles cleanly and runs the same on any MT5 build, with no DLL or pip install step required.

The T3 component (InpT3Period=21, InpT3Factor=0.7) is computed by walking six sequential EMAs of the close and recombining them through Tillson's polynomial coefficients (c1 through c4 derived from the volume factor). That gives a smooth line with notably less lag than a standard EMA of the same period. The Zero-Lag MA family is built differently: each line is 2 * EMA(period) − EMA(EMA(period)), the classic de-lagging trick attributed to Ehlers/Mulloy. EX18085 runs three of them in parallel — a fast 9-period, a slow 21-period, and a slow 50-period trend reference — and treats the 50 as the directional filter (longs only above it, shorts only below). The candle color layer is simpler and cheaper: a 10-period EMA of the close is compared to the current bar; a bar that closes above both the EMA and its own open is bullish (1), a bar that closes below both is bearish (−1), and doji-style bars where close and open disagree with the EMA are treated as neutral and ignored.

Entry logic in CheckSignal() is a four-way AND: the fast ZL-EMA must cross above the slow ZL-EMA on the most recent closed bar (with a strict inequality on bar 1 and a on bar 2 to catch only the first bar of a fresh cross), the close must be on the correct side of the 50-period trend ZL-EMA, the T3 line must be sloping in the trade direction (g_t3[1] > g_t3[2] for longs, mirror for shorts), and the candle color must agree. The result is one signal per closed bar, gated through a session filter and a spread filter before any order is sent. There is no long-only mode in the inputs — the EA can go either side, and it relies on the four-way agreement to keep fakeouts out.

Position management runs on every tick. ManageBreakeven() is invoked before the trailing logic and slides the stop to entry plus 50 points the moment price reaches the configured 200-point BE trigger. ManageTrailingStop() then takes over: once price is 300 points in profit, the stop is ratcheted to a fixed 200 points behind the current bid/ask, but only if the new stop would be strictly better than the current one (a one-way ratchet that never loosens). The TP target is left untouched by the trailing logic, so a 1:3 R:R position can still close at the 1500-point target if the trend runs cleanly. Both helpers are independent toggles — a trader who prefers the static 500/1500 bracket can disable the trailing, the breakeven, or both, and the EA will still respect the bracket exits.

Risk is handled inside CalculateLotSize(). With InpRiskPercent=1.0 the lot is derived from the SL distance: risk money is balance * 1%, the loss-per-lot is computed from SYMBOL_TRADE_TICK_VALUE and SYMBOL_TRADE_TICK_SIZE at the SL distance, and the lot is rounded down to the broker's volume step, clamped to the symbol's min/max and capped at InpMaxLotSize (1.0 default). If the user sets InpRiskPercent to 0, the EA falls back to a fixed 0.01 lot. The order comment, magic number, slippage control and order execution are all channeled through CTrade from <Trade/Trade.mqh>, with the modify path going through a 3-retry TryModify_EX18085 helper that pauses 100 ms on requote/timeout.

The no-trade stack is short and explicit. The new-bar gate (IsNewBar()) ensures that the full indicator suite recomputes only when a fresh M5 bar opens. The session gate (IsWithinTradingSession()) supports two independent windows — by default 08:00–12:00 and 14:00–18:00 server time — which on a typical ECN broker corresponds to the London open and the London/New York overlap. Both windows can be disabled, both start and end hours can be shifted, and a position is never closed just because the session ended: management runs continuously, only fresh entries are blocked. The spread gate accepts any trade where (ask - bid) / _Point <= 200, which on XAUUSD is roughly 2.0 USD of spread — tight enough to filter news spikes but loose enough not to choke on quiet rollovers.

Pyramiding is included but off by default. When InpEnablePyramid is flipped on, IsPyramidSafe() enforces three rules: total open positions for the symbol and magic must be below InpMaxPyramidLevels (3), the SL on every existing position in the pyramid must already be locked into profit by at least InpMinSLProfit points (150 default), and the EA will not add into a position whose stop has not yet trailed above entry. That last rule effectively means new entries only join a trade that is already working — the system will not stack into a losing position. With pyramid disabled, the EA simply holds at most one position per symbol per magic and re-enters only after a stop or TP fires.

The header of the source lists the file as part of the TrendFollow family at version 2.00, with magic 22218085. The .mq5 declares zero #define constants — every tunable sits in the input groups, which makes the EA easy to A/B test from the MT5 Strategy Tester. There is no OnTester pass function and no chart info panel; the strategy is meant to be read through its trade comments and the Experts log. For backtesting, expect the full 1:3 R:R bracket to be the dominant exit path on trending XAUUSD sessions, with the BE/trailing stack doing most of the work on shallow pullbacks inside a longer move.

Strategy Deep Dive

On every tick, ManageTrailingStop() and ManageBreakeven() walk all open positions and ratchet the stops for any position in profit; only when a new M5 bar opens does the EA recompute the entire indicator stack (CalculateT3, CalculateZeroLagMAs, CalculateCandleColor) from raw MqlRates buffers — no iCustom, no indicator handles — and then run the four-way AND test in CheckSignal(). The session gate filters the result to the configured 08:00–12:00 and 14:00–18:00 server windows, the spread gate caps entries at 200 points, and the pyramid gate blocks adds unless every existing position's stop is already in profit by at least 150 points. Lot sizing comes from CalculateLotSize() (1% of balance per SL, capped to InpMaxLotSize=1.0), and orders are sent through the standard CTrade wrapper with a 3-retry, 100ms pause modify helper.

Entry Signal

A long entry fires on the close of an M5 bar when the 9-period Zero-Lag EMA crosses above the 21-period Zero-Lag EMA, the bar's close is above the 50-period trend Zero-Lag EMA, the Tillson T3 (period 21, factor 0.7) is sloping upward, and the candle-color filter classifies the bar as bullish (close > 10-EMA and close > open). A short entry mirrors all four conditions.

Exit Signal

Positions exit when the static 1:3 R:R target is hit (1500 points), when the SL fires (500 points), or when management logic — breakeven at 200 points / trailing 300 points start with 200 points distance — adjusts the stop so the position is closed by the broker. There is no opposite-signal close, no time-stop, and no end-of-day exit; trades run until TP, SL, or the trailing/BE ratchet hits.

Stop Loss

Stop loss is the static InpStopLoss=500 points on every entry, placed at ask-500 for buys and bid+500 for sells. The breakeven manager then promotes that stop to entry+50 points once price reaches 200 points in profit, and the trailing manager can later ratchet it forward 200 points behind price once price is 300 points beyond entry.

Take Profit

Take profit is a fixed InpTakeProfit=1500 points, set at ask+1500 for buys and bid-1500 for sells, giving a constant 1:3 risk-to-reward ratio against the 500-point stop. The TP is not modified by the breakeven or trailing logic and is left to the broker to fill at the original level.

Best For

Best for XAUUSD traders running the M5 timeframe on a $100+ account, where 1% risk per trade and a 1:3 R:R bracket match the asset's daily range. The two session windows (08:00–12:00 and 14:00–18:00 server) target London open and the London/New York overlap — periods where XAUUSD typically trends — so a broker offering tight spreads during those windows is preferred. The candle color filter and the four-way ZL-EMA + T3 + trend-MA agreement make this a high-confirmation trend system suited to traders who want fewer but cleaner signals rather than high trade frequency.

Strategy Logic

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

Family: TrendFollow Magic: 22218085 Version: 2.00

BRIEF: Self-contained zero-lag trend system for XAUUSD M5 using Tillson T3 with lag reduction, candle-color EMA filter and dual zero-lag MA crossover. All indicators calculated inline. Includes session, spread, trailing, breakeven and safe pyramiding. Full 12-layer stack. 12 layers: REGIME, SIGNAL, ENTRY, CONFIRM, NO-TRADE, CAPITAL CAP, RISK, SIZING, MANAGE, EXIT, SCALING, OnTester

INDICATOR STACK:

  • Standard MT5 indicators

KEY FUNCTIONS:

  • ZeroLagEMA()
  • CalculateT3()
  • CalculateZeroLagMAs()
  • CalculateCandleColor()
  • CalculateLotSize()
  • IsWithinTradingSession()
  • IsSpreadOK()
  • CountOpenTrades()
  • IsPyramidSafe()
  • ManageTrailingStop()
  • ManageBreakeven()
  • IsNewBar()
  • ...and 4 more

INTERNAL CONSTANTS (0 total):

INPUT PARAMETERS (31 total across 10 groups):

  • [=== Identity ===] InpTradeComment = "Psgrowth.com Expert_18085" // Trade Comment
  • [=== Identity ===] InpMagicNumber = 22218085 // Magic Number
  • [=== Zero-Lag T3 Settings ===] InpT3Period = 21 // T3 Period
  • [=== Zero-Lag T3 Settings ===] InpT3Factor = 0.7 // T3 Volume Factor (0-1)
  • [=== Zero-Lag MA Settings ===] InpMAPeriod = 50 // MA Period (for trend)
  • [=== Zero-Lag MA Settings ===] InpFastMAPeriod = 9 // Fast MA Period
  • [=== Zero-Lag MA Settings ===] InpSlowMAPeriod = 21 // Slow MA Period
  • [=== Candle Color Filter ===] InpUseCandleColor = true // Use Candle Color Filter
  • [=== Candle Color Filter ===] InpCandleEMA = 10 // Candle EMA Period
  • [=== Risk Management ===] InpRiskPercent = 1.0 // Risk % per Trade
  • [=== Risk Management ===] InpFixedLot = 0.01 // Fixed Lot (if Risk=0)
  • [=== Risk Management ===] InpMaxLotSize = 1.0 // Max Lot Size
  • [=== Stop Loss & Take Profit ===] InpStopLoss = 500 // Stop Loss (Points)
  • [=== Stop Loss & Take Profit ===] InpTakeProfit = 1500 // Take Profit (Points)
  • [=== Trailing & Breakeven ===] InpUseTrailing = true // Enable Trailing Stop
  • [=== Trailing & Breakeven ===] InpTrailStart = 300 // Trail Start (Points)
  • [=== Trailing & Breakeven ===] InpTrailDistance = 200 // Trail Distance (Points)
  • [=== Trailing & Breakeven ===] InpUseBreakeven = true // Enable Breakeven
  • [=== Trailing & Breakeven ===] InpBEStart = 200 // BE Trigger (Points)
  • [=== Trailing & Breakeven ===] InpBEProfit = 50 // BE Lock Profit (Points)
  • [=== Time Management ===] InpEnableSession1 = true // Enable Session 1
  • [=== Time Management ===] InpSession1Start = 8 // Session 1 Start Hour
  • [=== Time Management ===] InpSession1End = 12 // Session 1 End Hour
  • [=== Time Management ===] InpEnableSession2 = true // Enable Session 2
  • [=== Time Management ===] InpSession2Start = 14 // Session 2 Start Hour
  • [=== Time Management ===] InpSession2End = 18 // Session 2 End Hour
  • [=== Spread Filter ===] InpEnableSpreadFilter = true // Enable Spread Filter
  • [=== Spread Filter ===] InpMaxSpread = 200 // Max Spread (Points)
  • [=== Safe Pyramid ===] InpEnablePyramid = false // Enable Pyramiding
  • [=== Safe Pyramid ===] InpMaxPyramidLevels = 3 // Max Pyramid Positions
  • [=== Safe Pyramid ===] InpMinSLProfit = 150 // Min SL in Profit (Points)
Pseudocode
// Pipsgrowth EX18085 TrendFollow — Execution Flow (from source analysis)
// Family: TrendFollow
// Self-contained zero-lag trend system for XAUUSD M5 using Tillson T3 with lag reduction, candle-color EMA filter and dual zero-lag MA crossover. All indicators calculated inline. Includes session, spread, trailing, breakeven and safe pyramiding. Full 12-layer stack. 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:
M5H1

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
InpTradeComment"Psgrowth.com Expert_18085"Trade Comment
InpMagicNumber22218085Magic Number
InpT3Period21T3 Period
InpT3Factor0.7T3 Volume Factor (0-1)
InpMAPeriod50MA Period (for trend)
InpFastMAPeriod9Fast MA Period
InpSlowMAPeriod21Slow MA Period
InpUseCandleColortrueUse Candle Color Filter
InpCandleEMA10Candle EMA Period
InpRiskPercent1.0Risk % per Trade
InpFixedLot0.01Fixed Lot (if Risk=0)
InpMaxLotSize1.0Max Lot Size
InpStopLoss500Stop Loss (Points)
InpTakeProfit1500Take Profit (Points)
InpUseTrailingtrueEnable Trailing Stop
InpTrailStart300Trail Start (Points)
InpTrailDistance200Trail Distance (Points)
InpUseBreakeventrueEnable Breakeven
InpBEStart200BE Trigger (Points)
InpBEProfit50BE Lock Profit (Points)
InpEnableSession1trueEnable Session 1
InpSession1Start8Session 1 Start Hour
InpSession1End12Session 1 End Hour
InpEnableSession2trueEnable Session 2
InpSession2Start14Session 2 Start Hour
InpSession2End18Session 2 End Hour
InpEnableSpreadFiltertrueEnable Spread Filter
InpMaxSpread200Max Spread (Points)
InpEnablePyramidfalseEnable Pyramiding
InpMaxPyramidLevels3Max Pyramid Positions
InpMinSLProfit150Min SL in Profit (Points)
Source Code (.mq5)Open Source
Pipsgrowth_com_EX18085.mq5
#property copyright "Pipsgrowth.com"
#property link      "https://pipsgrowth.com"
#property version   "2.00"
#property strict
#property description "Pipsgrowth.com EX18085 XAUUSD_M5_ZeroLagTrend_EA — Zero Lag T3 + Candle Color + Ultra Trend, full 12-layer stack."
#include <Trade/Trade.mqh>
CTrade trade;

//+------------------------------------------------------------------+
//| Signal Type Enum                                                   |
//+------------------------------------------------------------------+
enum ENUM_SIGNAL_TYPE {
   SIGNAL_NONE,
   SIGNAL_BUY,
   SIGNAL_SELL
};

//+------------------------------------------------------------------+
//| Input Parameters                                                  |
//+------------------------------------------------------------------+
input group "=== Identity ==="
input string    InpTradeComment = "Psgrowth.com Expert_18085";       // Trade Comment
input ulong     InpMagicNumber = 22218085;            // Magic Number

input group "=== Zero-Lag T3 Settings ==="
input int       InpT3Period = 21;                   // T3 Period
input double    InpT3Factor = 0.7;                  // T3 Volume Factor (0-1)

input group "=== Zero-Lag MA Settings ==="
input int       InpMAPeriod = 50;                   // MA Period (for trend)
input int       InpFastMAPeriod = 9;                // Fast MA Period
input int       InpSlowMAPeriod = 21;               // Slow MA Period

input group "=== Candle Color Filter ==="
input bool      InpUseCandleColor = true;           // Use Candle Color Filter
input int       InpCandleEMA = 10;                  // Candle EMA Period

input group "=== Risk Management ==="
input double    InpRiskPercent = 1.0;               // Risk % per Trade
input double    InpFixedLot = 0.01;                 // Fixed Lot (if Risk=0)
input double    InpMaxLotSize = 1.0;                // Max Lot Size

input group "=== Stop Loss & Take Profit ==="
input int       InpStopLoss = 500;                  // Stop Loss (Points)
input int       InpTakeProfit = 1500;               // Take Profit (Points)

input group "=== Trailing & Breakeven ==="
input bool      InpUseTrailing = true;              // Enable Trailing Stop
input int       InpTrailStart = 300;                // Trail Start (Points)
input int       InpTrailDistance = 200;             // Trail Distance (Points)
input bool      InpUseBreakeven = true;             // Enable Breakeven
input int       InpBEStart = 200;                   // BE Trigger (Points)
input int       InpBEProfit = 50;                   // BE Lock Profit (Points)

input group "=== Time Management ==="
input bool      InpEnableSession1 = true;           // Enable Session 1
input int       InpSession1Start = 8;               // Session 1 Start Hour
input int       InpSession1End = 12;                // Session 1 End Hour
input bool      InpEnableSession2 = true;           // Enable Session 2
input int       InpSession2Start = 14;              // Session 2 Start Hour

Full source code available on download

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

Tags:ex18085trendfollowpipsgrowthfreemt5xauusd

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