Pipsgrowth EX16005 Trend
MT5 Expert Advisor (Open Source) · XAUUSD, EURUSD, GBPUSD, USDJPY · M15, M30
Pipsgrowth.com EX16005 ADX_EA — ADX Trend-Following EA, full 12-layer stack.
Overview
Pipsgrowth EX16005 Trend is a Welles-Wilder-style directional-movement EA that only trades when trend strength, direction, and regime filter all agree on the same bar. Instead of guessing whether a market is trending, the EA asks the Average Directional Index (ADX) for a number — when ADX(14) climbs above the InpADXMin threshold (22.0 by default), the strategy treats that as evidence that a real move is in progress and not random noise. From there, the +DI and -DI lines decide which way that move is heading, and a 50-period EMA on close decides whether the bar agrees with the regime at all. The result is a tight three-condition AND gate that produces fewer but cleaner setups than a single-indicator trend follower.
The signal stack is intentionally minimal. The OnInit routine opens exactly two handles: hADX = iADX(_Symbol, _Period, InpADXPeriod=14) and hEMA = iMA(_Symbol, _Period, InpEMAPeriod=50, 0, MODE_EMA, PRICE_CLOSE). There is no MACD, no Stochastic, no Bollinger, no multi-timeframe read, and no external indicator calls. Inside CheckSignal(), the EA pulls ADX main line, +DI, and -DI from buffer index 1 (the just-closed bar) along with the EMA value, then reads close[1] for the final regime check. The BUY branch is g_adx > InpADXMin && g_plusDI > g_minusDI && close1 > g_ema; the SELL branch mirrors with -DI > +DI && close < EMA. Because all three values come from bar[1] rather than bar[0], the entry fires on the open of the next bar — no repaint, no mid-bar whipsaw.
Position management is a two-stage ratchet handled in ManageOpenPositions() every tick. Stage one is a breakeven: when profit reaches InpBEStart=300 points, the stop is moved to openPrice ± InpBEOffset=30 points (a 30-point buffer above entry to absorb spread plus a small slippage cushion). Stage two is the trail: once profit reaches InpTrailStart=400 points, the stop ratchets to price − InpTrailDistance=200 points (or price + 200 for sells), with a guard that the new stop must stay above the original open price so the trade can never be stopped out at a loss once it has been moved. The active SL is whichever is higher of the BE stop and the trail stop, and the move is pushed to the broker through TryModify_EX16005 — a three-attempt retry wrapper that re-quotes the modification on REQUOTE, TIMEOUT, PRICE_OFF, and PRICE_CHANGED with 100ms Sleeps between attempts.
Risk is governed by two parallel caps inside CheckDrawdownLimits(). The first is the daily loss: at the start of every server day (CheckNewDay rolls g_dailyStartBalance from account.Balance() at midnight), the EA computes g_dailyStartBalance - currentBalance and trips g_ddLimitHit=true once the loss reaches InpMaxDailyLoss=3.0%. The second is the equity drawdown from peak: g_peakEquity is updated every tick to the running max, and once (peak - equity) / peak reaches InpMaxEquityLoss=10.0%, the trip fires again. Either trip blocks all new entries through the g_ddLimitHit gate at the top of CheckDrawdownLimits, and — because InpCloseOnDDLimit=true by default — also forces CloseAllPositions() via TryClose_EX16005, which is the same 3-attempt retry wrapper used by the trailing path. The trip resets the next day at server midnight through CheckNewDay. A 250-point spread cap (InpMaxSpread) is the first thing OnTick checks, before even the time filter, so the EA never enters a wide market.
Pyramiding is on by default (InpEnablePyramid=true, InpMaxPositions=3). The IsGridSafe() guard walks the open-position list and refuses to add a new entry unless every existing in-direction position is already in profit by at least InpMinProfitPoints=300. This makes the pyramid a 'pyramid-into-strength' rather than a 'pyramid-into-loss' design: the EA will not average down, but it will scale into a winning trend up to three positions in the same direction. The first position uses the standard lot from CalculateLotSize (0.5% risk × balance / SL loss per lot, floored to lotStep and clamped to vol_min/vol_max/InpMaxLotSize=5.0); subsequent pyramid entries use the same sizing rule rather than a martingale multiplier. CalculateLotSize also calls OrderCalcMargin() before the trade is sent, so a request that exceeds free margin is refused with a Print error rather than a broker rejection.
Time and session control is optional. InpUseTimeFilter is false by default, which means the EA trades whenever the symbol is open and the spread is below the cap. When the operator flips it on, CheckTimeFilter() blocks Saturday and Sunday outright, refuses entries outside the InpStartHour=8 to InpEndHour=20 server-hour window, and adds a Friday close-all at InpFridayCloseHour=20 (the EA calls CloseAllPositions() the moment the clock hits 20:00 on day_of_week==5). For most retail brokers, the default-off time filter makes sense because the M15/M30 cadence already filters the worst late-Asian illiquidity, but operators who run this EA on XAUUSD during thin sessions will want to enable it.
On the operational side, OnInit calls SetProperFillingMode() to auto-detect whether the broker supports ORDER_FILLING_FOK, ORDER_FILLING_IOC, or ORDER_FILLING_RETURN, and sets the CTrade object accordingly. OpenPosition() retries up to InpMaxRetries=3 times on REQUOTE/PRICE_CHANGED/PRICE_OFF/TIMEOUT with 100ms Sleeps and a RefreshRates between attempts, and the order is sent with the trade-comment string 'Psgrowth.com Expert_16005' so positions are easy to identify in the journal. The on-chart info panel is a 220×180 dark-slate OBJ_RECTANGLE_LABEL with eight OBJ_LABEL lines (title, magic, ADX with strength label, +DI, -DI, BULLISH/BEARISH trend, buy/sell counts, and running P/L) drawn at InpPanelX/InpPanelY. OnDeinit releases both indicator handles and calls ObjectsDeleteAll(0, 'EA_') so the panel never lingers after the EA is removed.
What an operator actually sees in forward testing: a low trade frequency (ADX only crosses 22 a handful of times per week on M15, and only half of those passes the regime filter), a high proportion of winners because entries are gated by trend strength, and the occasional large runner when a 500-point SL trade becomes a 1500-point TP trade through the trail. The fixed 1:3 RR (InpStopLoss=500 / InpTakeProfit=1500) gives the math a fighting chance even at a 40% win rate, and the 3%-daily / 10%-equity caps put a hard floor under catastrophic sequences. The EA is not a high-frequency system — it is a trend-quality filter with a 1:3 reward profile and a tight risk budget, and it should be sized and brokered accordingly.
Strategy Deep Dive
On every tick, OnTick first checks the spread cap (250 points), then the time filter if enabled, then the DD trip-wire, then runs ManageOpenPositions to ratchet any open SL. On the open of each new bar, CheckSignal pulls bar[1] values from the iADX(14) handle (main + DI lines) and the iMA(EMA,50) handle, applies the three-condition AND gate, and either opens a new position or — if a position already exists in the same direction and the pyramid gate passes (≤3 positions, IsGridSafe confirms every existing one is +300 points in profit) — adds a scaled-in entry. The single OnInit creates exactly two handles, the DD circuit is reset by CheckNewDay at server midnight, and OnDeinit releases both handles plus the chart panel.
Long entries fire when ADX(14) climbs above the InpADXMin threshold (22.0 by default), +DI is above -DI, and the previous bar's close sits above the 50-period EMA. Short entries are the mirror: ADX above threshold, -DI above +DI, close below EMA. All three values are read from bar[1], so the entry executes on the open of the next bar — no mid-bar repaint.
There is no fixed-take-profit close path — exits come from the 500-point SL on the order or the 200-point trailing stop once profit reaches 400 points. The breakeven moves the stop to entry + 30 points at 300 points of profit, so any exit after that point is at minimum scratch. The DD trip-wires force CloseAllPositions() when the 3% daily or 10% equity-from-peak threshold is breached.
Every order is sent with a hard InpStopLoss=500-point stop attached at open. ManageOpenPositions then ratchets that stop in two stages: at 300 points of profit the SL moves to entry + 30 points (breakeven with a 30-point buffer above entry), and at 400 points of profit the SL trails price by 200 points, never below the original entry price.
Every order is sent with a hard InpTakeProfit=1500-point target, giving a fixed 1:3 reward-to-risk ratio against the 500-point stop. Combined with the trailing ratchet, this means a typical trade either closes at +1500 points, gets trailed out, or hits the original 500-point stop — the EA does not invent TP from an indicator value.
Best paired with an ECN/RAW-spread broker on XAUUSD, EURUSD, GBPUSD, or USDJPY running M15 (works M15-M30) so the ADX reading has enough bars to settle. Minimum recommended balance: $100 — the 0.5% risk-per-trade default keeps a single 500-point SL well within a $100 account when sized to a 0.01-lot micro position. Sessions: the default-off time filter is fine for 24-hour FX pairs, but operators running XAUUSD should enable the 8-20 server-hour window to avoid late-Asian illiquidity. The 3%-daily / 10%-equity DD caps make this suitable for traders who want a hard circuit-breaker rather than discretionary override.
Strategy Logic
Pipsgrowth EX16005 Trend — Strategy Logic Analysis (from .mq5 source)
Family: Trend
Magic: 22216005
Version: 2.00
BRIEF:
ADX Trend-Following EA using ADX strength and DI crossovers. BUY: ADX > threshold + +DI > -DI + Price > EMA
INDICATOR STACK:
- Standard
MT5indicators
KEY FUNCTIONS:
SetProperFillingMode()CheckTimeFilter()CheckDrawdownLimits()CheckNewDay()CheckSignal()OpenPosition()IsGridSafe()ManageOpenPositions()CalculateLotSize()NormalizeLot()CountPositions()CloseAllPositions()- ...and 6 more
INTERNAL CONSTANTS (0 total):
INPUT PARAMETERS (34 total across 8 groups):
- [═══════════ Trade Execution ═══════════]
InpMagicNumber=22216005// MagicNumber(222 + Expert ID) - [═══════════ Trade Execution ═══════════]
InpSlippage= 30 // MaxSlippage(points) - [═══════════ Trade Execution ═══════════]
InpMaxSpread= 250 // MaxSpread(points, 0=disabled) - [═══════════ Trade Execution ═══════════]
InpMaxRetries= 3 // Order Retry Attempts - [═══════════ Trade Execution ═══════════]
InpTradeComment= "Psgrowth.com Expert_16005" // TradeComment - [═══════════ Money Management ═══════════]
InpRiskPercent=0.5// Risk % per Trade - [═══════════ Money Management ═══════════]
InpFixedLot=0.01// FixedLot(if Risk=0) - [═══════════ Money Management ═══════════]
InpMaxLotSize=5.0// Maximum Lot Size Cap - [═══════════ Money Management ═══════════]
InpStopLoss= 500 // StopLoss(points) - [═══════════ Money Management ═══════════]
InpTakeProfit= 1500 // TakeProfit(points) - [═══════════ Strategy Settings ═══════════]
InpADXPeriod= 14 //ADXPeriod - [═══════════ Strategy Settings ═══════════]
InpADXMin=22.0//ADXMinimum for Entry - [═══════════ Strategy Settings ═══════════]
InpEMAPeriod= 50 //EMAFilter Period - [═══════════ Time Filter ═══════════]
InpUseTimeFilter=false// Enable Time Filter - [═══════════ Time Filter ═══════════]
InpStartHour= 8 // StartHour(Server Time) - [═══════════ Time Filter ═══════════]
InpEndHour= 20 // EndHour(Server Time) - [═══════════ Time Filter ═══════════]
InpTradeFriday=true// Trade on Friday - [═══════════ Time Filter ═══════════]
InpFridayCloseHour= 20 // Close All Friday After - [═══════════ Trade Management ═══════════]
InpUseBreakeven=true// Enable Breakeven - [═══════════ Trade Management ═══════════]
InpBEStart= 300 // BEStart(points profit) - [═══════════ Trade Management ═══════════]
InpBEOffset= 30 // BEOffset(points above entry) - [═══════════ Trade Management ═══════════]
InpEnableTrail=true// Enable Trailing Stop - [═══════════ Trade Management ═══════════]
InpTrailStart= 400 // Trail StartDistance(points) - [═══════════ Trade Management ═══════════]
InpTrailDistance= 200 // Trail Distance behind price - [═══════════ Pyramid Settings ═══════════]
InpEnablePyramid=true// Enable Safe Pyramiding - [═══════════ Pyramid Settings ═══════════]
InpMaxPositions= 3 // Max Open Positions - [═══════════ Pyramid Settings ═══════════]
InpMinProfitPoints= 300 // MinProfit(points) for Next Entry - [═══════════ Drawdown Protection ═══════════]
InpUseDDProtection=true// Enable Drawdown Protection - [═══════════ Drawdown Protection ═══════════]
InpMaxDailyLoss=3.0// Max Daily Loss % (0=disabled) - [═══════════ Drawdown Protection ═══════════]
InpMaxEquityLoss=10.0// Max Equity Loss % from Peak - [═══════════ Drawdown Protection ═══════════]
InpCloseOnDDLimit=true// Close All When DD Limit Hit - [═══════════ Display ═══════════]
InpShowPanel=true// Show Info Panel - [═══════════ Display ═══════════]
InpPanelX= 10 // Panel X Position - [═══════════ Display ═══════════]
InpPanelY= 30 // Panel Y Position
// Pipsgrowth EX16005 Trend — Execution Flow (from source analysis)
// Family: Trend
// ADX Trend-Following EA using ADX strength and DI crossovers. BUY: ADX > threshold + +DI > -DI + Price > EMA
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 |
|---|---|---|
| InpMagicNumber | 22216005 | Magic Number (222 + Expert ID) |
| InpSlippage | 30 | Max Slippage (points) |
| InpMaxSpread | 250 | Max Spread (points, 0=disabled) |
| InpMaxRetries | 3 | Order Retry Attempts |
| InpTradeComment | "Psgrowth.com Expert_16005" | Trade Comment |
| InpRiskPercent | 0.5 | Risk % per Trade |
| InpFixedLot | 0.01 | Fixed Lot (if Risk=0) |
| InpMaxLotSize | 5.0 | Maximum Lot Size Cap |
| InpStopLoss | 500 | Stop Loss (points) |
| InpTakeProfit | 1500 | Take Profit (points) |
| InpADXPeriod | 14 | ADX Period |
| InpADXMin | 22.0 | ADX Minimum for Entry |
| InpEMAPeriod | 50 | EMA Filter Period |
| InpUseTimeFilter | false | Enable Time Filter |
| InpStartHour | 8 | Start Hour (Server Time) |
| InpEndHour | 20 | End Hour (Server Time) |
| InpTradeFriday | true | Trade on Friday |
| InpFridayCloseHour | 20 | Close All Friday After |
| InpUseBreakeven | true | Enable Breakeven |
| InpBEStart | 300 | BE Start (points profit) |
| InpBEOffset | 30 | BE Offset (points above entry) |
| InpEnableTrail | true | Enable Trailing Stop |
| InpTrailStart | 400 | Trail Start Distance (points) |
| InpTrailDistance | 200 | Trail Distance behind price |
| InpEnablePyramid | true | Enable Safe Pyramiding |
| InpMaxPositions | 3 | Max Open Positions |
| InpMinProfitPoints | 300 | Min Profit (points) for Next Entry |
| InpUseDDProtection | true | Enable Drawdown Protection |
| InpMaxDailyLoss | 3.0 | Max Daily Loss % (0=disabled) |
| InpMaxEquityLoss | 10.0 | Max Equity Loss % from Peak |
| InpCloseOnDDLimit | true | Close All When DD Limit Hit |
| InpShowPanel | true | Show Info Panel |
| InpPanelX | 10 | Panel X Position |
| InpPanelY | 30 | Panel Y Position |
#property copyright "Pipsgrowth.com"
#property link "https://pipsgrowth.com"
#property version "2.00"
#property strict
#property description "Pipsgrowth.com EX16005 ADX_EA — ADX Trend-Following EA, full 12-layer stack."
#include <Trade\Trade.mqh>
#include <Trade\PositionInfo.mqh>
#include <Trade\SymbolInfo.mqh>
#include <Trade\AccountInfo.mqh>
//+------------------------------------------------------------------+
//| INPUT GROUP: Trade Execution |
//+------------------------------------------------------------------+
input group "═══════════ Trade Execution ═══════════"
input int InpMagicNumber = 22216005; // Magic Number (222 + Expert ID)
input int InpSlippage = 30; // Max Slippage (points)
input int InpMaxSpread = 250; // Max Spread (points, 0=disabled)
input int InpMaxRetries = 3; // Order Retry Attempts
input string InpTradeComment = "Psgrowth.com Expert_16005"; // Trade Comment
//+------------------------------------------------------------------+
//| INPUT GROUP: Money Management |
//+------------------------------------------------------------------+
input group "═══════════ Money Management ═══════════"
input double InpRiskPercent = 0.5; // Risk % per Trade
input double InpFixedLot = 0.01; // Fixed Lot (if Risk=0)
input double InpMaxLotSize = 5.0; // Maximum Lot Size Cap
input int InpStopLoss = 500; // Stop Loss (points)
input int InpTakeProfit = 1500; // Take Profit (points)
//+------------------------------------------------------------------+
//| INPUT GROUP: Strategy Settings |
//+------------------------------------------------------------------+
input group "═══════════ Strategy Settings ═══════════"
input int InpADXPeriod = 14; // ADX Period
input double InpADXMin = 22.0; // ADX Minimum for Entry
input int InpEMAPeriod = 50; // EMA Filter Period
//+------------------------------------------------------------------+
//| INPUT GROUP: Time Filter |
//+------------------------------------------------------------------+
input group "═══════════ Time Filter ═══════════"
input bool InpUseTimeFilter = false; // Enable Time Filter
input int InpStartHour = 8; // Start Hour (Server Time)
input int InpEndHour = 20; // End Hour (Server Time)
input bool InpTradeFriday = true; // Trade on Friday
input int InpFridayCloseHour= 20; // Close All Friday After
//+------------------------------------------------------------------+
//| INPUT GROUP: Trade Management |
//+------------------------------------------------------------------+
input group "═══════════ Trade Management ═══════════"
input bool InpUseBreakeven = true; // Enable Breakeven
input int InpBEStart = 300; // BE Start (points profit)
input int InpBEOffset = 30; // BE Offset (points above entry)
input bool InpEnableTrail = true; // Enable Trailing Stop
input int InpTrailStart = 400; // Trail Start Distance (points)
input int InpTrailDistance = 200; // Trail Distance behind price
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.