P
PipsGrowth
Trend FollowingOpen Source – Free

Pipsgrowth EX18108 TrendFollow

MT5 Expert Advisor (Open Source) · XAUUSD · M5, H1

Pipsgrowth.com EX18108 per — EMA/MACD/RSI indicator monitor with automated execution, full 12-layer stack.

Overview

Pipsgrowth EX18108 is a single-position, bar-driven indicator monitor that scans four cross-checking signals before it ever considers firing an order. The strategy skeleton rests on a 21-period EMA and a 55-period EMA, a 12/26/9 MACD, a 14-period RSI, and a 14-period ATR. On every new bar of the chart, OnTick calls IsNewBar() to confirm a fresh candle, then walks through UpdateBalanceTracking, CheckRiskLimits, GetIndicatorValues, CheckTimeFilters, CheckVolatilityFilters, and finally CheckEntrySignals. Anything that returns false short-circuits the rest of the chain, so the EA never enters when its safety conditions are not met.

The trade trigger itself is constructed to catch pullbacks inside an established trend, not breakouts. CheckLongEntry requires the close to be above both EMA(21) and EMA(55), which confirms an uptrend regime. It then walks the last two completed bars looking for a MACD main-line cross below the signal line on the more recent of those bars. That bearish cross represents the momentary loss of upside momentum that the EA treats as the pullback. The RSI filter then narrows the band: long entries are only taken when the current RSI sits inside 40-60, which is the neutral zone where momentum is cooling but not yet oversold. Finally, the distance from price to EMA(21) is checked against EMA_Pullback_Pips (default 15 pips) so the entry sits close enough to the moving average to actually be a pullback rather than a fresh leg. CheckShortEntry mirrors all of this with the same distance band and the inverted RSI band (40-60 maps to 40-60 on the short side via 100 - RSI_High and 100 - RSI_Low, which the source computes as 40 to 60 — a symmetry worth noting because it does not skew toward long or short).

Risk and trade management are explicit and quantified. The stop loss is sized as ATR(14) * 2.0 pips, capped by MaxStopLossPips at 150 pips. The take profit is ATR(14) * 3.0 pips, with no cap. That gives a 1.5 reward-to-risk ratio at the default configuration, but the actual ratio at any entry depends on the live ATR — a high-volatility bar can produce a 2.0 ATR stop capped at 150 pips with a 3.0 ATR take profit further away in absolute pips. CalculateLotSize then sizes the position so that the trade risks exactly RiskPercent percent of the account balance if the stop is hit. The formula is balance * RiskPercent/100 / (ticks_in_SL * tick_value), with the result floored to the symbol's lot step and clamped between the symbol's min and max volume. This is a textbook pip-value position sizer, not a fixed-lot scheme, so a $100 account and a $10,000 account at 1% risk will both open positions sized to their balance — though the smaller account will often hit the broker's minimum lot.

The EA enforces a strict one-position cap via MaxPositions = 1. It does not pyramid, does not scale in, and does not add to winners. CheckEntrySignals counts positions whose symbol and magic number match before each signal check and returns immediately if the cap is hit. The lot sizing, take profit, and stop loss are all baked into the order at entry; there is no trailing stop, no break-even ratchet, and no partial close in the active path. The retry helpers TryClose_EX18108, TryClosePartial_EX18108, and TryModify_EX18108 exist in the file but are not called from OnTick — they are dormant infrastructure. The only position state change is the order itself, plus server-side SL and TP.

Two hard-coded safety gates sit upstream of the signal check. CheckTimeFilters honors the three session flags. With the defaults (Asian ON 00:00-09:00, London ON 07:00-16:00, New York OFF), the EA only opens orders when the broker's server time falls inside the Asian or London window — a configuration that covers the London-Asia overlap from 07:00 to 09:00. CheckVolatilityFilters rejects any bar where the ATR is below MinATR (0.5) or above MaxATR (2.0), and rejects any tick where the spread exceeds MaxSpreadPips (2.5 pips after the 3-or-5-digit normalization). Both gates log to the journal, which makes it easy to audit a backtest's no-trade rate by searching for [Filters].

The account-level kill switch lives in CheckRiskLimits. It tracks two reference balances: daily_starting_balance, reset on the first tick of each new broker day, and peak_balance, which is the all-time high water mark since the EA was attached. If the day's loss as a percent of the starting balance reaches DailyLossLimit (3%), or if the current drawdown from peak reaches MaxDrawdownPercent (15%), CheckRiskLimits returns false and the rest of the bar is skipped. There is no closing of existing positions — the EA only refuses to open new ones. The peak-balance approach means a long quiet period followed by a drawdown will be measured against the highest balance ever seen, not the most recent.

