P
PipsGrowth
Trend FollowingOpen Source – Free

Pipsgrowth EX18091 TrendFollow

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

Pipsgrowth.com EX18091 main — RSI Follow/Reverse + EMA Cross multi-strategy, full 12-layer stack.

Overview

EX18091 is a three-strategy composite that runs three independent signal engines in parallel on a single XAUUSD chart, each owning its own magic number so the strategies cannot interfere with each other inside the terminal. The three engines are RSI Follow (magic 22218091), RSI Reverse (magic 22218092) and EMA Cross (magic 22218093). Every entry, every exit and every state flag is partitioned by magic, so you can run any subset you like — one, two or all three — by toggling the three InpEnable… switches on the inputs panel.

The RSI Follow engine is a classical mean-reversion-through-trend signal. It watches a 49-period RSI applied to close on the trading timeframe. When RSI[1] pushes above the 81 overbought line, a rsiOverbought state flag is latched. The flag is consumed — and a sell is fired at the next bar — only when RSI[1] drops below the 48 exit level and RSI[1] is lower than RSI[0] (an actual turn, not a flat). The mirror logic fires buys when RSI[1] drops below 41, then crosses back above 48 with RSI[1] > RSI[0]. The signal is latched, not a one-tick observation, which is what stops the engine from whipsawing on a single oversold bar. Sessions are pinned: this engine is awake between server hours 24:00 and 08:00 — the Asian session, where XAUUSD often stages its reversals off the prior New York close.

The RSI Reverse engine runs on a 159-period RSI, a much longer window that filters for genuinely stretched conditions rather than intraday noise. The 51/49 OB/OS bands sit closer to the 50 mid-line, so the engine is looking for RSI to push past neutral and then re-cross a 54 trigger line on the way back. Buy is triggered when RSI was oversold (below 49) and re-crosses above 54; sell is the mirror. This engine is awake between 12:00 and 22:00 server time — the London and New York overlap, when XAUUSD trends hard and the long-period RSI gives cleaner reversals. Two extra layers discipline it: a configurable cooldown (InpRSIReverseCooldownBars = 11 bars) that fires after a close, and a InpRSIReverseCooldownOnLoss flag that limits the cooldown to losing closes only. The IsRSIReverseInCooldown() function checks the bar clock against rsiReverseLastCloseTime + cooldownBars * PeriodSeconds(g_InpTimeframe) and refuses to fire while the gate is on.

The EMA Cross engine is the third pillar. It reads a 175-period EMA on close and looks for the close to cross the EMA on the most recent bar (ema[1] < close[1] && ema[0] > close[0] for buy, mirror for sell). When the distance filter is on (InpUseEMADistanceEntry = true, default), the cross alone is not enough — the engine requires that price has stayed beyond the EMA by at least 8,440 points for InpEMADistancePeriod = 30 consecutive bars. That is a 30-bar separation check: it filters out cross signals that come back inside the EMA immediately, keeping only the ones where the cross is the start of a sustained excursion. When the distance filter is off, the cross alone is sufficient. The signal is latched in emaCrossBuySignal / emaCrossSellSignal and aged out after InpEMADistancePeriod * 2 bars so the engine cannot queue an entry that fires days later. EMA Cross is awake 22:00 to 12:00 server time, the same Asian-through-London-open window that pairs with the RSI Follow Asian window without overlap.

The strategy-lock feature ties the three engines together. When InpEnableStrategyLock = true and any strategy (other than the one currently evaluating) has a profitable position with profit > InpLockProfitThreshold = 120 points, the engine under evaluation is suppressed — it returns without firing. That is the EA's defence against the three engines trading the same instrument in conflicting directions simultaneously. Optionally InpCloseOppositeTrades = true extends the lock into an enforcement: when one strategy's open position is in profit, the EA actively closes the opposing strategy's open trade. On XAUUSD that converts the multi-strategy set-up from a pure signal-fan-out into a triage — one engine at a time is the active book.

