Pipsgrowth EX18050 TrendFollow
MT5 Expert Advisor (Open Source) · XAUUSD · M5
Pipsgrowth.com EX18050 HHHH2 -- T3 Tillson slope trend-follow, full 12-layer stack.
Overview
Pipsgrowth EX18050 TrendFollow is a single-position M5 trend follower built around an inlined Tillson T3 moving average applied to a Heikin-Ashi-smoothed close. Rather than a fast/slow EMA cross or a MACD histogram flip, the entry engine watches the slope of a T3 line that the EA itself computes from six nested EMAs of period 14, weighted by Tillson's volume factor of 0.7. The T3 is drawn on top of a four-price HA close rather than raw candles, so the curve stays smooth through sideways noise and only bends meaningfully when the underlying rhythm shifts. A long signal fires when the current T3 value sits at least five points above its prior-bar reading and the actual close also sits above the previous T3 value; a short signal mirrors that pair. Because both legs of the test must clear, the EA refuses to enter on a slope that is rising into price still trading under the curve, and vice versa — that is the repaint guard that makes the strategy usable on live data, not just backtested curves.
The signal lives inside a seven-state regime classifier in ComputeRegime(). The classifier uses an ADX(14) reading, the 50-bar percentile of ATR(14), and the ratio of current Bollinger Band(20, 2.0) width to its prior bar. STRONG_TREND requires ADX above 22 and an ATR percentile at or above 60 — momentum plus volatility expansion in agreement. WEAK_TREND triggers when ADX clears 15.4 but the volatility percentile hasn't followed. EXPAND is detected by a 20%+ widening of the Bollinger envelope even when ADX is still building, while COMPRESS flags the opposite. BREAKOUT and RANGE are pure ATR-percentile buckets (>=75 and <=25 respectively). Anything that doesn't fit lands in CHOPPY, which the strategy treats as a hard block. The RegimeAllowsEntry() gate then narrows the tradeable set to STRONG_TREND, WEAK_TREND, BREAKOUT, and EXPAND, which is why the EA sits out of compression and pure range regimes entirely rather than getting chopped up at the band edges.
Confirmation is a three-gate panel. First, the higher-timeframe EMA(50) — pulled on the timeframe set by InpHTF (default H1) — must slope in the same direction as the signal; a long signal against a falling H1 EMA is refused. Second, current spread must sit at or below InpSpreadMaxPts of 30 points. Third, the active session must match one of three booleans: London 08:00–16:00 server, New York 13:00–21:00 server, or Asian 00:00–08:00 server. An RSI(14) extreme-check sits behind those gates: longs are refused when RSI is above 80, shorts when below 20. The CheckConfirm() helper returns the first failure reason as a string so the EA can log exactly which gate blocked.
The risk engine sizes every entry off the signal ATR — iATR on the signal timeframe with period equal to the T3 period (14). Stop loss is InpATRStopMult of 2.0× that ATR, take profit is InpATRTargetMult of 4.0× ATR, hardcoding a 1:2 reward-to-risk ratio. If a calculation slips below the InpMinRR of 1.5, the target is widened until the ratio clears. Position size is then computed in PreSendRiskOK() against InpRiskPercent of 0.5% of effective capital (or capped at the lot ceiling), with OrderCalcMargin checking free margin before the order is dispatched. The InpCapAmount input sets an optional equity ceiling — set to 0 it disables the cap; InpCapFloor of $50 blocks entries once effective capital drops below that level. A hard cap of 50 trades per day is enforced through _MAX_DAILY_TRADES_HARD.
Once in a position, ManageExits() runs a layered exit stack on every tick. When unrealized profit reaches one R multiple, MoveSL() slides the stop to entry plus the InpBEOffsetPts of 10 points, locking in a scratch-free exit. At the same 1R mark, half the position is closed via TryClosePartial_EX18050 (three attempts on requote, timeout, price-off, or price-changed, with 200ms sleeps between tries). Beyond 1R, a 2.5×ATR trailing stop takes over and only ever moves in the favorable direction. Two hard exits run in parallel: an opposite T3-signal exit closes the trade, and a regime flip to CHOPPY liquidates the position regardless of profit. A 500-bar time-based stop finally kicks in if the trade has been alive that long on the entry timeframe — a generous cap designed for the slow XAUUSD trend this EA targets.
A loss-cooldown watchdog sits in OnTradeTransaction. Every deal tagged with the EA's magic number is read; three consecutive losses activate a four-hour cooldown during which NoTradeReasons() returns the string "cooldown after losses". Daily and weekly equity-anchored loss limits (3% / 6% default) similarly pause entries once breached. A duplicate-entry guard keyed on the signal-bar timestamp prevents the EA from firing twice on the same close. Pyramiding is compiled in via MaybePyramid() and capped at _PYRAMID_MAX_LEVELS of 3 with 1.5×ATR spacing, but the InpPyramidEnable input is false by default — out of the box, EX18050 runs one position at a time. The InpDryRun input defaults to true, so the EA prints intended orders to the log without sending them; the user has to flip that to false to trade live. InpKillSwitch provides a manual panic button that hard-stops new entries from the next tick.
The OnTester fitness function is (netProfit * profitFactor) / (1 + drawdownPct/100), gated on a 30-trade minimum and a positive PF. That makes the optimizer reward raw return dampened by drawdown rather than chasing profit alone, which is why a parameter set with a smooth equity curve and modest profit will outrank a spiky high-PF one in optimization.
In practice, expect EX18050 to take a handful of trades per week on XAUUSD M5 during active sessions, with most winners carried by the trailing stop rather than the fixed 1:2 target. Backtest curves on gold typically show long flat stretches punctuated by 2:1 to 4:1 winners when a trend extends. The InpDryRun=true default means the EA is safe to drop on a chart immediately for visual verification — the user toggles the live switch only after confirming the signal and regime logic against their broker's data.
Strategy Deep Dive
On every M5 bar close, EvaluateSignal() builds a Heikin-Ashi-smoothed close series, runs a six-stage inlined Tillson T3 (period 14, hot factor 0.7) over it, and returns +1 or -1 only when both the T3 slope and the raw close clear the prior-bar T3 by at least 5 points. ComputeRegime() then classifies the market into one of seven states from ADX(14), 50-bar ATR percentile, and Bollinger(20, 2.0) width ratio, allowing entries only inside StrongTrend, WeakTrend, Breakout, or Expand. CheckConfirm() gates each signal through H1 EMA(50) direction, a 30-point spread cap, an active London/NY/Asia session, and an RSI(14) extreme block. The risk engine sizes every entry to 0.5% of effective capital against the 2.0×ATR(14) stop and 4.0×ATR(14) target, then ManageExits() runs a 1R break-even + 10pt offset, 50% partial at 1R, 2.5×ATR(14) trailing stop, opposite-signal close, regime-to-Choppy close, and a 500-bar time stop in parallel. A 4-hour cooldown activates after 3 consecutive losses, daily 3% and weekly 6% equity-anchored loss limits pause entries, and the default InpDryRun=true flag prints intended orders without sending them.
Long entries fire on a closed M5 bar when the inlined Tillson T3 slope is rising by at least 5 points and the bar's close sits above the prior-bar T3 value; shorts mirror that pair. The signal must also pass a three-gate confirm panel — H1 EMA(50) agreement, spread <= 30 points, active London/NY/Asia session — and ride inside a STRONG_TREND, WEAK_TREND, BREAKOUT, or EXPAND regime. RSI(14) above 80 blocks longs, below 20 blocks shorts.
Exits run in parallel: an opposite T3 signal closes the position outright, a regime flip into CHOPPY liquidates regardless of profit, and a 500-bar time stop catches trades that never resolved. A partial 50% close fires at 1R, break-even at 1R + 10 points locks a scratch-free exit, and a 2.5×ATR(14) trailing stop takes over after 1R to carry the remainder.
Stop loss is hardcoded at 2.0× the signal ATR(14) in points — for XAUUSD M5 that typically lands between 200 and 600 points depending on volatility. The stop is clamped to the broker's stops-level + a 5-point floor in AdjustStops(), then run through the break-even and trailing logic in ManageExits() once the trade is in profit.
Take profit is 4.0× the signal ATR(14) in points, hardcoding a 1:2 reward-to-risk ratio against the 2.0×ATR stop. If the calculated ratio slips below the InpMinRR floor of 1.5, the target is widened until it clears. In practice, most winners exit via the trailing stop rather than the fixed target.
Best deployed on XAUUSD M5 during the London or New York session windows (the EA's regime classifier needs ADX above 15 and an active 30-point-cap spread, both of which gold consistently offers in those hours). Minimum recommended balance: $100 given the $50 capital floor and 0.5% per-trade sizing. Use an ECN or low-spread broker — the 30-point spread cap and 2.0×ATR(14) stop are unforgiving on a wide-spread feed. Risk profile: MEDIUM, with a 3% daily / 6% weekly loss gate and a 4-hour cooldown after 3 consecutive losses.
Strategy Logic
Pipsgrowth EX18050 TrendFollow — Strategy Logic Analysis (from .mq5 source)
Family: TrendFollow
Magic: 22218050
Version: 2.00
BRIEF:
Closed-bar price candle + inlined Tillson T3 (zero-lag, GD-form from EMA(price,N) chain e1..e6) slope confirmation. 12 mandatory layers wired into OnTick: REGIME, SIGNAL (HA+T3), ENTRY, CONFIRM, NO-TRADE, CAPITAL-ALLOCATION-CAP, RISK, SIZING, MANAGE/EXIT (BE + ATR trail + partial TP + regime-change + opposite-signal + session-close), SCALING (pyramid off, capped), EXEC, OnTester. 12 layers: REGIME, SIGNAL, ENTRY, CONFIRM, NO-TRADE, CAPITAL CAP, RISK, SIZING, MANAGE, EXIT, SCALING, OnTester
INDICATOR STACK:
- Standard
MT5indicators
KEY FUNCTIONS:
PointSize()TickSize()TickValue()StopsLevelPts()FreezeLevelPts()NormPrice()PtToPrice()EffectiveCapital()RealizedPnLTodayForMagic()DebugLog()CopyBufSafe()RegimeAllowsEntry()- ...and 23 more
INTERNAL CONSTANTS (15 total):
- _T3_PERIOD = 14 // T3 Tillson period
- _T3_HOT =
0.7// T3 hot coefficient (volume factor) - _HTF_EMA_PERIOD = 50 // Higher-timeframe
EMAperiod - _ATR_REG_PERIOD = 50 //
ATRpercentile lookback - _BB_PERIOD = 20 // Bollinger period (regime width)
- _BB_DEV =
2.0// Bollinger deviation - _ADX_REG_PERIOD = 14 //
ADXperiod (regime) - _RSI_PERIOD = 14 //
RSIperiod (confirm) - _BASE_SAR_PERIODS = 25 // bars of session aware lookback
- _PYRAMID_MAX_LEVELS = 3 // hard cap for scaling
- _PYRAMID_ATR_SPACING =
1.5//ATRmultiplier between levels - _MAX_DAILY_TRADES_HARD = 50 // hard cap on trades/day
- _PARTIAL_TP_FRACTION =
0.5// close 50% atTP1 - _NEWS_BLOCK_MINUTES = 30 // manual news blackout window (each side)
- _REQUOTE_RETRY_DELAY_MS = 500 // ==================
INPUTS(12..22 grouped) ==================
INPUT PARAMETERS (33 total across 6 groups):
- [=== Identity ===]
InpTradeComment= "Psgrowth.com Expert_18050" // Trade comment (string) - [=== Identity ===]
InpMagicNumber=22218050// Magic number (int) - [=== Identity ===]
InpAllowLongTrades=true// Allow long entries (bool) - [=== Identity ===]
InpAllowShortTrades=true// Allow short entries (bool) - [=== Identity ===]
InpDryRun=true// Dry-run: skip actual order sends (bool) - [=== Identity ===]
InpKillSwitch=false// Kill switch: stop trading immediately (bool) - [=== Risk & Sizing ===]
InpRiskPercent=0.5// Risk per trade (% of effective capital) (%) - [=== Risk & Sizing ===]
InpMinRR=1.5// Minimum reward:risk ratio (ratio) - [=== Risk & Sizing ===]
InpDailyLossLimitPct=3.0// Max daily loss (% of effective capital) (%) - [=== Risk & Sizing ===]
InpWeeklyLossLimitPct=6.0// Max weekly loss (% of effective capital) (%) - [=== Risk & Sizing ===]
InpMaxConcurrent= 1 // Max concurrent positions (count) - [=== Risk & Sizing ===]
InpMaxSymbolTrades= 1 // Max concurrent trades on this symbol (count) - [=== Risk & Sizing ===]
InpCooldownLosses= 3 // Losses before cooldown (count) - [=== Capital Allocation Cap ===]
InpCapAmount=0.0// Cap on real-money equity ($) - [=== Capital Allocation Cap ===]
InpCapFloor=50.0// Floor below which new entries are blocked ($) - [=== Signal & Indicators ===]
InpSignalTF= 0 //Timeframe(1=M1,2=M5,3=M15,4=M30,5=H1,6=H4,7=D1) // Signal timeframe (tf) - [=== Signal & Indicators ===]
InpHTF= 8 //Timeframe(1=M1,2=M5,3=M15,4=M30,5=H1,6=H4,7=D1) // Higher timeframe for trend confirm (tf) - [=== Signal & Indicators ===]
InpADXMin=22.0// MinimumADXfor trend regime (value) - [=== Signal & Indicators ===]
InpSpreadMaxPts= 30 // Max allowed spread (points) - [=== Signal & Indicators ===]
InpATRStopMult=2.0//ATRmultiplier forSL(ratio) - [=== Signal & Indicators ===]
InpATRTargetMult=4.0//ATRmultiplier forTP(ratio) - [=== Signal & Indicators ===]
InpATRTrailMult=2.5//ATRmultiplier for trailing stop (ratio) - [=== Management ===]
InpUseBreakEven=true// Use break-even move (bool) - [=== Management ===]
InpBEActivateR=1.0// Activate BE after R multiples (R) - [=== Management ===]
InpBEOffsetPts= 10 // Lock-in offset at BE (points) - [=== Management ===]
InpUsePartialTP=true// Close partial position atTP1(bool) - [=== Management ===]
InpPartialTPR=1.0// R multiple for partialTP(R) - [=== Management ===]
InpExitOppSignal=true// Exit on opposite signal (bool) - [=== Management ===]
InpExitRegimeChange=true// Exit on regime change (bool) - [=== Management ===]
InpPyramidEnable=false// Enable pyramiding (off by default) (bool) - [===
Sessions(broker time) ===]InpTradeLondon=true// Trade London session 08-16 (bool) - [===
Sessions(broker time) ===]InpTradeNY=true// Trade NY session 13-21 (bool) - [===
Sessions(broker time) ===]InpTradeAsia=false// Trade Asian session 00-08 (bool)
// Pipsgrowth EX18050 TrendFollow — Execution Flow (from source analysis)
// Family: TrendFollow
// Closed-bar price candle + inlined Tillson T3 (zero-lag, GD-form from EMA(price,N) chain e1..e6) slope confirmation. 12 mandatory layers wired into OnTick: REGIME, SIGNAL (HA+T3), ENTRY, CONFIRM, NO-TRADE, CAPITAL-ALLOCATION-CAP, RISK, SIZING, MANAGE/EXIT (BE + ATR trail + partial TP + regime-change + opposite-signal + session-close), SCALING (pyramid off, capped), EXEC, OnTester. 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 |
|---|---|---|
| InpTradeComment | "Psgrowth.com Expert_18050" | Trade comment (string) |
| InpMagicNumber | 22218050 | Magic number (int) |
| InpAllowLongTrades | true | Allow long entries (bool) |
| InpAllowShortTrades | true | Allow short entries (bool) |
| InpDryRun | true | Dry-run: skip actual order sends (bool) |
| InpKillSwitch | false | Kill switch: stop trading immediately (bool) |
| InpRiskPercent | 0.5 | Risk per trade (% of effective capital) (%) |
| InpMinRR | 1.5 | Minimum reward:risk ratio (ratio) |
| InpDailyLossLimitPct | 3.0 | Max daily loss (% of effective capital) (%) |
| InpWeeklyLossLimitPct | 6.0 | Max weekly loss (% of effective capital) (%) |
| InpMaxConcurrent | 1 | Max concurrent positions (count) |
| InpMaxSymbolTrades | 1 | Max concurrent trades on this symbol (count) |
| InpCooldownLosses | 3 | Losses before cooldown (count) |
| InpCapAmount | 0.0 | Cap on real-money equity ($) |
| InpCapFloor | 50.0 | Floor below which new entries are blocked ($) |
| InpSignalTF | 0 | Timeframe (1=M1,2=M5,3=M15,4=M30,5=H1,6=H4,7=D1) // Signal timeframe (tf) |
| InpHTF | 8 | Timeframe (1=M1,2=M5,3=M15,4=M30,5=H1,6=H4,7=D1) // Higher timeframe for trend confirm (tf) |
| InpADXMin | 22.0 | Minimum ADX for trend regime (value) |
| InpSpreadMaxPts | 30 | Max allowed spread (points) |
| InpATRStopMult | 2.0 | ATR multiplier for SL (ratio) |
| InpATRTargetMult | 4.0 | ATR multiplier for TP (ratio) |
| InpATRTrailMult | 2.5 | ATR multiplier for trailing stop (ratio) |
| InpUseBreakEven | true | Use break-even move (bool) |
| InpBEActivateR | 1.0 | Activate BE after R multiples (R) |
| InpBEOffsetPts | 10 | Lock-in offset at BE (points) |
| InpUsePartialTP | true | Close partial position at TP1 (bool) |
| InpPartialTPR | 1.0 | R multiple for partial TP (R) |
| InpExitOppSignal | true | Exit on opposite signal (bool) |
| InpExitRegimeChange | true | Exit on regime change (bool) |
| InpPyramidEnable | false | Enable pyramiding (off by default) (bool) |
| InpTradeLondon | true | Trade London session 08-16 (bool) |
| InpTradeNY | true | Trade NY session 13-21 (bool) |
| InpTradeAsia | false | Trade Asian session 00-08 (bool) |
#property copyright "Pipsgrowth.com"
#property link "https://pipsgrowth.com"
#property version "2.00"
#property strict
#property description "Pipsgrowth.com EX18050 HHHH2 -- T3 Tillson slope 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>
//================== TUNABLE CONSTANTS (#define, not inputs) ==================
#define _T3_PERIOD 14 // T3 Tillson period
#define _T3_HOT 0.7 // T3 hot coefficient (volume factor)
#define _HTF_EMA_PERIOD 50 // Higher-timeframe EMA period
#define _ATR_REG_PERIOD 50 // ATR percentile lookback
#define _BB_PERIOD 20 // Bollinger period (regime width)
#define _BB_DEV 2.0 // Bollinger deviation
#define _ADX_REG_PERIOD 14 // ADX period (regime)
#define _RSI_PERIOD 14 // RSI period (confirm)
#define _BASE_SAR_PERIODS 25 // bars of session aware lookback
#define _PYRAMID_MAX_LEVELS 3 // hard cap for scaling
#define _PYRAMID_ATR_SPACING 1.5 // ATR multiplier between levels
#define _MAX_DAILY_TRADES_HARD 50 // hard cap on trades/day
#define _PARTIAL_TP_FRACTION 0.5 // close 50% at TP1
#define _NEWS_BLOCK_MINUTES 30 // manual news blackout window (each side)
#define _REQUOTE_RETRY_DELAY_MS 500
//================== INPUTS (12..22 grouped) ==================
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_InpSignalTF = PERIOD_H1;
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.