The header block in the .mq5 claims a 12-layer architecture, but a strict count of the actual code yields closer to eight: signal generation (the EMA/MACD/RSI triple), entry trigger, confirmation (the pullback distance), no-trade (session + volatility), capital cap (MaxPositions), risk (lot sizing and SL), exit (TP and SL are server-attached), and a daily drawdown brake. Missing from the implementation are any explicit regime classifier, scaling logic (single position only), OnTester block, news filter, equity curve filter, or info panel. The diagnostic PrintIndicatorSnapshot call after every filter pass writes EMA, MACD, RSI, and ATR values to the journal for post-mortem analysis, which is the only built-in observability beyond the filter and trade logs.

In backtest this configuration behaves like a London-session pullback engine on XAUUSD M5. The 1% risk per trade, 3% daily loss cap, 15% drawdown cap, 1.5 reward-to-risk target, and single-position cap are the load-bearing parameters. Anyone running this should size their account so the symbol's minimum lot does not force oversized risk on the small end, and should expect most blocked bars to come from the session filter outside London hours and the spread filter during thin Asian sessions on gold.

Strategy Deep Dive

Every new bar triggers a four-layer filter chain: daily drawdown check, indicator snapshot, session window, and ATR/spread volatility. The 5-handle stack (EMA21, EMA55, MACD 12/26/9, RSI14, ATR14) feeds 3-bar buffers; a long fires only when price sits above both EMAs, MACD just crossed bearish on bar 1 or 2, RSI sits between 40 and 60, and the close-to-fast-EMA distance is under 15 pips. Position sizing divides 1% of balance by the pip value of the ATR-based stop, then floors to the symbol's lot step. The same one-position cap governs the entire trade lifecycle; once an order is in, the EA does not touch it until SL or TP fires server-side.

Entry Signal

Long entries require the close above both EMA(21) and EMA(55), a fresh MACD main-line cross below the signal line on the last one or two completed bars, RSI(14) inside the 40-60 neutral band, and price within EMA_Pullback_Pips (default 15) of the fast EMA. Short entries mirror the same pullback construction with the inverted MACD cross and the same RSI band applied to the short side. A new bar must open, all three filter gates (risk limits, session, volatility) must clear, and MaxPositions must be under 1.

Exit Signal

Exit is server-side only. Each order attaches the calculated ATR(14)2.0 SL and ATR(14)3.0 TP at entry, and the EA does not trail, does not move to break-even, and does not partially close. The TryClose/TryClosePartial/TryModify retry helpers exist in the file but are not invoked from OnTick. Position state is fully determined by the original order ticket and the broker's SL/TP handling.

Stop Loss

Per-trade stop is ATR(14) * ATR_SL_Multiplier (default 2.0) pips, hard-capped at MaxStopLossPips (default 150) pips. The same formula applies symmetrically to long and short. There is no trailing stop, no break-even lock, and no modification after entry — the SL is frozen at order placement.

Take Profit

Per-trade take profit is ATR(14) * ATR_TP_Multiplier (default 3.0) pips, with no upper cap. The default 2.0 SL x and 3.0 TP x produce a 1.5 reward-to-risk ratio at the configured ATR, but the live ratio shifts with market volatility. TP is server-attached at order entry and never modified.

Best For

Recommended for XAUUSD on the M5 chart with a minimum balance of $100, although traders should size up to $500+ so the 1% risk allocation clears the typical XAUUSD minimum lot of 0.01 without forcing oversized percent risk on tiny accounts. The default session window is Asian 00:00-09:00 plus London 07:00-16:00 server time, which covers the London-Asia overlap; turn off Asian or turn on New York in the inputs if you want a tighter band. Run on a low-spread ECN or raw-spread account — the 2.5 pip MaxSpreadPips filter will throttle entries on standard accounts during Asian hours on gold. The 1.5 reward-to-risk target and 1% per-trade risk make this a fit for traders who want a quiet pullback system with a hard daily loss brake and a 15% drawdown ceiling.

Strategy Logic

Pipsgrowth EX18108 TrendFollow — Strategy Logic Analysis (from .mq5 source)

Family: TrendFollow Magic: 22218108 Version: 2.00

BRIEF: Indicator monitor with automated execution combining EMA crossover, MACD, RSI, and ATR-based SL/TP. Includes session filters, volatility filters, and daily loss/drawdown limits. 12 layers: REGIME, SIGNAL, ENTRY, CONFIRM, NO-TRADE, CAPITAL CAP, RISK, SIZING, MANAGE, EXIT, SCALING, OnTester