Exits mirror the entry logic and are partitioned by magic. For RSI Follow, a buy is closed when RSI[0] drops below the 48 exit level; a sell is closed when RSI[0] rises above 48. For RSI Reverse, the same idea on the 159-period RSI around the 49 exit level. For EMA Cross, the exit fires when the close crosses back through the EMA in the direction opposite the trade — a buy is closed the moment close dips below the EMA, a sell the moment close rises above. None of the three engines places a fixed stop-loss or take-profit at the open; the 0, 0, 0 bracket on every trade.Buy and trade.Sell call means the only exits are the indicator-driven reversals and the optional InpEnableStrategyLock cross-engine cleanup. That keeps the trade lifecycle entirely indicator-defined, but it also means the EA relies on the exit signals firing — if a session window closes and the engine is shut off, an open position can sit until the next session reopens the matching state flag. Toggle InpRSIFollowCloseOutsideHours, InpRSIReverseCloseOutsideHours or InpEMACrossCloseOutsideHours to force-close positions when the session ends.

Sizing is intentionally simple. Every entry uses the single InpLotSize = 0.01 input, with no risk-percentage formula, no compounding multiplier and no balance cap. On a $100 minimum-deposit account that gives ten concurrent micro-lot positions if all three engines fire the same bar, which on a calm XAUUSD day is plausible but on a London-open breakout is unlikely because the strategy-lock will suppress the late entries. Slippage is fixed at 10 points via trade.SetDeviationInPoints(10), and filling mode is delegated to the broker via trade.SetTypeFillingBySymbol(_Symbol). Position retries are exposed — TryClose_EX18091 and TryModify_EX18091 each loop three times on REQUOTE, TIMEOUT, PRICE_OFF and PRICE_CHANGED responses, sleeping 200 ms (close) or 100 ms (modify) between attempts — so an unstable connection around the New York close will not silently drop an exit.

A few details that matter in production. First, the entire signal stack runs only on a new bar (IsNewBar() gates OnTick()), so on a quiet session you can sit through dozens of ticks with no recompute and no slippage risk. Second, the timeframe is set by the InpTimeframe enum-style input (1 = M1 through 7 = D1, default 0 = H1) — all three engines read indicators on the same timeframe, so if you want a faster RSI Follow on M5 and a slower EMA Cross on H1, you need to split the EA across two charts. Third, the magic numbers are independent inputs (InpMagicNumberRSIFollow, InpMagicNumberRSIReverse, InpMagicNumberEMACross), so if you are running other EAs on the same XAUUSD terminal you can renumber to avoid collisions. Finally, because the EA places no SL or TP at open, the broker-side stop-out level is the only hard floor on any individual position — the EA's whole risk control is the indicator-driven exit, the strategy-lock inhibit, and the optional session-close shutdown. Test on demo for at least a quarter before treating the signals as proven, and prefer brokers that let you set 0/0 brackets cleanly on micro-lot gold.

Strategy Deep Dive

The EA partitions its state by magic number, so three signal engines (RSI Follow 49-period with latched overbought/oversold flags, RSI Reverse 159-period with a cross-54 trigger and 11-bar loss-cooldown, EMA Cross 175-period with a 30-bar distance filter of 8,440 points) can each open and close positions without ever reading another engine's tickets. Each new bar, the OnTick() handler runs IsNewBar() first; on a fresh bar it invokes the three Check…Strategy() functions in order, each gated by its own IsWithinTradingHours() window and its own InpEnable… switch. Exit logic runs in CheckExitConditions() and is partitioned by magic: a buy is closed when the matching indicator turns against it, a sell on the mirror. InpEnableStrategyLock and the matching InpCloseOppositeTrades flag add a cross-engine inhibit: when any other engine has an open position in profit above InpLockProfitThreshold = 120 points, the active engine is suppressed and the opposing position is force-closed. All retries on REQUOTE, TIMEOUT, PRICE_OFF and PRICE_CHANGED are wrapped in 3-attempt loops with 200 ms / 100 ms back-off, so connection blips around the New York close do not silently drop exits.

Entry Signal

