Pipsgrowth EX16078 Trend
MT5 Expert Advisor (Open Source) · XAUUSD · M5, H1
Pipsgrowth.com EX16078 SmoothEngineEA — HMA + LR + ATR + Choppiness trend EA, full 12-layer stack.
Overview
Pipsgrowth EX16078 is a smoothed trend-following EA built around four custom indicators computed in-process rather than fetched through iHandles. The core stack is a Hull Moving Average of period 20 whose slope is fed into a Linear Regression of period 14, the resulting regression slope is normalized by an ATR(14) to dampen volatility noise, and the whole signal is gated by a Choppiness Index(14) that suppresses entries whenever the CI reading is above 61.8. The net effect is an engine that only opens trend positions when price is actually moving directionally and the recent range structure is non-rotational.
The HMA itself is constructed by hand in CalculateHMA(): a WMA of the close over the full period, a second WMA over half the period, a doubled difference (2·WMA_half − WMA_full), and a final WMA over √N of that difference array. The output is a curve that lags price by about half the period of a normal WMA but still smooths enough to suppress whipsaw. CalculateLRSlope() then takes the most recent 14 HMA points and runs a least-squares fit, returning the slope of the regression line. Divide that slope by the current ATR(14) value to get the normalized slope, the only directional feature the engine actually trades on. ATR is rebuilt in CalculateATR() using the high/low and previous-close True Range, then smoothed with a Wilder-style running average.
The Choppiness Index is the regime classifier. Over a 14-bar window it sums the ATR values, captures the high-low range of the same window, and returns 100·log10(ΣATR/range)/log10(period). When CI sits above 61.8, the market is in a chop — neither a clean trend nor a clear range. GetSignal() therefore returns 0 (no trade) in that state, regardless of slope direction. When CI falls back below 61.8 and the normalized slope is positive, the engine returns a buy signal of +1; when slope is negative it returns −1. The shift inside the engine is fixed at 0 because the internal arrays are updated from closed bar[1] data, so the signal is decision-ready on the open of bar[0] and the engine has not bar-snooped.
Each new tick OnTick checks for a new bar and pushes the closed bar[1] close/high/low into the engine's circular buffers via UpdateData(). The HMA, slope and CI values are recomputed and stored at their respective offsets. The trade logic that follows is split into two blocks: a close block and an open block. If the signal flips to −1 and there is at least one open BUY, CloseAllTrades(POSITION_TYPE_BUY) is invoked, which iterates the position list and calls TryClose_EX16078 on each ticket. TryClose_EX16078 wraps trade.PositionClose in a 3-attempt loop that retries on requote, timeout, price-off and price-changed retcodes with a 200ms sleep between attempts. The reverse path runs identically for sell positions when signal flips to +1.
The open block enforces a position cap and an optional pyramiding rule. When the signal is +1 and no BUY is open, OpenTrade(ORDER_TYPE_BUY) fires; the order is sized by CalculateLotSize() to risk exactly 1% of account balance against the fixed 300-point StopLoss_Points distance, snapped to the symbol's lot step. If pyramiding is enabled and the BUY count is below MaxOpenTrades (3 by default), the engine checks the most recent open BUY's profit converted into points; when that profit-in-points exceeds PyramidingStep_Points (200), a second (and eventually third) BUY is layered in. The pyramid rule is the same on the sell side. The open path also runs CheckSpread() at the top, blocking any new order if the symbol spread is above MaxSpread_Points (30) and printing a Spread Filter block message to the Experts log.
The session gate is a string-based filter. The TradingHours input defaults to '08:00-20:00' and is parsed by GetStartHour/GetStartMinute/GetEndHour/GetEndMinute into a minutes-of-day range; IsTradingTime() returns true only when the current server clock is inside that window. When outside the window OnTick returns early after the dashboard update, so the engine still tracks state but does not open or close positions — useful for traders who want to keep the dashboard visible around the clock while letting the EA act only during a defined band. The dashboard itself is a 200x160 black panel anchored at the top-left of the chart, displaying the current signal (WAIT/BUY/SELL in blue or red), the cumulative P/L across all positions on the chart symbol, and the current HMA period. Two buttons labeled [+] and [−] live under the period label: clicking [+] increments g_HMA_Period and calls ReinitializeEngine() to rebuild the engine's buffers from history with the new period; clicking [−] decrements it down to a floor of 2. A red CLOSE ALL button is wired to flatten both sides at once.
What sets EX16078 apart from a vanilla MA-crossover is the dual smoothing on the slope side: the HMA removes the bar-to-bar jitter of a raw price MA, and the regression line over 14 HMA points removes whatever jitter the HMA still carries. The Choppiness Index then acts as a permission gate so the engine does not enter every micro-twitch in a sideways tape. Expect a low trade frequency, frequent small losses in chop, and a sequence of larger winners when a clean H1 or M5 trend develops during the 08:00-20:00 window. The risk per trade is fixed at 1% of equity through a 300-point stop, with a 600-point take-profit giving a 1:2 reward-to-risk on every fresh entry, and the same SL/TP is applied to the pyramid legs. For backtesting, be aware that the engine processes one bar per new-bar tick and updates the dashboard on every tick, so visualizer performance is well within MT5's tolerance; just remember that magic 22216078 is hard-coded into the comment 'Psgrowth.com Expert_16078' which appears on every order.
Strategy Deep Dive
EX16078 maintains seven in-process buffers (close, high, low, ATR, HMA, slope, Choppiness) inside a CSmoothEngine class, updated on every new bar from closed bar[1] data via UpdateData(). The HMA is constructed as 2·WMA(N/2) − WMA(N) re-smoothed by a √N WMA; the slope is the linear-regression gradient over the last 14 HMA points; the regime gate is 100·log10(ΣATR/range)/log10(14), blocked above 61.8. On every tick OnTick queries GetSignal() and runs the close path (reverse-signal close on the opposite side) and the open path (fixed-lot, risk-percent-sized entry with optional profit-step pyramiding up to MaxOpenTrades). A string-parsed TradingHours window (08:00-20:00 by default) gates the trading branch but the dashboard update runs every tick. The chart panel is interactive: the [+] and [−] buttons mutate g_HMA_Period at runtime and trigger ReinitializeEngine() to rebuild the buffers from history; the red CLOSE ALL button flattens both sides via TryClose_EX16078.
Long entries require the Choppiness Index(14) to print at or below 61.8 (regime filter) AND the ATR(14)-normalized slope of a 14-period linear regression on a Hull MA(20) to be positive. Short entries mirror that, requiring CI ≤ 61.8 with a negative normalized slope. Pyramiding layers up to MaxOpenTrades (3) additional positions in the trend direction, with each layer gated by PyramidingStep_Points (200) of profit on the most recent open leg.
A signal flip in either direction forces an immediate close of all positions on the opposite side via CloseAllTrades(), which uses the TryClose_EX16078 retry loop to handle requotes and price-change events. Each individual order carries a hard 600-point TakeProfit that closes the position automatically at the 1:2 reward-to-risk distance, independent of the signal-flip close path.
Every position is opened with a fixed 300-point StopLoss_Points attached at order time, normalized to the symbol's digits. There is no trailing stop and no breakeven ratchet in the engine — the 300-point distance is the absolute risk per leg, and CalculateLotSize() sizes the order so that this distance equals exactly 1% of the account balance.
Each new order carries a hard 600-point TakeProfit_Points target, set at order time and never trailed. Combined with the 300-point stop this gives a fixed 1:2 reward-to-risk on every entry including pyramid legs. The TP is enforced server-side by the broker at the order level, not polled from the EA.
Minimum recommended balance: $100 (1% risk sizing × 300-point stop on XAUUSD with 0.01 lot-step). Best deployed on XAUUSD M5 or H1; the 08:00-20:00 trading window lines up with the London and New York cash sessions where gold prints its cleanest directional ranges. Risk level: MEDIUM — fixed 1:2 RR, hard 300/600pt SL/TP, no martingale or grid. Broker requirements: low-spread account, since MaxSpread_Points = 30 is the only entry gate on top of the CI regime filter; on ECN/RAW under 15pt the entry frequency will be noticeably higher than on a typical 25-30pt standard account.
Strategy Logic
Pipsgrowth EX16078 Trend — Strategy Logic Analysis (from .mq5 source)
Family: Trend
Magic: 22216078
Version: 2.00
BRIEF:
Smooth Engine EA using Hull MA, Linear Regression slope, ATR volatility, and Choppiness Index for smooth trend entries. Supports pyramiding with step distance, spread filter, trading hours, and risk-percent position sizing
INDICATOR STACK:
- Standard
MT5indicators
KEY FUNCTIONS:
GetStartHour()GetStartMinute()GetEndHour()GetEndMinute()IsTradingTime()CheckSpread()CountTrades()CalculateLotSize()GetLastTradeProfit()OpenTrade()CloseAllTrades()CreateDashboard()- ...and 6 more
INTERNAL CONSTANTS (0 total):
INPUT PARAMETERS (3 total across 1 groups):
- [] CI_Threshold =
61.8// Global Variable for Live Tuning - []
InpMagicNumber=22216078// Magic number - []
InpTradeComment= "Psgrowth.com Expert_16078" // +------------------------------------------------------------------+
// Pipsgrowth EX16078 Trend — Execution Flow (from source analysis)
// Family: Trend
// Smooth Engine EA using Hull MA, Linear Regression slope, ATR volatility, and Choppiness Index for smooth trend entries. Supports pyramiding with step distance, spread filter, trading hours, and risk-percent position sizing
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 |
|---|---|---|
| CI_Threshold | 61.8 | Global Variable for Live Tuning |
| InpMagicNumber | 22216078 | Magic number |
| InpTradeComment | "Psgrowth.com Expert_16078" | +------------------------------------------------------------------+ |
#property copyright "Pipsgrowth.com"
#property link "https://pipsgrowth.com"
#property version "2.00"
#property strict
#property description "Pipsgrowth.com EX16078 SmoothEngineEA — HMA + LR + ATR + Choppiness trend EA, full 12-layer stack."
#include <Trade\Trade.mqh>
sinput const string GroupIndicator="";//=== Indicator Settings ===
input int HMA_Period = 20;
input int LR_Period = 14;
input int ATR_Period = 14;
input int CI_Period = 14;
input double CI_Threshold = 61.8;
// Global Variable for Live Tuning
int g_HMA_Period;
sinput const string GroupTrade="";//=== Trade Settings ===
input bool EnablePyramiding = true;
input int MaxOpenTrades = 3;
input int PyramidingStep_Points = 200;
input int StopLoss_Points = 300;
input int TakeProfit_Points = 600;
input int MaxSpread_Points = 30;
input string TradingHours = "08:00-20:00";
input double RiskPercent = 1.0;
sinput const string GroupIdentity="";//=== Identity ===
input long InpMagicNumber = 22216078; // Magic number
input string InpTradeComment = "Psgrowth.com Expert_16078";
//+------------------------------------------------------------------+
//| Class CSmoothEngine |
//+------------------------------------------------------------------+
class CSmoothEngine
{
private:
int m_hma_period;
int m_lr_period;
int m_atr_period;
int m_ci_period;
double m_ci_threshold;
int m_bars_needed;
int m_buffer_size;
double m_close[];
double m_high[];
double m_low[];
double m_atr[];
double m_hma[];
double m_slope[];
double m_ci[];
int m_current_pos;
double CalculateHMA(const double &price[], int index)
{
int half_period = (int)MathFloor(m_hma_period / 2.0);
int sqrt_period = (int)MathFloor(MathSqrt((double)m_hma_period));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.