Pipsgrowth EX18083 TrendFollow
MT5 Expert Advisor (Open Source) · XAUUSD, EURUSD · M5
Pipsgrowth.com EX18083 JMA_XAUUSD_5M — ATR-adaptive JMA trend EA with pyramiding, full 12-layer stack.
Overview
EX18083 is a single-file MT5 trend follower that builds its signal around a Hull Moving Average whose own period is allowed to breathe. The author calls it "JMA Adaptive" in the brief, but the implementation in GetSignal() is a classical HMA: HMA(period) = WMA(2*WMA(period/2) − WMA(period), sqrt(period)). The adaptive twist is that the period itself is rewritten every closed bar from a 30-bar ATR(30) ratio. The EA copies the last InpBasePeriod (30) ATR values, computes the mean, divides the mean by the most recent value, clamps the result to the [0.5, 2.0] band, and multiplies InpBasePeriod by that factor — yielding a final period in the 15–60 range depending on whether the market is hot or quiet. The HMA is then rebuilt from scratch on every bar inside CalculateHMA(), since the period is variable the code cannot cache a single iCustom buffer. Each rebuild reads roughly period + sqrt(period) + 10 closes and runs two WMA passes and one outer WMA over the resulting difference series.
With the HMA in hand, GetSignal() looks at the HMA on the just-closed bar (shift 1) and the bar before that (shift 2). A simple slope test — hma1 > hma2 for an uptrend, hma1 < hma2 for a downtrend — defines direction. A distance gate sits on top: the close of the trigger bar must lie on the correct side of the HMA, and MathAbs(close1 - hma1) must exceed current_atr * InpSignalAtrFactor (0.25 by default). The distance threshold is therefore a fraction of the current ATR, not a fixed pip count, which lets the EA accept wider pullbacks in volatile regimes and demand more separation in calm ones. If both slope and distance agree, the function returns +1 for long or −1 for short. If anything fails it returns 0 and the EA does nothing that bar. There is no higher-timeframe confirmation, no ADX filter, no news gate, and no regime classifier in the source — InpUseFlatFilter is exposed in the input list but GetSignal() never reads it, so toggling it on or off has no effect on entries.
OnTick() is a thin, single-position manager built around a closed-bar gate. The first thing it does is call ManageProfitLock() every tick, so trailing is continuous even when the bar is not yet closed. Then the time filter (InpUseTimeFilter = true, 08:00–20:00 server by default) — if InpCloseAtEnd is enabled, the EA flattens the basket at the end of the window; otherwise it simply stops opening new trades until the next session. A static last_bar variable gates the rest of the pipeline to one decision per M5 bar, after which GetSignal() is called. If the signal is non-zero, the EA hands the direction to CheckPyramidSafety(). That function refuses to add against an opposite-side position, refuses to add if the existing same-side position is not already in profit by at least InpPyramidMinProfit (100 points of secured profit, measured from open to current SL), and refuses if InpMaxPyramidTrades (3) is already reached. If the EA is running with InpUsePyramid=false, it acts as a strict single-position system and only opens the first trade in a series. The new trade is sized by GetLotSize(InpStopLoss), which prefers 1% balance risk and falls back to InpFixedLot (0.01) when InpRiskPercent is 0; the result is floored to the symbol's LotsStep, clamped to LotsMin/LotsMax, and capped at InpMaxLotSize (10.0). SL is InpStopLoss (500 points) and TP is InpTakeProfit (1500 points), giving a fixed 1:3 reward-to-risk on every entry — there is no ATR-scaling on the exits, so the structure of the trade is constant regardless of volatility.
ManageProfitLock() is a one-way ratchet that never loosens a stop. For a long, it computes the current profit in points; once that profit reaches InpLockTrigger (300 points), it sets a candidate SL at Bid − InpLockDistance * _Point (100 points behind price) and only sends a modify if the new SL is at least InpLockStep (50 points) above the current SL. For a short it mirrors the math. Because the trigger condition is strictly points_profit >= InpLockTrigger and the modify condition is strictly target_sl > sl + step (or target_sl < sl - step), the SL can only ever move in the profitable direction. The TP is left untouched by the ratchet, so the original 1500-point target stays in place until either TP or the ratcheted stop is hit. Closes go through TryClose_EX18083(), a 3-attempt wrapper that retries on TRADE_RETCODE_REQUOTE, TRADE_RETCODE_TIMEOUT, TRADE_RETCODE_PRICE_OFF, and TRADE_RETCODE_PRICE_CHANGED with a 200ms back-off; the corresponding modify wrapper TryModify_EX18083() uses a 100ms back-off.
The filling mode is hard-coded to ORDER_FILLING_FOK and SetDeviationInPoints(30) matches the InpSlippage input. The m_trade object is given magic 22218083, the comment "Psgrowth.com Expert_18083". There is no OnTester() block, no info panel, and no per-trade partial close — partials are wired through TryClosePartial_EX18083() but the EA never calls them. There is no drawdown breaker in the file: the only capital cap is the per-trade lot cap and the pyramid cap. Run it on a low-spread XAUUSD or EURUSD broker (the source assumes points-based pip math, so a 5-digit broker is required for the SL/TP/trailing values to read sensibly). On a $100 account the 1% risk default puts the per-trade stop at roughly the cash-equivalent of 100 points of pip-value, which on a 0.01-lot XAUUSD trade is small enough to survive the 500-point fixed SL without exhausting margin; raise InpMaxLotSize cautiously if you scale up the deposit. The most useful backtest probe is the InpSignalAtrFactor knob: lower it (0.15–0.20) for more entries in trends, raise it (0.30–0.40) for cleaner breakouts in noise.
Strategy Deep Dive
On every tick the EA first runs ManageProfitLock() to walk the SL on any open position whose profit has cleared the 300-point trigger, then enforces the 08:00–20:00 server-time window (flattens the basket if InpCloseAtEnd is on), then waits for a new M5 bar. On the closed bar GetSignal() copies the last 30 ATR(30) values, computes the mean, and uses the ratio of mean-to-current to rewrite the HMA period between 15 and 60. CalculateHMA() then rebuilds the HMA(period) at shifts 1 and 2 from scratch by reading closes and running two inner WMAs plus one outer WMA over their difference series. A long fires when hma1 > hma2 and the close sits above the HMA by at least 0.25 × current ATR; the short mirrors that. CheckPyramidSafety() then refuses to add against an opposite position, refuses to add to a same-direction position that is not already 100 points secured in profit, and caps the stack at 3 entries. The new trade is sized at 1% of balance with the 500-point fixed SL, capped at 10.0 lots, and submitted with a 30-point slippage tolerance under ORDER_FILLING_FOK.
EX18083 enters on a closed M5 bar when the adaptive HMA slopes up (hma1 > hma2) and the close sits above the HMA by more than current_ATR(30) × 0.25, then mirrors the condition for shorts. The HMA period itself is rewritten each bar from the ratio of mean ATR(30) over the last 30 bars to the most recent ATR(30), clamped to [0.5, 2.0] — so the look-back breathes between roughly 15 and 60 bars depending on volatility. Entries are blocked outside the 08:00–20:00 server window and only fire once per bar.
Exits are taken by the original fixed TP of 1500 points (1:3 R:R), by the ratcheted stop from ManageProfitLock() once profit reaches 300 points and the stop is pulled to price − 100 points, or by SL at 500 points. The optional InpCloseAtEnd flag forces a basket flatten at 20:00 server time. There is no opposite-signal exit, no time-stop, and no partial close in the source.
Per-trade stop is a fixed 500 points applied at entry; once the trade is in profit by 300 points, ManageProfitLock() pulls the stop to Bid − 100 points (or Ask + 100 points for shorts) and only ratchets further in 50-point increments. There is no global drawdown cap in the file — the only capital protection is the per-trade lot cap and the 3-position pyramid cap.
Take profit is a fixed 1500 points on every entry, giving a constant 1:3 reward-to-risk. The TP is not scaled by ATR and is not touched by the trailing logic — it stays in place until price reaches it or the ratcheted stop is hit first.
Best on a low-spread XAUUSD or EURUSD broker on a 5-digit feed where the 500-point SL and 1500-point TP translate sensibly to dollars; the 1% risk and 0.01-lot fallback keep the EA safe on a $100 account, though raising InpMaxLotSize to 1.0–2.0 is reasonable for $1,000+ balances. The 08:00–20:00 server window targets the London–New York overlap, so prop-firm and ECN setups during that overlap are the natural fit; Asian-session traders should turn the time filter off and lower InpSignalAtrFactor to 0.15 to catch the quieter breakouts.
Strategy Logic
Pipsgrowth EX18083 TrendFollow — Strategy Logic Analysis (from .mq5 source)
Family: TrendFollow
Magic: 22218083
Version: 2.00
BRIEF:
JMA Adaptive EA for XAUUSD M5 using Jurik Moving Average with ATR-adaptive signal threshold and flat/slope filter. Includes safe pyramiding, profit lock/trailing, time filter, and drawdown protection. 12 layers: REGIME, SIGNAL, ENTRY, CONFIRM, NO-TRADE, CAPITAL CAP, RISK, SIZING, MANAGE, EXIT, SCALING, OnTester
INDICATOR STACK:
- Standard
MT5indicators
KEY FUNCTIONS:
GetSignal()CalculateHMA()CheckPyramidSafety()ManageProfitLock()GetLotSize()RefreshRates()IsTradingTime()StrToTime()CloseAllPositions()TryClose_EX18083()TryClosePartial_EX18083()TryModify_EX18083()
INTERNAL CONSTANTS (0 total):
INPUT PARAMETERS (23 total across 7 groups):
- [=== Identity ===]
InpMagicNumber=22218083// Magic Number - [=== Signal Settings ===]
InpBasePeriod= 30 // BaseJMA/HMAPeriod - [=== Signal Settings ===]
InpAtrPeriod= 30 //ATRPeriod for Adaptation - [=== Signal Settings ===]
InpSignalAtrFactor=0.25// Signal DistanceThreshold(ATRMultiplier) - [=== Signal Settings ===]
InpUseFlatFilter=true// Use Slope Flat Filter - [=== Signal Settings ===]
InpPrice= 1 // Applied price (1=close,2=open,3=high,4=low,5=median,6=typical,7=weighted) // Applied Price - [=== Money Management ===]
InpRiskPercent=1.0// Risk per trade (% of Balance) - [=== Money Management ===]
InpFixedLot=0.01// FixedLot(if Risk=0) - [=== Money Management ===]
InpMaxLotSize=10.0// Max Lot Size per trade - [=== Trade Management ===]
InpStopLoss= 500 // StopLoss(Points) - [=== Trade Management ===]
InpTakeProfit= 1500 // TakeProfit(Points) - [=== Trade Management ===]
InpSlippage= 30 // MaxSlippage(Points) - [=== Pyramid / Scaling ===]
InpUsePyramid=true// Enable Safe Pyramiding - [=== Pyramid / Scaling ===]
InpMaxPyramidTrades= 3 // Max Open Positions - [=== Pyramid / Scaling ===]
InpPyramidMinProfit= 100 // Min SecuredProfit(Points) for Next Add - [=== Profit Lock & Trail ===]
InpUseProfitLock=true// Enable Profit Lock / Trailing - [=== Profit Lock & Trail ===]
InpLockTrigger= 300 // TriggerDistance(Points in Profit) - [=== Profit Lock & Trail ===]
InpLockStep= 50 // Step to advanceSL(Points) - [=== Profit Lock & Trail ===]
InpLockDistance= 100 // Distance to keep SL fromPrice(Points) - [=== Time Management ===]
InpUseTimeFilter=true// Enable Time Filter - [=== Time Management ===]
InpStartTime= "08:00" // Start TradingTime(Server) - [=== Time Management ===]
InpEndTime= "20:00" // End TradingTime(Server) - [=== Time Management ===]
InpCloseAtEnd=false// Close all at end time
// Pipsgrowth EX18083 TrendFollow — Execution Flow (from source analysis)
// Family: TrendFollow
// JMA Adaptive EA for XAUUSD M5 using Jurik Moving Average with ATR-adaptive signal threshold and flat/slope filter. Includes safe pyramiding, profit lock/trailing, time filter, and drawdown protection. 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 |
|---|---|---|
| InpMagicNumber | 22218083 | Magic Number |
| InpBasePeriod | 30 | Base JMA/HMA Period |
| InpAtrPeriod | 30 | ATR Period for Adaptation |
| InpSignalAtrFactor | 0.25 | Signal Distance Threshold (ATR Multiplier) |
| InpUseFlatFilter | true | Use Slope Flat Filter |
| InpPrice | 1 | Applied price (1=close,2=open,3=high,4=low,5=median,6=typical,7=weighted) // Applied Price |
| InpRiskPercent | 1.0 | Risk per trade (% of Balance) |
| InpFixedLot | 0.01 | Fixed Lot (if Risk=0) |
| InpMaxLotSize | 10.0 | Max Lot Size per trade |
| InpStopLoss | 500 | Stop Loss (Points) |
| InpTakeProfit | 1500 | Take Profit (Points) |
| InpSlippage | 30 | Max Slippage (Points) |
| InpUsePyramid | true | Enable Safe Pyramiding |
| InpMaxPyramidTrades | 3 | Max Open Positions |
| InpPyramidMinProfit | 100 | Min Secured Profit (Points) for Next Add |
| InpUseProfitLock | true | Enable Profit Lock / Trailing |
| InpLockTrigger | 300 | Trigger Distance (Points in Profit) |
| InpLockStep | 50 | Step to advance SL (Points) |
| InpLockDistance | 100 | Distance to keep SL from Price (Points) |
| InpUseTimeFilter | true | Enable Time Filter |
| InpStartTime | "08:00" | Start Trading Time (Server) |
| InpEndTime | "20:00" | End Trading Time (Server) |
| InpCloseAtEnd | false | Close all at end time |
#property copyright "Pipsgrowth.com"
#property link "https://pipsgrowth.com"
#property version "2.00"
#property strict
#property description "Pipsgrowth.com EX18083 JMA_XAUUSD_5M — ATR-adaptive JMA trend EA with pyramiding, full 12-layer stack."
#include <Trade\Trade.mqh>
#include <Trade\SymbolInfo.mqh>
#include <Trade\PositionInfo.mqh>
#include <Trade\AccountInfo.mqh>
// --- Global Objects ---
CTrade m_trade;
CSymbolInfo m_symbol;
CPositionInfo m_position;
CAccountInfo m_account;
// --- Inputs ---
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_APPLIED_PRICE g_InpPrice = PRICE_CLOSE;
input group "=== Identity ==="
input ulong InpMagicNumber = 22218083; // Magic Number
input string InpTradeComment = "Psgrowth.com Expert_18083";
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_APPLIED_PRICE g_InpPrice = PRICE_CLOSE;
input group "=== Signal Settings ==="
input int InpBasePeriod = 30; // Base JMA/HMA Period
input int InpAtrPeriod = 30; // ATR Period for Adaptation
input double InpSignalAtrFactor = 0.25; // Signal Distance Threshold (ATR Multiplier)
input bool InpUseFlatFilter = true; // Use Slope Flat Filter
input int InpPrice = 1; // Applied price (1=close,2=open,3=high,4=low,5=median,6=typical,7=weighted) // Applied 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.