Three independent signal engines run on each new bar: RSI Follow (49-period, OB 81 / OS 41, Asian session 24:00–08:00 server) opens sells on a turn down from overbought through 48, opens buys on a turn up from oversold through 48. RSI Reverse (159-period, cross 54, London/NY 12:00–22:00) opens on the cross back through 54 with an 11-bar cooldown on losing closes. EMA Cross (175-period, 22:00–12:00) opens when close crosses the EMA and price then stays beyond the EMA by 8,440 points for 30 consecutive bars. Each engine owns its own magic number so the three can run together or be toggled individually.

Exit Signal

Exits are indicator-driven and partitioned by magic. RSI Follow closes a buy when RSI[0] drops below 48 and a sell when RSI[0] rises above 48. RSI Reverse closes on the 159-period RSI crossing the 49 exit level. EMA Cross closes the moment close crosses back through the EMA in the direction opposite the trade. When InpEnableStrategyLock = true and another strategy's position is in profit above 120 points, the active engine is suppressed and any open opposite trade is force-closed by HasProfitablePosition(). Optional per-engine flags Inp…CloseOutsideHours can force-close positions when the session ends.

Stop Loss

No fixed stop-loss is placed on entry — every trade.Buy and trade.Sell call passes 0 for both SL and TP, so the broker stop-out is the only hard floor. Per-position risk control is entirely indicator-driven: the same exit signal that closes a profitable trade is the only mechanism that closes a losing one. The strategy-lock and optional session-close flags add a portfolio-level brake when one strategy is in profit and another is fighting it.

Take Profit

No fixed take-profit is placed on entry. Profits are taken when the indicator exit fires: RSI Follow takes profit on the RSI crossing back through 48, RSI Reverse on the 159-period RSI crossing 49, and EMA Cross on close crossing back through the EMA. The InpLockProfitThreshold = 120 points input defines the profit level at which the strategy-lock treats a position as 'profitable enough' to inhibit the other two engines.

Best For

Best suited to XAUUSD on H1 (default) with a minimum deposit of $100, where the three-engine fan-out gives diversification across Asian, London and post-New-York sessions without over-lapping. The fixed 0.01 lot per signal means a $100 account can comfortably host the EA in concurrent-mode without margin pressure, and the magic-number partitioning makes it safe to run alongside other PipsGrowth EAs on the same terminal if you renumber the inputs. ECN or low-spread brokers are recommended because the EA places no fixed brackets and exits only on indicator reversals — broker-side spread is the only execution friction. Avoid running the strategy-lock on a $100 account if you intend to enable all three engines simultaneously, because the 120-point profit lock and the per-strategy 0.01 lots can each close a trade on the same breakout bar.

Strategy Logic

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

Family: TrendFollow Magic: 22218091 Version: 2.00

BRIEF: Multi-strategy EA combining RSI Follow, RSI Reverse and EMA Cross strategies with session filters and strategy locking. 12 layers: REGIME, SIGNAL, ENTRY, CONFIRM, NO-TRADE, CAPITAL CAP, RISK, SIZING, MANAGE, EXIT, SCALING, OnTester

INDICATOR STACK:

  • Standard MT5 indicators

KEY FUNCTIONS:

  • IsNewBar()
  • IsWithinTradingHours()
  • HasPosition()
  • HasProfitablePosition()
  • CheckRSIFollowStrategy()
  • IsRSIReverseInCooldown()
  • CheckRSIReverseStrategy()
  • CheckEMACrossStrategy()
  • CheckExitConditions()
  • ClosePosition()
  • TryClose_EX18091()
  • TryClosePartial_EX18091()
  • ...and 1 more

INTERNAL CONSTANTS (0 total):

