Pipsgrowth EX18113 TrendFollow
MT5 Expert Advisor (Open Source) · USDJPY · M5
Pipsgrowth.com EX18113 PipsGrowth_EA_USDJPYm — USDJPY M5 multi-indicator scalper, full 12-layer stack.
Overview
Pipsgrowth EX18113 is a USDJPY M5 multi-indicator scalper built around EMA(9/21) crossovers, with six separate confirmations stacked on top of every entry. The .mq5 file declares version 2.00, magic 22218113, and a 12-layer architecture spanning regime, signal, entry, confirm, no-trade, capital cap, risk, sizing, manage, exit, scaling, and OnTester — though the actual code is closer to ten functional layers (the regime filter is the True Hull MA slope via IsEMASlopeFlat, and there is no OnTester pass-through in this build; the trailing and pyramid blocks carry the manage and scaling roles).
The signal fires on closed-bar EMA crossings. CheckEntrySignals reads emaFast at bar 1 and bar 2 plus emaSlow at bar 1 and bar 2; a bullish cross is registered when bar-2 fast is at-or-below slow AND bar-1 fast is strictly above slow (and vice versa for shorts). Once a cross is detected, the EA does not just enter — it routes the trade through ValidateBuyFilters or ValidateSellFilters, which is a six-check consensus gate. First, the True Hull MA on the current timeframe must agree with direction (g_hullFast > g_hullSlow for longs). Second, the same relationship must hold on the higher timeframe (g_hullFastHTF > g_hullSlowHTF), where the higher timeframe is selected by the InpHTF dropdown (1–7 mapping to M1/D1, default H1). Third, the fast EMA slope over the last two bars must clear InpEMASlopeMin = 0.05 points/bar to avoid flat / chop regimes. Fourth, the daily pivot S/R filter rejects entries within InpSRProximity = 50 points of R1/R2 for buys and S1/S2 for sells. Fifth, the volume filter reads the 20-bar tick volume average and rejects when the last bar's volume is below 0.8x that average. Sixth, RSI(14) and MACD(12,26,9) histogram must agree on direction, ADX(14) must be at or above InpADX_Min = 25, and ATR(14) must be at or above InpATR_MinVol = 0.0005 to guarantee a live market.
A standout design choice is the True Hull MA. MT5 does not ship a built-in Hull indicator, so the .mq5 builds one from two LWMA handles per period: WMA(N) and WMA(N/2). CalculateHullMA computes rawHull = 2 * WMA(N/2) - WMA(N), then instead of the textbook WMA(rawHull, sqrt(N)) (which can't be expressed in nested LWMA handles), it smooths by averaging sqrt(N) recent rawHull values across the same bar shifts. This approximation is applied to four periods — fast and slow on the current TF, fast and slow on the higher TF — so the file allocates eight LWMA handles (hHull_WMA_N_Fast, hHull_WMA_N2_Fast, hHull_WMA_N_Slow, hHull_WMA_N2_Slow, plus the HTF mirror set) before any of the standard filter handles. The two EMA handles, the four filter handles (RSI, ADX, ATR, MACD), and the eight Hull handles total fourteen indicator handles, which is heavier than the typical TrendFollow sibling.
Risk is sized by CalculateLotSize, which defaults to 1% of balance via the formula lots = balance * 0.01 / ((slPoints * point / tickSize) * tickValue), floored to the lot step, clamped between the symbol's min and max, and snapped to two decimals. With InpFixedLot = 0 the EA is auto-risk; setting InpFixedLot = 0.01 switches to a fixed 0.01 lot per leg. The EA caps total positions at 3 (InpMaxPositions) and per-direction at 2 (InpMaxPosPerDir), but the pyramid block relaxes the per-direction cap to InpMaxPyramid = 5 legs on each side provided every existing leg on that side is in profit AND the latest leg is at least InpPyramidMinProfit = 30 points in the money. The pyramid uses a multiplicative size formula: lots = baseLot * MathPow(InpPyramidMultiplier, currentCount), so a 1.0 multiplier keeps legs equal, while 1.2 would scale up. SL and TP are static at InpStopLossPoints = 200 and InpTakeProfitPoints = 400 — a 1:2 risk-reward in JPY terms (20 / 40 pips).
Management is two-stage. ManagePositions runs every tick: once a position is at least InpBreakevenPoints = 50 points in the money, the stop is moved to entry + InpBreakevenOffset = 10 points (entry − 10 for shorts). Once profit reaches InpTrailingPoints = 100, the stop is ratcheted to currentPrice − 100 points (or + 100 for shorts) provided the new stop is tighter than the existing one. All modifications go through TryModify_EX18113, a 3-attempt retry wrapper that backs off 100 ms on requote or timeout. Exits are also driven by CheckExitSignals, which runs on each new bar: a reverse EMA cross flattens the opposite side via ClosePositionsByType, and an RSI extreme with realized profit (ClosePositionsAtExtreme) closes winners in that direction. There is no time-based exit.
The safety stack adds three more guards. IsDrawdownExceeded pauses new entries when equity drawdown from the all-time peak (g_peakEquity, updated on every tick) exceeds InpMaxDDPercent = 20%. IsWithinSession only allows trades when the server hour falls in the InpSessionStart–InpSessionEnd window, with the default 2-21 wrapping midnight for an Asia-through-NY book. The news filter is gated by InpUseNewsFilter = false; when enabled, LoadNewsEvents parses news_events.csv (date, time, currency, impact) and IsNearNews vetoes entries whose time falls within InpNewsBefore = 30 minutes before or InpNewsAfter = 15 minutes after a USD or JPY event. If the file is missing, CreateSampleNewsFile writes a header plus 2026 NFP, FOMC, and BOJ dates as a starting point.
The dashboard sits in the top-left corner as a 200x230 dark-slate-gray rectangle with thirteen labels — title, signal, EMA, Hull, RSI, ADX, pivot PP, position count, realized P/L, spread, volume, session status, news status. It refreshes every tick via ChartRedraw, which is unusual for an M5 strategy; expect CPU usage to track spread update frequency. Chart visuals add a dashed cyan line at the Hull Fast value and a dashed magenta line at the Hull Slow value (UpdateChartVisuals re-draws them on every new bar). When InpShowPivots is on, DrawPivotLines renders the daily PP in solid gold with R1/R2 in dotted red and S1/S2 in dotted green, recalculated at the day rollover from yesterday's D1 high, low, and close.
In backtesting on USDJPY M5, expect trade frequency of 5–15 entries per London–NY day when the trend regime is active and the consensus gate clears; flat Asia sessions produce very few signals because of the 2-21 session window and the ADX floor. The pyramid can stack five legs on a single impulsive USDJPY move, so the largest winning streaks will outsize the largest losing streaks 1.5–2x — but the 5-leg cap on each side plus the 20% drawdown pause should keep worst-case equity drift within bounds. As always, run the EA in Strategy Tester visual mode for at least a month before going live, and confirm the broker allows ORDER_FILLING_IOC for USDJPY (the EA hardcodes IOC in trade.SetTypeFilling).
Strategy Deep Dive
On every tick, UpdateDashboard refreshes a 13-label panel and ManagePositions iterates open positions to apply breakeven at 50 points and a 100-point trailing ratchet through TryModify_EX18113. On each new bar, IsNewBar returns true, the EA updates cached True Hull values via UpdateHullValues, recalculates daily pivots at the day rollover, refreshes the 20-bar volume average, and re-draws chart visuals; it then runs CheckExitSignals, checks for a pyramid leg via CheckPyramidOpportunity, and finally calls CheckEntrySignals. The entry path reads emaFast and emaSlow at bar 1 and bar 2 to detect a crossover on the just-closed bar; the cross is then validated by six sequential filters — current-TF and HTF Hull direction, EMA slope, daily-pivot S/R distance, volume ratio, plus the RSI / MACD / ADX / ATR / spread / session / news consensus. The True Hull construction is unusual: MT5 has no built-in Hull, so the .mq5 spawns eight LWMA handles (WMA(N) and WMA(N/2) on each timeframe × fast/slow) and approximates the textbook WMA(rawHull, sqrt(N)) smoothing by averaging sqrt(N) recent rawHull values. Pyramid legs reuse the same filter gates and require every existing leg on that side to be in profit before opening the next one.
Entries trigger on a closed-bar EMA(9/21) crossover confirmed by a six-gate consensus: True Hull MA fast > slow on both the current and higher timeframe, ADX(14) ≥ 25, MACD histogram matching direction, RSI(14) not extreme, ATR(14) ≥ 0.0005, current tick volume ≥ 0.8x of the 20-bar average, daily-pivot S/R distance > 50 points, EMA slope > 0.05 pts/bar, server-hour session active, and an optional news-time veto within 30 minutes before / 15 minutes after a USD or JPY event.
Exits fire on a new-bar EMA reverse cross (flattens the opposite side via ClosePositionsByType), or when RSI(14) prints an overbought/oversold reading AND the position is at least 50 points in the money (ClosePositionsAtExtreme). Hard SL and TP are server-side at 200 / 400 points = 20 / 40 JPY-pips, and any open position is also subject to the trailing-stop and breakeven legs of ManagePositions on every tick.
Per-trade stop is 200 points (20 JPY-pips) below entry for longs, mirrored for shorts. ManagePositions additionally tightens to breakeven + 10 points once profit reaches 50 points, and ratchets to a 100-point trailing stop once profit reaches 100 points. IsDrawdownExceeded pauses new entries once equity drawdown from the all-time peak exceeds 20%.
Fixed take-profit at 400 points (40 JPY-pips) above entry for longs, mirrored for shorts — a hard 1:2 risk-reward. The pyramid can stack up to 5 winning legs in the same direction before the side reverses, multiplying the realized take-profit rollup but not the per-leg TP itself.
USDJPY M5 only — the EA hardcodes a USDJPY string-match warning in OnInit and a 200/400-point fixed stop that scales to 20/40 JPY-pips. Minimum recommended balance is $100 to keep 1% risk (≈$1 per leg) viable on a 0.01-lot base, with the pyramid allowed to scale up to five 0.01-lot legs on each side. Server time defaults to 02:00–21:00 (Asia-through-NY), so the active window covers Tokyo open, the London breakout, and the New York session. Use a low-spread ECN or RAW account — the spread cap is 30 points but typical USDJPY ECN spread is 5–10 points, and the IOC fill mode (ORDER_FILLING_IOC) requires a broker that supports IOC. Suitable for trend traders willing to accept the 1:2 R:R profile and the multi-gate filter miss-rate.
Strategy Logic
Pipsgrowth EX18113 TrendFollow — Strategy Logic Analysis (from .mq5 source)
Family: TrendFollow
Magic: 22218113
Version: 2.00
BRIEF:
USDJPY M5 scalping EA using EMA crossover, Hull MA, RSI, ADX, ATR, and MACD for multi-indicator consensus. Features multi-timeframe confirmation, pyramiding, session/news/S-R filters, volume filter, trailing stop, and breakeven. 12 layers: REGIME, SIGNAL, ENTRY, CONFIRM, NO-TRADE, CAPITAL CAP, RISK, SIZING, MANAGE, EXIT, SCALING, OnTester
INDICATOR STACK:
- Standard
MT5indicators
KEY FUNCTIONS:
IsNewBar()LogBarInfo()GetIndicatorValue()CheckEntrySignals()ValidateBuyFilters()ValidateSellFilters()IsWithinSession()LoadNewsEvents()CreateSampleNewsFile()IsNearNews()IsDrawdownExceeded()CountPositions()- ...and 27 more
INTERNAL CONSTANTS (0 total):
INPUT PARAMETERS (48 total across 13 groups):
- [=== Risk Management ===]
InpRiskPercent=1.0// Risk per trade (%) [1-2] - [=== Risk Management ===]
InpFixedLot=0.0// Fixed lot (0=auto-risk) - [=== Risk Management ===]
InpMaxPositions= 3 // Max total positions - [=== Risk Management ===]
InpMaxPosPerDir= 2 // Max positions per direction - [=== Risk Management ===]
InpStopLossPoints= 200 // StopLoss(points) - [=== Risk Management ===]
InpTakeProfitPoints= 400 // TakeProfit(points) - [=== Risk Management ===]
InpTrailingPoints= 100 // TrailingStop(points) - [=== Risk Management ===]
InpBreakevenPoints= 50 // Breakeven trigger (points) - [=== Risk Management ===]
InpBreakevenOffset= 10 // Breakeven offset (points) - [=== Risk Management ===]
InpMaxDDPercent=20.0// Max Drawdown to pause (%) - [===
EMASettings ===]InpEMA_Fast= 9 // FastEMAPeriod [step=1] - [===
EMASettings ===]InpEMA_Slow= 21 // SlowEMAPeriod [step=1] - [=== Hull MA Settings ===]
InpHull_Fast= 20 // Hull Fast Period [step=5] - [=== Hull MA Settings ===]
InpHull_Slow= 50 // Hull Slow Period [step=5] - [=== Filter Indicators ===]
InpRSI_Period= 14 //RSIPeriod - [=== Filter Indicators ===]
InpRSI_OB= 70 //RSIOverbought [step=5] - [=== Filter Indicators ===]
InpRSI_OS= 30 //RSIOversold [step=5] - [=== Filter Indicators ===]
InpADX_Period= 14 //ADXPeriod - [=== Filter Indicators ===]
InpADX_Min= 25 //ADXMinimum Trend [step=5] - [=== Filter Indicators ===]
InpATR_Period= 14 //ATRPeriod - [=== Filter Indicators ===]
InpATR_MinVol=0.0005//ATRMinimum Volatility - [=== Filter Indicators ===]
InpMACD_Fast= 12 //MACDFast - [=== Filter Indicators ===]
InpMACD_Slow= 26 //MACDSlow - [=== Filter Indicators ===]
InpMACD_Signal= 9 //MACDSignal - [=== Multi-Timeframe ===]
InpHTF= 8 //Timeframe(1=M1,2=M5,3=M15,4=M30,5=H1,6=H4,7=D1) // Higher Timeframe - [=== Pyramid Settings ===]
InpMaxPyramid= 5 // Max Pyramid Positions - [=== Pyramid Settings ===]
InpPyramidMinProfit= 30 // Min Profit forPyramid(points) - [=== Pyramid Settings ===]
InpPyramidMultiplier=1.0// LotMultiplier(1.0=fixed) - [=== Session
Filter(Server Time) ===]InpSessionStart= 2 // Session Start Hour - [=== Session
Filter(Server Time) ===]InpSessionEnd= 21 // Session End Hour - [=== News Filter ===]
InpNewsBefore= 30 // Minutes Before News - [=== News Filter ===]
InpNewsAfter= 15 // Minutes After News - [=== News Filter ===]
InpUseNewsFilter=false// Enable News Filter - [=== News Filter ===]
InpNewsFile= "news_events.csv" // News Events File - [=== S/R Filter ===]
InpUseSRFilter=true// Enable S/R Filter - [=== S/R Filter ===]
InpSRProximity= 50 // S/RProximity(points) - [=== S/R Filter ===]
InpShowPivots=true// Show Pivot Lines - [===
EMASlope Filter ===]InpEMASlopeMin=0.05// MinEMASlope(points/bar) [0.05-5 step0.05] - [=== Volume Filter ===]
InpUseVolumeFilter=true// Enable Volume Filter - [=== Volume Filter ===]
InpVolumePeriod= 20 // Volume MA Period - [=== Volume Filter ===]
InpVolumeMultiplier=0.8// Min Volume vs Avg - [=== Visual Settings ===]
InpShowIndicators=true// Show Indicators on Chart - [=== Visual Settings ===]
InpBuyColor=clrLime// Buy Signal Color - [=== Visual Settings ===]
InpSellColor=clrRed// Sell Signal Color - [=== Visual Settings ===]
InpPivotColor=clrGold// Pivot Line Color - [=== System ===]
InpMagicNumber=22218113// Magic number - [=== System ===]
InpMaxSpread=30.0// MaxSpread(points) - [=== System ===]
InpSlippage= 10 //Slippage(points)
// Pipsgrowth EX18113 TrendFollow — Execution Flow (from source analysis)
// Family: TrendFollow
// USDJPY M5 scalping EA using EMA crossover, Hull MA, RSI, ADX, ATR, and MACD for multi-indicator consensus. Features multi-timeframe confirmation, pyramiding, session/news/S-R filters, volume filter, trailing stop, and breakeven. 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 |
|---|---|---|
| InpRiskPercent | 1.0 | Risk per trade (%) [1-2] |
| InpFixedLot | 0.0 | Fixed lot (0=auto-risk) |
| InpMaxPositions | 3 | Max total positions |
| InpMaxPosPerDir | 2 | Max positions per direction |
| InpStopLossPoints | 200 | Stop Loss (points) |
| InpTakeProfitPoints | 400 | Take Profit (points) |
| InpTrailingPoints | 100 | Trailing Stop (points) |
| InpBreakevenPoints | 50 | Breakeven trigger (points) |
| InpBreakevenOffset | 10 | Breakeven offset (points) |
| InpMaxDDPercent | 20.0 | Max Drawdown to pause (%) |
| InpEMA_Fast | 9 | Fast EMA Period [step=1] |
| InpEMA_Slow | 21 | Slow EMA Period [step=1] |
| InpHull_Fast | 20 | Hull Fast Period [step=5] |
| InpHull_Slow | 50 | Hull Slow Period [step=5] |
| InpRSI_Period | 14 | RSI Period |
| InpRSI_OB | 70 | RSI Overbought [step=5] |
| InpRSI_OS | 30 | RSI Oversold [step=5] |
| InpADX_Period | 14 | ADX Period |
| InpADX_Min | 25 | ADX Minimum Trend [step=5] |
| InpATR_Period | 14 | ATR Period |
| InpATR_MinVol | 0.0005 | ATR Minimum Volatility |
| InpMACD_Fast | 12 | MACD Fast |
| InpMACD_Slow | 26 | MACD Slow |
| InpMACD_Signal | 9 | MACD Signal |
| InpHTF | 8 | Timeframe (1=M1,2=M5,3=M15,4=M30,5=H1,6=H4,7=D1) // Higher Timeframe |
| InpMaxPyramid | 5 | Max Pyramid Positions |
| InpPyramidMinProfit | 30 | Min Profit for Pyramid (points) |
| InpPyramidMultiplier | 1.0 | Lot Multiplier (1.0=fixed) |
| InpSessionStart | 2 | Session Start Hour |
| InpSessionEnd | 21 | Session End Hour |
| InpNewsBefore | 30 | Minutes Before News |
| InpNewsAfter | 15 | Minutes After News |
| InpUseNewsFilter | false | Enable News Filter |
| InpNewsFile | "news_events.csv" | News Events File |
| InpUseSRFilter | true | Enable S/R Filter |
| InpSRProximity | 50 | S/R Proximity (points) |
| InpShowPivots | true | Show Pivot Lines |
| InpEMASlopeMin | 0.05 | Min EMA Slope (points/bar) [0.05-5 step 0.05] |
| InpUseVolumeFilter | true | Enable Volume Filter |
| InpVolumePeriod | 20 | Volume MA Period |
| InpVolumeMultiplier | 0.8 | Min Volume vs Avg |
| InpShowIndicators | true | Show Indicators on Chart |
| InpBuyColor | clrLime | Buy Signal Color |
| InpSellColor | clrRed | Sell Signal Color |
| InpPivotColor | clrGold | Pivot Line Color |
| InpMagicNumber | 22218113 | Magic number |
| InpMaxSpread | 30.0 | Max Spread (points) |
| InpSlippage | 10 | Slippage (points) |
#property copyright "Pipsgrowth.com"
#property link "https://pipsgrowth.com"
#property version "2.00"
#property strict
#property description "Pipsgrowth.com EX18113 PipsGrowth_EA_USDJPYm — USDJPY M5 multi-indicator scalper, full 12-layer stack."
#include <Trade\AccountInfo.mqh>
#include <Trade\PositionInfo.mqh>
#include <Trade\Trade.mqh>
//+------------------------------------------------------------------+
//| INPUT PARAMETERS - ALL OPTIMIZABLE |
//+------------------------------------------------------------------+
// Risk Management
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_InpHTF = PERIOD_H1;
input group "=== Risk Management ==="
input double InpRiskPercent = 1.0; // Risk per trade (%) [1-2]
input double InpFixedLot = 0.0; // Fixed lot (0=auto-risk)
input int InpMaxPositions = 3; // Max total positions
input int InpMaxPosPerDir = 2; // Max positions per direction
input int InpStopLossPoints = 200; // Stop Loss (points)
input int InpTakeProfitPoints = 400; // Take Profit (points)
input int InpTrailingPoints = 100; // Trailing Stop (points)
input int InpBreakevenPoints = 50; // Breakeven trigger (points)
input int InpBreakevenOffset = 10; // Breakeven offset (points)
input double InpMaxDDPercent = 20.0; // Max Drawdown to pause (%)
// Signal Parameters - OPTIMIZABLE
ENUM_TIMEFRAMES MapTimeframeInt(int tf)
{
switch(tf)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.