Pipsgrowth EX18027 TrendFollow
MT5 Expert Advisor (Open Source) · XAUUSD · M5, H1
Pipsgrowth.com EX18027 EN MultiIndicator — T3/ZLMA/UltraTrend consensus trend follow, full 12-layer stack.
Overview
Pipsgrowth EX18027 MultiIndicator TrendFollow is a per-bar consensus EA that fires only when at least three of four inlined trend primitives agree on direction. The four primitives are not stock MQL indicators — they are rebuilt in code from EMA and price primitives during the same bar. The first is EN-Candle-Color: a binary vote on whether the most recent closed bar printed a bullish body (close[1] > open[1]) or a bearish one. The second is EN-zero-lag-T3, the Tillson T3 smoothed moving average: ComputeT3() walks the last up-to-200 bars through six nested EMAs of period InpFastPeriod=14, then weights those six EMA outputs with the four Tillson coefficients derived from InpT3Hot=0.7 (c1 = -v³ = -0.343, c2 = 3v² + 3v³ = 1.911, c3 = -6v² - 3v - 3v³ = -3.207, c4 = 1 + 3v + 3v² + v³ = 3.639), producing a T3 line that lags price by far less than a stock EMA of the same period. The T3 vote is bullish when close[1] is above the T3 line, bearish when it is below. The third is EN-zero-lag-MA, the standard ZLEMA constructed inside ComputeZLMA() as EMA(2*close[i] - close[i+period], period) — that lag-correction trick cancels most of the EMA's lag, so the ZLEMA vote is bullish when close[1] is above the ZLMA line AND the ZLMA line is rising (ZLMA[1] > ZLMA[2]). The fourth is EN-ultra-trend-zero-lag-MA: a simple comparison of the fast ZLMA(14) against the slow ZLMA(50) — bullish when fast ZLMA is above slow ZLMA, bearish when it is below. ComputeSignal() increments the buy counter on each bullish primitive and the sell counter on each bearish one, then assigns a confidence score of |buyVotes - sellVotes| / 4 * 100. A trade only opens when one side has InpVoteThreshold=3 votes and beats the other side outright; the third bar in a clean trend almost always delivers 3 or 4 votes while a chop bar rarely delivers more than 2.
The signal then has to pass three layers of gating before TryEntry() will fire. The first is the regime classifier in DetectRegime(). Each closed bar, the EA computes ADX(14), the Bollinger(20, 2) width-as-fraction-of-middle, and the ATR(14) percentile over a 50-bar window. Seven states are possible: REG_STRONG_TREND requires ADX>=30 and ATR-percentile above 70%; REG_WEAK_TREND requires ADX>=22; REG_EXPAND requires Bollinger width above 3% of the middle AND ATR-percentile above 60%; REG_COMPRESS requires Bollinger width below 1% AND ATR-percentile below 30%; REG_BREAKOUT requires ATR-percentile above 85% AND Bollinger width above 3%; REG_CHOPPY triggers when ADX drops below 15; everything else falls into REG_RANGE. Choppy is the only regime the EA hard-blocks via CanTradeNow(); Compress, Range, and Breakout are all eligible for entries because each contains trend moments that the four-vote consensus can pick up.
The second gate is the higher-timeframe confirmation inside TryEntry() itself. The EA reads an EMA(InpHtfEmaPeriod=50) from the higher timeframe selected by InpHtfTF. The InpHtfTF input is a 1-7 mapped through MapTimeframeInt() (1=M1, 2=M5, 3=M15, 4=M30, 5=H1, 6=H4, 7=D1), and any value outside that 1-7 window — including the EA's default InpHtfTF=8 — falls through the switch to PERIOD_H1. So the default configuration confirms against the H1 50-EMA: a buy requires ask >= htfEma(50) at H1, a sell requires bid <= htfEma(50). This filter alone is what keeps the EA out of M5 trades that are running counter to the H1 trend.
The third gate is CanTradeNow(). It checks: (1) InpKillSwitch is off; (2) the terminal and account both allow trading; (3) symbol rates refreshed successfully; (4) live spread is below InpMaxSpreadPoints=30 points; (5) live spread in price terms is below 50% of the ATR(14) — so a 30-point spread on a 60-point ATR(14) is fine but a 30-point spread on a 40-point ATR(14) is not; (6) the server clock is in the 7..21 window (no weekends, no low-liquidity hours); (7) when InpCapitalCapAmount>0 and g_effectiveCapital drops below InpCapitalCapFloor=$50, no new entries — the default cap is 0 (cap off), but the $50 floor still blocks under-funded accounts; (8) the day's realized PnL hasn't already lost InpDailyLossLimitPct=3% of g_effectiveCapital; (9) the week's realized PnL hasn't already lost InpWeeklyLossLimitPct=6%; (10) the cooldown gate has not been engaged by InpCooldownLosses=3 consecutive losses (which then locks the EA out for InpCooldownBars=20 closed bars); and (11) the regime is not REG_CHOPPY.
Position management runs every tick from ManageOpenPositions(). The order in which the EA processes a position is: time-exit first (if BarsInTrade(openTime) >= InpMaxBarsInTrade=200, close with reason TIME_EXIT), then break-even (if R-multiple >= InpBreakEvenR=1.0 and the current stop is still below entry, snap SL to entry+2 points and continue), then partial close at TP1 (if InpPartialPct=50 and bid/ask has reached open+0.5InpAtrTpMultATR for buys, or open-0.5InpAtrTpMultATR for sells, and the remaining lot after partial is at or above the broker minimum, close half), then ATR trailing (snap SL to bid-trail for buys, ask+trail for sells, where trail = InpAtrTrailMult=2.5 * ATR(14), and only ratchet in the favorable direction). Each modification retries three times on requote, timeout, price-off, or price-changed before giving up. The order matters: if time-exit fires, the position is gone and break-even never runs; if break-even moves the SL, the trailing pass then re-evaluates whether the new SL is still the right distance behind price.
Initial SL is set to InpAtrSlMult=1.8 * ATR(14) on the bar the trade opens; initial TP is set to InpAtrTpMult=3.0 * ATR(14), which works out to a 1:1.67 reward-to-risk ratio against the SL. The EA rejects any candidate trade where the projected TP distance is smaller than the projected SL distance (the ratio must be at least 1.0). Sizing goes through CalcLotSize(): riskMoney = g_effectiveCapital * InpRiskPercent/100 = effective_capital * 0.005, divided by per-lot stop-loss value (slDist / tickSize * tickValue), then floored to the symbol's volume step and clamped to the symbol's volume min/max. Before any order is sent, OrderCalcMargin() verifies that the requested lot × entry price requires less than the account's free margin; if not, the order is refused without consuming a ticket attempt. The execution helper TryEntry() itself has a 1-retry loop for requote/timeout/price-changed before the trade is given up on for the bar. The InpDryRun=true default means the EA logs every decision to the journal (with votes, confidence, regime, lots, slDist, tpDist) but does not place orders until you flip that input off.
The original-source design of EX18027 is best understood as a vote-then-confirm model. The 3-of-4 threshold (InpVoteThreshold=3) is intentionally stricter than 2-of-4: a single bar in a 50% chop environment can produce 2 buy votes and 2 sell votes, but a clean trend almost always produces 3 or 4 votes on the dominant side within one to two bars. Pairing that with the H1 50-EMA confirmation and the 1:1.67 R:R means the EA is a conservative swing-on-5min EA: it does not take many trades, it waits for H1 to agree, it manages each trade through break-even at 1R, partial at 1.5R, and ATR trail from there, and it bails after 200 M5 bars (about 16 hours) if the trade hasn't moved. OnTester() multiplies net profit by profit factor and divides by 1+balance-drawdown, with a 30-trade minimum before the score is non-zero — a metaheuristic that lets the strategy tester rank passes that have statistically meaningful sample sizes.
A practical note on the InpHtfTF=8 default: any value outside 1..7 silently maps to H1, so the default is in fact the H1 confirmation, but if you set the input to 4 expecting M30 confirmation you have to know to enter 4 not 8. If you want pure intraday confirmation, set InpHtfTF=5 (H1) explicitly; if you want daily-trend confirmation, set it to 7 (D1); if you want the EA to trade within a H4 swing, set it to 6. The H1 50-EMA is the well-tested default and the only configuration the EA's published backtest covers. Other choices (H4 50, D1 50) are valid but represent parameter exploration the EA does not pre-tune for you.
Strategy Deep Dive
EX18027 rebuilds four trend primitives on every closed bar from raw price and EMA: candle-color (close>open), the Tillson T3 line (6 nested EMAs of period InpFastPeriod=14 weighted by coefficients from InpT3Hot=0.7), the ZLEMA(14) line as EMA(2*close[i] - close[i+14], 14), and the ZLEMA(14)/ZLEMA(50) ultra-trend comparison. Each primitive casts one buy or sell vote, and ComputeSignal() only opens a trade when InpVoteThreshold=3 votes agree and beat the opposite side; confidence is |buyVotes-sellVotes|/4100. DetectRegime() then classifies the bar as StrongTrend/WeakTrend/Range/Breakout/Compress/Expand/Choppy from ADX(14), Bollinger(20,2) width, and ATR(14) percentile over 50 bars — Choppy hard-blocks via CanTradeNow(). TryEntry() requires the H1 EMA(50) (because InpHtfTF=8 falls through MapTimeframeInt()'s default to PERIOD_H1) to agree with the direction, refuses if spread >30 points or >50% of ATR(14), and sizes the lot from g_effectiveCapital0.5% divided by per-lot stop value with OrderCalcMargin() pre-check. ManageOpenPositions() runs every tick and applies, in order, the 200-bar time exit, 1.0R break-even to entry±2 points, 50% partial at TP1=1.5*ATR(14), and the 2.5xATR(14) forward-only trail; each Modify/Close helper retries up to three times on requote/timeout/price-off/price-changed. The capital cap (InpCapitalCapAmount=0.0 by default) is off, but the $50 floor still blocks under-funded accounts, and the 3%-daily / 6%-weekly loss limits plus the 3-losses→20-bars cooldown protect the equity curve.
EX18027 opens a long when at least three of four inlined trend votes agree on the buy side and beat the sell side, the close of bar[1] is above the T3 line, above the ZLMA(14) which is also rising, and the fast ZLMA(14) is above the slow ZLMA(50). The higher-timeframe H1 50-EMA must also be at or below the current ask. A short opens symmetrically. Choppy regime (ADX(14) < 15) hard-blocks the entry, and the CanTradeNow() gate additionally refuses orders during weekends, outside the 7-21 server-time window, when live spread exceeds 30 points or 50% of ATR(14), or when daily/weekly loss limits or the 20-bar cooldown have engaged.
Positions are closed by one of four mechanisms: a 200-bar time exit on the current timeframe (InpMaxBarsInTrade=200, ~16 hours on M5), the 2.5xATR(14) forward-only trail ratcheting the SL to bid-2.5ATR for buys or ask+2.5ATR for sells, a 50% partial close at TP1 (0.5 * InpAtrTpMult * ATR), or an outright stop/target hit at the broker. The break-even step at 1.0R moves SL to entry+2 points (or entry-2 for shorts) on the first occasion that threshold is reached, and that move is one-shot. Each ModifySLTP/ClosePosition/ClosePartial call retries up to three times on requote, timeout, price-off, or price-changed before logging the failure.
Initial stop is set to 1.8xATR(14) from the entry (InpAtrSlMult=1.8, the same ATR(14) that the signal uses), which is then passed through RespectStops() to clamp it to the broker's stops-level minimum. The break-even at InpBreakEvenR=1.0 moves SL to entry+2 points (or entry-2 for shorts) on the first occasion the position reaches +1R; from there the 2.5xATR(14) forward-only trail takes over. A pre-trade TP/SL ratio check (tpDist/slDist must be >= 1.0) rejects entries that cannot deliver at least 1:1 R:R at the current ATR.
Initial take-profit is set to 3.0xATR(14) from the entry (InpAtrTpMult=3.0), which is a 1:1.67 reward-to-risk ratio against the 1.8xATR(14) stop. A one-shot 50% partial close fires at TP1 = 0.5 * InpAtrTpMult * ATR = 1.5*ATR(14), banking half the position; the remaining half is then managed by the 2.5xATR(14) forward trail toward the 3.0xATR TP or until the 200-bar time exit, the stop, or a regime-driven close fires.
Best suited to traders running Pipsgrowth EX18027 MultiIndicator TrendFollow on XAUUSD M5-H1 with a starting balance in the $100-$300 range (the documented minimum is $100 and the capital floor is $50). The 7-21 server-time session covers the London and New York gold sessions, so the broker should quote tight spreads through those hours; InpMaxSpreadPoints=30 plus the 50%-of-ATR(14) spread filter will refuse wide quotes. Because the EA runs 1 position at a time, uses 0.5% risk, 3% daily / 6% weekly loss limits, and a 3-losses-to-20-bars cooldown, an ECN or RAW-spread account with low commission and reliable requote handling is the right venue. Traders who want fewer, higher-conviction trades should raise InpVoteThreshold to 4 (all four votes must agree); traders who want more trades can lower it to 2 (any majority), but be aware that 2-of-4 lets chop bars through.
Strategy Logic
Pipsgrowth EX18027 TrendFollow — Strategy Logic Analysis (from .mq5 source)
Family: TrendFollow
Magic: 22218027
Version: 2.00
BRIEF:
Multi-indicator trend consensus EA. Inlines four original custom indicators (EN-Candle-Color, EN-zero-lag-T3, EN-zero-lag- MA, EN-ultra-trend-zero-lag-ma) from primitives (EMA/ATR/ADX/ Bands). A trade fires only when >=N of 4 trend votes agree, gated by ADX+ATR-pct+BB-width regime, HTF-EMA confirmation, spread/session/no-trade filters, capital-allocation cap, ATR- based SL/TP, partial TP, ATR trail, break-even and full exit ladder. No martingale; pyramid default OFF. 12 layers: REGIME, SIGNAL, ENTRY, CONFIRM, NO-TRADE, CAPITAL CAP, RISK, SIZING, MANAGE, EXIT, SCALING, OnTester
INDICATOR STACK:
- Standard
MT5indicators
KEY FUNCTIONS:
AtrPercentile()RegimeName()ComputeSignal()ComputeT3()ComputeZLMA()EMASeries()TryEntry()CanTradeNow()RealizedPnLToday()RealizedPnLThisWeek()RealizedPnLWindow()UpdateLossTracker()- ...and 17 more
INTERNAL CONSTANTS (0 total):
INPUT PARAMETERS (26 total across 6 groups):
- [=== Identity ===]
InpMagic=22218027// Magic number - [=== Identity ===]
InpTradeComment= "Psgrowth.com Expert_18027" // Trade comment - [=== Identity ===]
InpDryRun=true// Dry-run (signal/decision only) - [=== Identity ===]
InpKillSwitch=false// Kill switch (block all new trades) - [=== Capital Allocation Cap ===]
InpCapitalCapAmount=0.0// Real-money cap ($, equity) - [=== Capital Allocation Cap ===]
InpCapitalCapFloor=50.0// Floor below which no new entries ($) - [=== Risk & Sizing ===]
InpRiskPercent=0.5// Risk per trade (% effective cap) - [=== Risk & Sizing ===]
InpDailyLossLimitPct=3.0// Daily loss limit (% effective cap) - [=== Risk & Sizing ===]
InpWeeklyLossLimitPct=6.0// Weekly loss limit (% effective cap) - [=== Risk & Sizing ===]
InpCooldownLosses= 3 // Losses before cooldown (count) - [=== Risk & Sizing ===]
InpCooldownBars= 20 // Cooldown duration (bars) - [=== Signal & Entry ===]
InpFastPeriod= 14 // T3 / fast-ZLMAperiod (bars) - [=== Signal & Entry ===]
InpSlowPeriod= 50 // Slow trendEMAperiod (bars) - [=== Signal & Entry ===]
InpT3Hot=0.7// T3 volume factor (0..1) - [=== Signal & Entry ===]
InpVoteThreshold= 3 // Min consensus votes (1..4) - [=== Signal & Entry ===]
InpHtfTF= 8 //Timeframe(1=M1,2=M5,3=M15,4=M30,5=H1,6=H4,7=D1)// Higher-timeframe confirm - [=== Signal & Entry ===]
InpHtfEmaPeriod= 50 //HTFEMAperiod (bars) - [=== Exit & Trade Management ===]
InpAtrPeriod= 14 //ATRperiod (bars) - [=== Exit & Trade Management ===]
InpAtrSlMult=1.8// SL =ATR* mult - [=== Exit & Trade Management ===]
InpAtrTpMult=3.0// TP =ATR* mult - [=== Exit & Trade Management ===]
InpAtrTrailMult=2.5//ATRtrailing multiplier - [=== Exit & Trade Management ===]
InpBreakEvenR=1.0// Break-even trigger (R multiple) - [=== Exit & Trade Management ===]
InpPartialPct= 50 // Partial-close atTP1(% of lots) - [=== Exit & Trade Management ===]
InpMaxBarsInTrade= 200 // Max bars in trade (time exit) - [=== Execution & Filters ===]
InpMaxConcurrent= 1 // Max concurrent positions (this magic) - [=== Execution & Filters ===]
InpMaxSpreadPoints= 30 // Max spread (points)
// Pipsgrowth EX18027 TrendFollow — Execution Flow (from source analysis)
// Family: TrendFollow
// Multi-indicator trend consensus EA. Inlines four original custom indicators (EN-Candle-Color, EN-zero-lag-T3, EN-zero-lag- MA, EN-ultra-trend-zero-lag-ma) from primitives (EMA/ATR/ADX/ Bands). A trade fires only when >=N of 4 trend votes agree, gated by ADX+ATR-pct+BB-width regime, HTF-EMA confirmation, spread/session/no-trade filters, capital-allocation cap, ATR- based SL/TP, partial TP, ATR trail, break-even and full exit ladder. No martingale; pyramid default OFF. 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 |
|---|---|---|
| InpMagic | 22218027 | Magic number |
| InpTradeComment | "Psgrowth.com Expert_18027" | Trade comment |
| InpDryRun | true | Dry-run (signal/decision only) |
| InpKillSwitch | false | Kill switch (block all new trades) |
| InpCapitalCapAmount | 0.0 | Real-money cap ($, equity) |
| InpCapitalCapFloor | 50.0 | Floor below which no new entries ($) |
| InpRiskPercent | 0.5 | Risk per trade (% effective cap) |
| InpDailyLossLimitPct | 3.0 | Daily loss limit (% effective cap) |
| InpWeeklyLossLimitPct | 6.0 | Weekly loss limit (% effective cap) |
| InpCooldownLosses | 3 | Losses before cooldown (count) |
| InpCooldownBars | 20 | Cooldown duration (bars) |
| InpFastPeriod | 14 | T3 / fast-ZLMA period (bars) |
| InpSlowPeriod | 50 | Slow trend EMA period (bars) |
| InpT3Hot | 0.7 | T3 volume factor (0..1) |
| InpVoteThreshold | 3 | Min consensus votes (1..4) |
| InpHtfTF | 8 | Timeframe (1=M1,2=M5,3=M15,4=M30,5=H1,6=H4,7=D1)// Higher-timeframe confirm |
| InpHtfEmaPeriod | 50 | HTF EMA period (bars) |
| InpAtrPeriod | 14 | ATR period (bars) |
| InpAtrSlMult | 1.8 | SL = ATR * mult |
| InpAtrTpMult | 3.0 | TP = ATR * mult |
| InpAtrTrailMult | 2.5 | ATR trailing multiplier |
| InpBreakEvenR | 1.0 | Break-even trigger (R multiple) |
| InpPartialPct | 50 | Partial-close at TP1 (% of lots) |
| InpMaxBarsInTrade | 200 | Max bars in trade (time exit) |
| InpMaxConcurrent | 1 | Max concurrent positions (this magic) |
| InpMaxSpreadPoints | 30 | Max spread (points) |
#property copyright "Pipsgrowth.com"
#property link "https://pipsgrowth.com"
#property version "2.00"
#property strict
#property description "Pipsgrowth.com EX18027 EN MultiIndicator — T3/ZLMA/UltraTrend consensus trend follow, full 12-layer stack."
#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 (22 total) ==================
ENUM_TIMEFRAMES MapTimeframeInt(int tf)
{
switch(tf)
{
case 1: return PERIOD_M1;
case 2: return PERIOD_M5;
case 3: return PERIOD_M15;
case 4: return PERIOD_M30;
case 5: return PERIOD_H1;
case 6: return PERIOD_H4;
case 7: return PERIOD_D1;
default: return PERIOD_H1;
}
}
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_TIMEFRAMES g_InpHtfTF = PERIOD_H1;
input group "=== Identity ==="
input int InpMagic = 22218027; // Magic number
input string InpTradeComment = "Psgrowth.com Expert_18027"; // Trade comment
input bool InpDryRun = true; // Dry-run (signal/decision only)
input bool InpKillSwitch = false; // Kill switch (block all new trades)
ENUM_TIMEFRAMES MapTimeframeInt(int tf)
{
switch(tf)
{
case 1: return PERIOD_M1;
case 2: return PERIOD_M5;
case 3: return PERIOD_M15;
case 4: return PERIOD_M30;
case 5: return PERIOD_H1;
case 6: return PERIOD_H4;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.