INDICATOR STACK:

  • Standard MT5 indicators

KEY FUNCTIONS:

  • IsNewBar()
  • GetIndicatorValues()
  • ValidateSessionInputs()
  • IsWithinSession()
  • UpdateBalanceTracking()
  • CheckRiskLimits()
  • CheckEntrySignals()
  • CheckLongEntry()
  • CheckShortEntry()
  • CheckTimeFilters()
  • CheckVolatilityFilters()
  • CalculateLotSize()
  • ...and 6 more

INTERNAL CONSTANTS (0 total):

INPUT PARAMETERS (0 total across 0 groups):

Pseudocode
// Pipsgrowth EX18108 TrendFollow — Execution Flow (from source analysis)
// Family: TrendFollow
// Indicator monitor with automated execution combining EMA crossover, MACD, RSI, and ATR-based SL/TP. Includes session filters, volatility filters, and daily loss/drawdown limits. 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

Optimized Brokers:
ExnessIC Markets
Optimized Symbols:
XAUUSD
Optimized Timeframes:
M5H1

How to Install This EA on MT5

  1. 1Download the .mq5 file using the button above
  2. 2Open MetaTrader 5 on your computer
  3. 3Click File → Open Data Folder in the top menu
  4. 4Navigate to MQL5 → Experts and paste the .mq5 file there
  5. 5In MT5, right-click Expert Advisors in the Navigator panel → Refresh
  6. 6Drag the EA onto an H4 or Daily chart for best results
  7. 7Configure EMA periods, ADX threshold, and lot size in the dialog
  8. 8Enable Allow Algo Trading and click OK
Source Code (.mq5)Open Source
Pipsgrowth_com_EX18108.mq5
#property copyright "Pipsgrowth.com"
#property link      "https://pipsgrowth.com"
#property version   "2.00"
#property strict
#property description "Pipsgrowth.com EX18108 per — EMA/MACD/RSI indicator monitor with automated execution, full 12-layer stack."

#include <Trade/Trade.mqh>
#include <Trade/PositionInfo.mqh>

input group "=== Moving Average Settings ==="
input int    EMA_Fast_Period  = 21;
input int    EMA_Slow_Period  = 55;

input group "=== MACD Settings ==="
input int    MACD_Fast_EMA    = 12;
input int    MACD_Slow_EMA    = 26;
input int    MACD_Signal_SMA  = 9;

input group "=== RSI Settings ==="
input int    RSI_Period       = 14;
input double RSI_Low          = 40.0;
input double RSI_High         = 60.0;

input group "=== ATR Settings ==="
input int    ATR_Period        = 14;
input double ATR_SL_Multiplier = 2.0;
input double ATR_TP_Multiplier = 3.0;

input group "=== Signal Filters ==="
input double EMA_Pullback_Pips = 15.0;

input group "=== Risk Management ==="
input double RiskPercent      = 1.0;
input double MaxStopLossPips  = 150.0;
input int    MaxPositions     = 1;

input group "=== Trade Settings ==="
input bool   EnableTrading    = true;
input int    TradeDeviation   = 5;
input long   MagicNumber      = 22218108;
input string InpTradeComment     = "Psgrowth.com Expert_18108";

input group "=== Session Filters ==="
input bool   EnableSessionFilter     = true;
input bool   TradeAsianSession       = true;
input int    AsianSessionStartHour   = 0;
input int    AsianSessionStartMinute = 0;
input int    AsianSessionEndHour     = 9;
input int    AsianSessionEndMinute   = 0;
input bool   TradeLondonSession      = true;
input int    LondonSessionStartHour  = 7;
input int    LondonSessionStartMinute= 0;
input int    LondonSessionEndHour    = 16;
input int    LondonSessionEndMinute  = 0;
input bool   TradeNewYorkSession     = false;
input int    NewYorkSessionStartHour = 13;
input int    NewYorkSessionStartMinute = 0;
input int    NewYorkSessionEndHour   = 22;
input int    NewYorkSessionEndMinute = 0;

Full source code available on download

Educational purposes only. Do NOT use with real money. Test on demo accounts only.

Tags:ex18108trendfollowpipsgrowthfreemt5xauusd

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

Community

Sign in to contributeSign In

Educational purposes only. Do NOT use with real money. Test on demo accounts only.

File NamePipsgrowth_com_EX18108.mq5
File Size23.3 KB
Versionv2.00
PlatformMetaTrader 5
File Type.mq5 Source
StrategyTrend Following
Risk LevelMedium Risk
Timeframes
M5H1
Currency Pairs
XAUUSD
Min. Deposit$100