Pipsgrowth EX18069 TrendFollow
MT5 Expert Advisor (Open Source) · XAUUSD · M5, H1
Pipsgrowth.com EX18069 T3_Expert — T3 (Tillson) Trend-Follow EA, full 12-layer stack.
Overview
Pipsgrowth EX18069 is a T3 (Tillson) trend-following EA built around a single smoothing engine that the source code constructs from scratch, without any external indicator file. The author chose to inline T3 inside the EA rather than call it via iCustom, and the build reflects that decision end to end. The core smoothing formula is the generalized-difference form: GD(P) = EMA(P)*(1 + v) − EMA(EMA(P))*v, and T3 is computed as GD(GD(GD(P))) — three nested applications of the GD operator. After the third pass, the result is combined with the Tillson coefficients c1 = −b³, c2 = 3b² + 3b³, c3 = −6b² − 3b − 3b³, c4 = 1 + 3b + b³ + 3b², where b is the volume factor (InpT3VolumeFactor, default 0.7 — Tillson's standard). Because the source rebuilds the entire chain from a single native EMA(price, 14) call (g_hEMAc0 on the chart TF and g_hEMAh0 on the HTF), the EA needs only 1 + 1 = 2 EMA handles plus the regime stack (ATR, ADX, Bollinger) — no iCustom, no chart-attached child indicator, no .ex5 dependency.
The signal is a direction flip on the last closed bar. T3Signal() reads T3DirectionChart(1) and T3DirectionChart(2) and returns +1 when the latest closed T3 slopes up after sloping down, −1 for the reverse, and 0 when there is no flip. The flip is the only event that can fire the engine; slope-only continuation is ignored by design. To filter noise, ConfirmSlope() demands that the most recent InpT3SlopeBars (default 2) closed bars all slope in the same direction as the signal — a tighter, multi-bar consensus check that prevents triggering on single-bar wiggles that can occur with T3 near horizontal. ConfirmHTF() then checks that the higher-timeframe T3 (default HTF = 8 input, which falls through MapTimeframeInt to PERIOD_H1) slopes in the same direction. ConfirmPriceSide() finally requires the close of the last closed bar to be on the correct side of the chart-T3 value at that bar, so the price is moving with the curve, not just the curve tilting while price drifts sideways.
Entries are gated by a six-state regime classifier (ClassifyRegime), but only three of those states are actually tradeable. The classifier uses ADX(14) and a 50-bar ATR(14) percentile together with a Bollinger(20, 2.0) band-width ratio (current width / prior width). STRONG_TREND is the gate where ADX ≥ InpMinADX (20) and ATR-percentile ≥ InpATRPctMin (30%) — this is the primary mode. WEAK_TREND is the same idea with relaxed thresholds (0.7× ADX, 0.5× ATR-pct), letting the EA still take swings in early-trend development. EXPAND is fired when the Bollinger band-width grows more than 10% in one bar (bbRatio > 1.10), catching volatility bursts even when ADX is still climbing. The other three states — REG_RANGE, REG_COMPRESS, REG_BREAKOUT — are explicitly excluded by RegimeAllowsEntry(). In other words, the EA will not fire on a flat tape, a squeeze, or in the immediate aftermath of a band-width explosion. This is a deliberate narrowing of the trade universe: trend-mode or volatility-expansion-mode only.
Risk is enforced at three levels. The per-trade risk is InpRiskPercent (default 0.5% of effective capital) divided by the SL distance in price, then converted to lots via tick-value math in CalcLotsByRisk. Capital is gated by a cap that is OFF by default — InpCapitalCapAmount defaults to 0.0, in which case the EA uses the full equity as effective capital. When the cap is enabled, the effective capital becomes min(cap, equity) and any new entry is blocked if the resulting cap would drop below InpCapitalCapFloor (50 USD by default). On top of that, a daily loss limit (3% of effective capital) and a weekly loss limit (6% of equity at the start of the week) both block new entries once tripped. The realised PnL for the daily and weekly checks is computed inside the EA by walking the deal history (HistorySelect) and filtering on DEAL_MAGIC and DEAL_SYMBOL — so the limits are EA-magic-specific, not account-wide.
The stop and target are both ATR(14)-anchored. InpSLATR = 1.5 and InpTPATR = 3.0, giving a hard R:R of 1:2 at the ATR baseline, with a ConfirmRR() check that rejects the trade if ATR-shrinkage has pushed the realised R:R below InpMinRR (1.5). Both distances are also clamped to the broker's SYMBOL_TRADE_STOPS_LEVEL so that micro-trades are not sent with SL/TP inside the freeze zone. SL and TP placement is price-relative (Ask/Bid at execution), and any retry on TRADE_RETCODE_REQUOTE, _TIMEOUT, or _PRICE_CHANGED is preceded by RefreshRates() and a re-pull of Ask/Bid. Margin is pre-checked via OrderCalcMargin before the order is sent, so a free-margin shortage returns INSUFFICIENT_MARGIN rather than triggering a broker-side reject.
Once a position is open, ManagePosition() walks through the active trade every tick. Partial TP fires at InpPartialTPR (1.0R) closing InpPartialTPPct (50%) of the volume — but only if the remaining volume stays at or above the broker's minimum lot, otherwise the partial is skipped to avoid orphaned sub-minimum positions. The one-shot break-even at InpBreakevenAtR (1.0R) moves SL to the open price, again respecting the stops level by clamping the new SL to stopsLevel + 1 point away from the current Bid/Ask if the move would otherwise sit inside the freeze zone. The trailing stop is ATR(14) * InpTrailATR (2.0x) away from price, with a 0.5x ATR minimum ratchet (InpTrailATRStep) to suppress micro-wobble. The trailing only moves forward, never backward. Beyond that, ManagePosition() also implements a regime-change exit (RANGE or COMPRESS, soft mode — only triggered when the position is currently losing) and an opposite-signal exit (T3 flips against the open position). The time-based exit InpMaxBarsInTrade is wired into the same function but defaults to 0, so it is disabled unless the operator explicitly turns it on.
For deployment, the EA targets XAUUSD on the M5 chart (and is marked broker-portable for gold and FX majors), opens within a 7–21 server-time session window, blocks entries on weekends and after 20:00 on Friday, and rejects any signal when the live spread is above 3.0 pips. The default state is DryRun = true, so the EA logs intended orders instead of sending them until the operator turns trading on. KillSwitch is a separate hard-stop input. Order comment is the hard-coded Psgrowth.com Expert_18069 string, and OnTester returns (netProfit * profitFactor) / (1 + balanceDrawdown) with a 30-trade floor, so the strategy optimizer ranks candidates on a combined profit-and-stability metric rather than net profit alone.
Strategy Deep Dive
Each tick pulls ATR(14), ADX(14), Bollinger(20, 2.0), a chart-TF EMA(14) used as the T3 seed, and — when InpUseHTF is on — an H1 EMA(14) for the higher-timeframe T3. The T3 chain is rebuilt in ComputeT3Series() via the generalized-difference form GD(x) = EMA(x)*(1+v) − EMA(EMA(x))*v applied three times, with the final value combined via the four Tillson coefficients. On a new bar, ClassifyRegime() reads ADX, the 50-bar ATR percentile, and the Bollinger band-width ratio to pick one of six regime states; entries are blocked unless the regime is STRONG_TREND, WEAK_TREND, or EXPAND. T3Signal() then tests for a T3 direction flip on the last closed bar, and ConfirmSlope(), ConfirmHTF(), ConfirmPriceSide() gate that flip. TryEntry() sizes the lot from effective capital × InpRiskPercent divided by the 1.5x-ATR SL distance, runs OrderCalcMargin as a pre-check, and sends the market order with one retry on requote/timeout/price-changed. ManagePosition() runs on every tick and is what walks each open position through partial TP, the one-shot breakeven, the 2.0x-ATR trail, the regime-change soft exit, and the opposite-signal hard exit.
T3 (Tillson) direction flip on the last closed bar — T3Signal() returns +1 when chart-T3 slopes up after sloping down (or −1 for the reverse), computed in-line from GD(GD(GD(price))) over a 14-period EMA with volume factor 0.7. Three confirmations must also pass: ConfirmSlope() requires the most recent 2 closed bars to all slope in the signal direction, ConfirmHTF() requires the H1 T3 to slope the same way, and ConfirmPriceSide() requires the last closed bar's close to be on the correct side of the chart-T3 value. The trade is only allowed when the regime is STRONG_TREND, WEAK_TREND, or EXPAND — range, compress, and breakout states are all blocked.
Three independent exit paths run in ManagePosition() on every tick. The opposite-signal exit closes the position the moment T3Signal() flips against the open direction. The soft regime-change exit closes the position if the regime degrades to RANGE or COMPRESS while the trade is currently losing. The hard exit paths are the partial-TP at 1R (50% close) and the 1R one-shot breakeven move, plus the 2.0x ATR(14) forward-only trail with a 0.5x ATR ratchet. There is no fixed time stop unless InpMaxBarsInTrade is set to a non-zero value.
Fixed 1.5x ATR(14) at entry, applied as a price distance from the entry Ask/Bid, then clamped to the broker's SYMBOL_TRADE_STOPS_LEVEL plus one point so the SL never sits inside the freeze zone. After price moves 1R in favour, the SL is ratcheted to the open price (one-shot breakeven), then a 2.0x ATR(14) trailing stop with a 0.5x ATR step takes over for the remainder of the trade. The SL is only ever moved forward — never backward.
Fixed 3.0x ATR(14) at entry as a hard take-profit — that is a 1:2 R:R baseline. ConfirmRR() rejects the order if the realized R:R drops below InpMinRR (1.5) due to ATR shrinkage between signal and execution. At 1R, 50% of the position is closed (InpPartialTPPct = 50%) as a partial-TP, after which the trailing stop governs the remaining runner. There is no separate TP for the remaining runner — the trailing stop or the opposite-signal exit is what closes it.
Best deployed on XAUUSD M5 with the default risk profile (0.5% per trade, 1:2 hard R:R via 1.5x/3.0x ATR multipliers, 50% partial at 1R, 2.0x ATR trail). The minimum recommended balance is $100 with the capital cap left at the default 0 (cap off) — turn the cap on only when you have a fixed notional allocation in mind. The 7–21 server-time session and 3.0-pip spread cap mean an ECN or low-spread broker with sub-50ms execution is required, and XAUUSD must be quoted in a unit where one 1-pip move is a single price step on the chart. Run DryRun = true first to confirm the regime classifier and T3 direction match your visual read of the bars before going live.
Strategy Logic
Pipsgrowth EX18069 TrendFollow — Strategy Logic Analysis (from .mq5 source)
Family: TrendFollow
Magic: 22218069
Version: 2.00
BRIEF:
T3 (Tillson) is inlined from nested EMA primitives using the generalized-difference (GD) form: GD = EMA(P)*(1+v)- EMA(EMA(P))*v, T3 = GD(GD(GD(P))). Direction flip on the LAST CLOSED bar (shift=1) is the core signal; agreement with HTF T3 slope + closed-bar price side provides confirmation. Entries gated by ADX/ATR-pct/BB-width regime, session/spread filters, capital-allocation-cap, ATR-based hard SL/TP, break-even + partial TP + ATR trail. 12 layers: REGIME, SIGNAL, ENTRY, CONFIRM, NO-TRADE, CAPITAL CAP, RISK, SIZING, MANAGE, EXIT, SCALING, OnTester
INDICATOR STACK:
ATRADXBB
KEY FUNCTIONS:
PipSize()PipsToPrice()NormPrice()NormLots()StopsLevelPrice()FreezeLevelPrice()BuildT3HandlesChart()BuildT3HandlesHTF()ComputeT3Series()EffectiveCapital()RealizedPnLToday()RealizedPnLThisWeek()- ...and 21 more
INTERNAL CONSTANTS (0 total):
INPUT PARAMETERS (40 total across 8 groups):
- [=== T3 Signal ===]
InpT3Period= 14 // T3EMAperiod (bars) - [=== T3 Signal ===]
InpT3VolumeFactor=0.7// T3 volume factor v (0..1) - [=== T3 Signal ===]
InpT3Price= 5 // Applied price (1=close,2=open,3=high,4=low,5=median,6=typical,7=weighted) // T3 applied price - [=== T3 Signal ===]
InpT3TF= 0 //Timeframe(1=M1,2=M5,3=M15,4=M30,5=H1,6=H4,7=D1) // T3 timeframe (chart if current) - [=== T3 Signal ===]
InpT3SlopeBars= 2 // Min consecutive slope bars in direction - [===
HTFConfirmation ===]InpHTF= 8 //Timeframe(1=M1,2=M5,3=M15,4=M30,5=H1,6=H4,7=D1) // Higher-timeframe T3 trend - [===
HTFConfirmation ===]InpUseHTF=true// RequireHTFT3 agreement - [=== Regime Filter ===]
InpADXPeriod= 14 //ADXperiod (bars) - [=== Regime Filter ===]
InpMinADX=20.0// MinADXforStrongTrendentry - [=== Regime Filter ===]
InpATRPeriod= 14 //ATRperiod (bars) - [=== Regime Filter ===]
InpATRPctLookback= 50 //ATRpercentile lookback (bars) - [=== Regime Filter ===]
InpATRPctMin=30.0// MinATRpercentile to trade (%) - [=== Regime Filter ===]
InpBBPeriod= 20 // Bollinger period (bars) - [=== Regime Filter ===]
InpBBDev=2.0// Bollinger stddev - [=== Entry / Risk ===]
InpRiskPercent=0.5// Risk per trade (% of effective capital) - [=== Entry / Risk ===]
InpSLATR=1.5// Stop lossATRmultiplier - [=== Entry / Risk ===]
InpTPATR=3.0// Take profitATRmultiplier - [=== Entry / Risk ===]
InpMinRR=1.5// Min required reward:risk ratio - [=== Entry / Risk ===]
InpMaxConcurrent= 1 // Max concurrent positions (this magic) - [=== Entry / Risk ===]
InpMaxSymbolPos= 1 // Max positions on this symbol - [=== Capital Allocation Cap ===]
InpCapitalCapAmount=0.0// Cap on real-money equity ($) - [=== Capital Allocation Cap ===]
InpCapitalCapFloor=50.0// Floor below which new entries blocked ($) - [=== Capital Allocation Cap ===]
InpDailyLossLimitPct=3.0// Max daily loss (% effective cap) - [=== Capital Allocation Cap ===]
InpWeeklyLossLimitPct=6.0// Max weekly loss (% effective cap) - [=== Capital Allocation Cap ===]
InpCooldownAfterLosses= 3 // Cooldown after N consecutive losses (bars*0 = off) - [=== Trade Management ===]
InpBreakevenAtR=1.0// Move to breakeven at R-multiple - [=== Trade Management ===]
InpPartialTPR=1.0// Partial close at R-multiple (0=off) - [=== Trade Management ===]
InpPartialTPPct=50.0// Partial close volume % - [=== Trade Management ===]
InpTrailATR=2.0//ATRtrailing multiplier (0=off) - [=== Trade Management ===]
InpTrailATRStep=0.5//ATRtrailing step (min move) - [=== Trade Management ===]
InpMaxBarsInTrade= 0 // Max bars in trade (0=disabled) - [=== Exec / Filters ===]
InpMaxSpreadPips=3.0// Max spread (pips) - [=== Exec / Filters ===]
InpSlippagePoints= 30 //Slippage(points) - [=== Exec / Filters ===]
InpSessionStartHour= 7 // Session start hour (server time, 0-23) - [=== Exec / Filters ===]
InpSessionEndHour= 21 // Session end hour (server time, 0-23) - [=== Exec / Filters ===]
InpAvoidFridayLate=true// Block entries late Friday - [=== System ===]
InpMagic=22218069// Magic number - [=== System ===]
InpTradeComment= "Psgrowth.com Expert_18069" // Trade comment - [=== System ===]
InpDryRun=true// Dry-run: no live sends - [=== System ===]
InpKillSwitch=false// Kill switch (hard stop)
// Pipsgrowth EX18069 TrendFollow — Execution Flow (from source analysis)
// Family: TrendFollow
// T3 (Tillson) is inlined from nested EMA primitives using the generalized-difference (GD) form: GD = EMA(P)*(1+v)- EMA(EMA(P))*v, T3 = GD(GD(GD(P))). Direction flip on the LAST CLOSED bar (shift=1) is the core signal; agreement with HTF T3 slope + closed-bar price side provides confirmation. Entries gated by ADX/ATR-pct/BB-width regime, session/spread filters, capital-allocation-cap, ATR-based hard SL/TP, break-even + partial TP + ATR trail. 12 layers: REGIME, SIGNAL, ENTRY, CONFIRM, NO-TRADE, CAPITAL CAP, RISK, SIZING, MANAGE, EXIT, SCALING, OnTester
ON_INIT:
Create indicator handles: ATR, ADX, BB
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 |
|---|---|---|
| InpT3Period | 14 | T3 EMA period (bars) |
| InpT3VolumeFactor | 0.7 | T3 volume factor v (0..1) |
| InpT3Price | 5 | Applied price (1=close,2=open,3=high,4=low,5=median,6=typical,7=weighted) // T3 applied price |
| InpT3TF | 0 | Timeframe (1=M1,2=M5,3=M15,4=M30,5=H1,6=H4,7=D1) // T3 timeframe (chart if current) |
| InpT3SlopeBars | 2 | Min consecutive slope bars in direction |
| InpHTF | 8 | Timeframe (1=M1,2=M5,3=M15,4=M30,5=H1,6=H4,7=D1) // Higher-timeframe T3 trend |
| InpUseHTF | true | Require HTF T3 agreement |
| InpADXPeriod | 14 | ADX period (bars) |
| InpMinADX | 20.0 | Min ADX for StrongTrend entry |
| InpATRPeriod | 14 | ATR period (bars) |
| InpATRPctLookback | 50 | ATR percentile lookback (bars) |
| InpATRPctMin | 30.0 | Min ATR percentile to trade (%) |
| InpBBPeriod | 20 | Bollinger period (bars) |
| InpBBDev | 2.0 | Bollinger stddev |
| InpRiskPercent | 0.5 | Risk per trade (% of effective capital) |
| InpSLATR | 1.5 | Stop loss ATR multiplier |
| InpTPATR | 3.0 | Take profit ATR multiplier |
| InpMinRR | 1.5 | Min required reward:risk ratio |
| InpMaxConcurrent | 1 | Max concurrent positions (this magic) |
| InpMaxSymbolPos | 1 | Max positions on this symbol |
| InpCapitalCapAmount | 0.0 | Cap on real-money equity ($) |
| InpCapitalCapFloor | 50.0 | Floor below which new entries blocked ($) |
| InpDailyLossLimitPct | 3.0 | Max daily loss (% effective cap) |
| InpWeeklyLossLimitPct | 6.0 | Max weekly loss (% effective cap) |
| InpCooldownAfterLosses | 3 | Cooldown after N consecutive losses (bars*0 = off) |
| InpBreakevenAtR | 1.0 | Move to breakeven at R-multiple |
| InpPartialTPR | 1.0 | Partial close at R-multiple (0=off) |
| InpPartialTPPct | 50.0 | Partial close volume % |
| InpTrailATR | 2.0 | ATR trailing multiplier (0=off) |
| InpTrailATRStep | 0.5 | ATR trailing step (min move) |
| InpMaxBarsInTrade | 0 | Max bars in trade (0=disabled) |
| InpMaxSpreadPips | 3.0 | Max spread (pips) |
| InpSlippagePoints | 30 | Slippage (points) |
| InpSessionStartHour | 7 | Session start hour (server time, 0-23) |
| InpSessionEndHour | 21 | Session end hour (server time, 0-23) |
| InpAvoidFridayLate | true | Block entries late Friday |
| InpMagic | 22218069 | Magic number |
| InpTradeComment | "Psgrowth.com Expert_18069" | Trade comment |
| InpDryRun | true | Dry-run: no live sends |
| InpKillSwitch | false | Kill switch (hard stop) |
#property copyright "Pipsgrowth.com"
#property link "https://pipsgrowth.com"
#property version "2.00"
#property strict
#property description "Pipsgrowth.com EX18069 T3_Expert — T3 (Tillson) Trend-Follow EA, 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 |
//+------------------------------------------------------------------+
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_InpT3TF = PERIOD_H1;
ENUM_TIMEFRAMES g_InpHTF = PERIOD_H1;
ENUM_APPLIED_PRICE g_InpT3Price = PRICE_CLOSE;
input group "=== T3 Signal ==="
input int InpT3Period = 14; // T3 EMA period (bars)
input double InpT3VolumeFactor = 0.7; // T3 volume factor v (0..1)
input int InpT3Price = 5; // Applied price (1=close,2=open,3=high,4=low,5=median,6=typical,7=weighted) // T3 applied price
input int InpT3TF = 0; // Timeframe (1=M1,2=M5,3=M15,4=M30,5=H1,6=H4,7=D1) // T3 timeframe (chart if current)
input int InpT3SlopeBars = 2; // Min consecutive slope bars in direction
ENUM_TIMEFRAMES MapTimeframeInt(int tf)
{
switch(tf)
{
case 1: return PERIOD_M1;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.