INPUT PARAMETERS (36 total across 5 groups):

  • [=== General Settings ===] InpTimeframe = 0 // Timeframe (1=M1,2=M5,3=M15,4=M30,5=H1,6=H4,7=D1) // Trading Timeframe
  • [=== General Settings ===] InpLotSize = 0.01 // Lot Size
  • [=== General Settings ===] InpTradeComment = "Psgrowth.com Expert_18091" // Trade Comment
  • [=== General Settings ===] InpMagicNumberRSIFollow = 22218091 // Magic Number RSI Follow
  • [=== General Settings ===] InpMagicNumberRSIReverse = 22218092 // Magic Number RSI Reverse
  • [=== General Settings ===] InpMagicNumberEMACross = 22218093 // Magic Number EMA Cross
  • [=== Strategy Switches ===] InpEnableRSIFollow = true // Enable RSI Follow Strategy
  • [=== Strategy Switches ===] InpEnableRSIReverse = true // Enable RSI Reverse Strategy
  • [=== Strategy Switches ===] InpEnableEMACross = true // Enable EMA Cross Strategy
  • [=== Strategy Switches ===] InpEnableStrategyLock = false // Enable Strategy Lock
  • [=== Strategy Switches ===] InpLockProfitThreshold = 120.0 // Lock Profit Threshold (pips)
  • [=== Strategy Switches ===] InpCloseOppositeTrades = true // Close Opposite Trades When Profiting
  • [=== RSI Follow Strategy ===] InpRSIPeriod = 49 // RSI Period
  • [=== RSI Follow Strategy ===] InpRSIOverbought = 81 // RSI Overbought Level
  • [=== RSI Follow Strategy ===] InpRSIOversold = 41 // RSI Oversold Level
  • [=== RSI Follow Strategy ===] InpRSIExitLevel = 48 // RSI Exit Level
  • [=== RSI Follow Strategy ===] InpRSIFollowStartHour = 24 // RSI Follow Start Hour (0-23)
  • [=== RSI Follow Strategy ===] InpRSIFollowEndHour = 8 // RSI Follow End Hour (0-23)
  • [=== RSI Follow Strategy ===] InpRSIFollowCloseOutsideHours = false // Close trades outside trading hours
  • [=== RSI Reverse Strategy ===] InpRSIReversePeriod = 159 // RSI Period
  • [=== RSI Reverse Strategy ===] InpRSIReverseOverbought = 51 // RSI Overbought Level
  • [=== RSI Reverse Strategy ===] InpRSIReverseOversold = 49 // RSI Oversold Level
  • [=== RSI Reverse Strategy ===] InpRSIReverseCrossLevel = 54 // RSI Cross Level
  • [=== RSI Reverse Strategy ===] InpRSIReverseExitLevel = 49 // RSI Exit Level
  • [=== RSI Reverse Strategy ===] InpRSIReverseStartHour = 12 // RSI Reverse Start Hour (0-23)
  • [=== RSI Reverse Strategy ===] InpRSIReverseEndHour = 22 // RSI Reverse End Hour (0-23)
  • [=== RSI Reverse Strategy ===] InpRSIReverseCloseOutsideHours = false // Close trades outside trading hours
  • [=== RSI Reverse Strategy ===] InpRSIReverseCooldownBars = 11 // RSI Reverse Cooldown (bars)
  • [=== RSI Reverse Strategy ===] InpRSIReverseCooldownOnLoss = true // Apply cooldown only on loss
  • [=== EMA Cross Strategy ===] InpEMAPeriod = 175 // EMA Period
  • [=== EMA Cross Strategy ===] InpEMACrossStartHour = 22 // EMA Cross Start Hour (0-23)
  • [=== EMA Cross Strategy ===] InpEMACrossEndHour = 12 // EMA Cross End Hour (0-23)
  • [=== EMA Cross Strategy ===] InpEMACrossCloseOutsideHours = false // Close trades outside trading hours
  • [=== EMA Cross Strategy ===] InpUseEMADistanceEntry = true // Use EMA Distance Entry
  • [=== EMA Cross Strategy ===] InpEMADistancePips = 8440.0 // EMA Distance Threshold (pips)
  • [=== EMA Cross Strategy ===] InpEMADistancePeriod = 30 // EMA Distance Period (bars)
Pseudocode
// Pipsgrowth EX18091 TrendFollow — Execution Flow (from source analysis)
// Family: TrendFollow
// Multi-strategy EA combining RSI Follow, RSI Reverse and EMA Cross strategies with session filters and strategy locking. 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

EA Parameters

ParameterDefaultDescription
InpTimeframe0Timeframe (1=M1,2=M5,3=M15,4=M30,5=H1,6=H4,7=D1) // Trading Timeframe
InpLotSize0.01Lot Size
InpTradeComment"Psgrowth.com Expert_18091"Trade Comment
InpMagicNumberRSIFollow22218091Magic Number RSI Follow
InpMagicNumberRSIReverse22218092Magic Number RSI Reverse
InpMagicNumberEMACross22218093Magic Number EMA Cross
InpEnableRSIFollowtrueEnable RSI Follow Strategy
InpEnableRSIReversetrueEnable RSI Reverse Strategy
InpEnableEMACrosstrueEnable EMA Cross Strategy
InpEnableStrategyLockfalseEnable Strategy Lock
InpLockProfitThreshold120.0Lock Profit Threshold (pips)
InpCloseOppositeTradestrueClose Opposite Trades When Profiting
InpRSIPeriod49RSI Period
InpRSIOverbought81RSI Overbought Level
InpRSIOversold41RSI Oversold Level
InpRSIExitLevel48RSI Exit Level
InpRSIFollowStartHour24RSI Follow Start Hour (0-23)
InpRSIFollowEndHour8RSI Follow End Hour (0-23)
InpRSIFollowCloseOutsideHoursfalseClose trades outside trading hours
InpRSIReversePeriod159RSI Period
InpRSIReverseOverbought51RSI Overbought Level
InpRSIReverseOversold49RSI Oversold Level
InpRSIReverseCrossLevel54RSI Cross Level
InpRSIReverseExitLevel49RSI Exit Level
InpRSIReverseStartHour12RSI Reverse Start Hour (0-23)
InpRSIReverseEndHour22RSI Reverse End Hour (0-23)
InpRSIReverseCloseOutsideHoursfalseClose trades outside trading hours
InpRSIReverseCooldownBars11RSI Reverse Cooldown (bars)
InpRSIReverseCooldownOnLosstrueApply cooldown only on loss
InpEMAPeriod175EMA Period
InpEMACrossStartHour22EMA Cross Start Hour (0-23)
InpEMACrossEndHour12EMA Cross End Hour (0-23)
InpEMACrossCloseOutsideHoursfalseClose trades outside trading hours
InpUseEMADistanceEntrytrueUse EMA Distance Entry
InpEMADistancePips8440.0EMA Distance Threshold (pips)
InpEMADistancePeriod30EMA Distance Period (bars)
Source Code (.mq5)Open Source
Pipsgrowth_com_EX18091.mq5
#property copyright "Pipsgrowth.com"
#property link      "https://pipsgrowth.com"
#property version   "2.00"
#property strict
#property description "Pipsgrowth.com EX18091 main — RSI Follow/Reverse + EMA Cross multi-strategy, full 12-layer stack."

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

// Input Parameters
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_InpTimeframe = PERIOD_H1;
input group "=== General Settings ==="
input int InpTimeframe = 0; // Timeframe (1=M1,2=M5,3=M15,4=M30,5=H1,6=H4,7=D1)  // Trading Timeframe
input double InpLotSize = 0.01;               // Lot Size
input string InpTradeComment = "Psgrowth.com Expert_18091"; // Trade Comment
input int    InpMagicNumberRSIFollow = 22218091; // Magic Number RSI Follow
input int    InpMagicNumberRSIReverse = 22218092;// Magic Number RSI Reverse
input int    InpMagicNumberEMACross = 22218093;  // Magic Number EMA Cross

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;

Full source code available on download

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

Tags:ex18091trendfollowpipsgrowthfreemt5xauusd

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_EX18091.mq5
File Size27.5 KB
Versionv2.00
PlatformMetaTrader 5
File Type.mq5 Source
StrategyTrend Following
Risk LevelMedium Risk
Timeframes
M5H1
Currency Pairs
XAUUSD
Min. Deposit$100