P
PipsGrowth
Trend FollowingOpen Source – Free

Pipsgrowth EX18094 TrendFollow

MT5 Expert Advisor (Open Source) · XAUUSD · M5

Pipsgrowth.com EX18094 main — RSI scalping with target exits, full 12-layer stack.

Overview

Pipsgrowth EX18094 is a one-indicator RSI scalper built around a simple, almost mechanical recovery-then-fade thesis. The whole EA watches a single iRSI(14, applied price = close) on the configured timeframe — H1 by default because the TimeFrame input defaults to 9, which falls through the MapTimeframeInt switch to PERIOD_H1 — and trades a single position at a time. There is no regime classifier, no HTF confirmation, no session filter, no spread gate, no news filter, and no pyramid. Every entry and every exit is decided from the same 14-period RSI buffer, and the EA's behaviour from one tick to the next is fully captured in 9 functions totaling roughly 400 lines of MQL5.

The entry rule is a two-bar cross of the oversold or overbought line. The defaults shipped in the source are RSI_Oversold = 55 and RSI_Overbought = 82, which is a noticeably wider pair of thresholds than the 46/49 pair seen on most RSI-recovery EAs. The buy arm fires when rsi_two_bars_ago <= 55 AND rsi_prev > 55 — i.e. RSI spent a closed bar inside the 55-or-below zone and then closed the next bar back above 55. The sell arm is symmetric: rsi_two_bars_ago >= 82 AND rsi_prev < 82. The two-bars-ago check is the only debounce in the entry path; it kills the case where RSI whipsaws across 55 on two consecutive ticks but never actually closed there on a previous bar. The CheckEntrySignals() function calls OpenBuyPosition() or OpenSellPosition() directly, which call trade.Buy(LotSize, _Symbol, ask, 0, 0, ...) and trade.Sell(LotSize, _Symbol, bid, 0, 0, ...) — every bracket is zero, so the broker records the position with no attached stop loss and no take profit.

LotSize is a fixed input and the source ships it at 50, which is roughly two orders of magnitude above what a $100 minimum deposit would normally support on a 100 oz XAUUSD contract. This is a parameter that the operator is expected to set per account size, not a recommended default for the as-shipped account size. There is no risk-percent sizing, no balance-based scaler, and no margin check beyond the broker's own. CTrade is configured with magic 22218094, slippage 3 points, and ORDER_FILLING_FOK; FOK means the order either fills at the full requested size or does not fill at all, which is worth knowing if you change LotSize to something your broker cannot fill in one shot.

Exits are managed inside CheckExistingPosition() and they are the more interesting part of the EA, because there are two completely separate exit paths and they have a precedence relationship baked in. Path 1 is the target exit. For a long, the trade closes when rsi_current >= RSI_Target_Buy; for a short, when rsi_current <= RSI_Target_Sell. The default target values are 39 for the buy and 35 for the sell. Both targets are BELOW the 50 line and well below the entry thresholds of 55 and 82 — meaning the EA does not exit on momentum extension, it exits on reversion. You buy a recovery cross out of 55 and close the position when RSI gives back down to 39, which is exactly the kind of "buy the dip, take the bounce, don't be greedy" logic that produces tight equity curves on ranging instruments. Path 2 is the bars-against timeout, governed by BarsToWait (default 2). If RSI moves back against the open position — long when rsi_current < RSI_Oversold=55, short when rsi_current > RSI_Overbought=82 — the EA starts counting consecutive bars where the indicator is on the wrong side. The moment RSI returns to the friendly side the counter resets to 0; if the count reaches BarsToWait (2 closed bars in a row) the position is force-closed by ClosePosition(). This is effectively a 2-bar invalidation: if the recovery thesis doesn't prove itself within two candles, the trade is dead.

There is no price stop. The 0/0 brackets passed to trade.Buy() and trade.Sell() mean the broker's stop-out margin rule is the only price-based protection on every open position. A 50-lot position with no attached SL on a $100 account is a margin-call candidate the first time the broker's maintenance threshold is breached, so the practical use of this EA almost always requires the operator to set LotSize to a value the account can actually carry, or to layer an external stop in the form of a manual intervention or a second EA that watches the magic number. The EA itself has no opinion about position risk beyond "close after 2 bars of RSI going the wrong way" and "close when RSI reverts past the target line."

Position tracking is done with two booleans and an integer ticket. On every new bar — gated by the last_bar_time check at the top of OnTick() — UpdateRSI() copies the latest three RSI values into a buffer, CheckExistingPosition() runs first, and CheckEntrySignals() only runs if position_open is false. There is no PositionSelect(_Symbol) sweep, no magic-number scan of the entire open-positions list, and no recovery path for a position that was closed externally — if the broker closes the trade for any reason, the EA's internal state (position_ticket, position_open, bars_against_count) is reset on the next tick when PositionSelectByTicket() returns false. Retry logic for the close itself is implemented in TryClose_EX18094: 3 attempts with a 200 ms Sleep() between retries, retrying only on TRADE_RETCODE_REQUOTE, _TIMEOUT, _PRICE_OFF, or _PRICE_CHANGED, and breaking on any other return code. Two unused-but-compiled helpers, TryClosePartial_EX18094 and TryModify_EX18094, exist for partial closes and SL/TP modifications; both are dead code in this build because no SL or TP is ever set, and no partial close is ever requested.

OnTick() also short-circuits with two early returns: a Bars(_Symbol, g_TimeFrame) < RSI_Period + 2 guard that prevents the EA from running before enough history exists for the indicator to produce stable values, and a same-bar return inside the new-bar gate that prevents the EA from re-evaluating the same closed bar twice in succession. There is no Print() logging, no info panel, no OnTester() override, no OnTrade() callback, and no chart-object commentary. The EA is intentionally quiet — operators who want trade-level diagnostics need to switch on the strategy tester journal or wrap the EA in an external logging harness.

The MT5 package itself is the standard Pipsgrowth drop: one .mq5 file, the standard Trade.mqh include, and 12 inputs split into a one-row Identity group and a Strategy Settings group containing the timeframe, RSI period, applied-price selector, four RSI thresholds, the bars-to-wait integer, the LotSize double, the magic, and the slippage. A known source-level artifact is that MapTimeframeInt() and MapAppliedPriceInt() are each declared four times in the file (the second copy immediately above the g_TimeFrame = MapTimeframeInt(TimeFrame) call, and a third+fourth pair interleaved the same way above the second g_TimeFrame assignment), and the g_TimeFrame / g_RSI_Applied_Price globals are declared twice as well. The MQL5 compiler absorbs the duplicate function definitions without complaint, and runtime behaviour is unaffected because each function body is identical, but it is the most visually noisy code-smell in the build. Backtests on H1 XAUUSD with the as-shipped 50-lot default will not reflect the EA's real-world behaviour on a $100 account; reducing LotSize to a value proportional to balance is mandatory before drawing any conclusions from the Strategy Tester report.

The practical operating shape is: load the EA on a single chart, pick a timeframe inside the 1–7 range (H1 is the default and is what the code actually runs when the input is 9), set LotSize to a value the account can support, and let the 14-period RSI do all the work. The 55/82 entry zone is wide enough that signals fire on most days, the 39/35 target keeps each trade short, and the 2-bar timeout is the kill-switch. There is no news awareness, no spread filter, and no session gating, so the EA will continue to attempt entries during illiquid rollover windows and around high-impact releases; if you run it on a live account, either trade through those windows with reduced LotSize, or stop the EA before the calendar and restart it after.

Strategy Deep Dive

The whole EA collapses to a single iRSI(14, close) handle evaluated on every new bar of the configured timeframe. OnTick() short-circuits on a same-bar gate and on insufficient bar history, then calls UpdateRSI() to copy the latest three RSI values into rsi_buffer, runs CheckExistingPosition() to manage the live trade, and only invokes CheckEntrySignals() when position_open is false. The single-position gate is enforced by the boolean, not by a position scan, and CTrade is configured with magic 22218094, slippage 3 points, and ORDER_FILLING_FOK. TryClose_EX18094 wraps the close with 3 attempts of 200 ms between retries on requote/timeout/price-changed retcodes; TryClosePartial_EX18094 and TryModify_EX18094 are compiled but unreferenced because no SL/TP is ever set and no partial close is ever requested. There is no regime filter, no HTF confirmation, no session filter, no spread gate, no news filter, and no pyramid — the four pairs of duplicate MapTimeframeInt / MapAppliedPriceInt blocks in the source are a cosmetic artifact (the compiler absorbs them and the runtime is identical), and the TimeFrame=9 input falls through the 1–7 switch to PERIOD_H1.

Entry Signal

Buys fire when iRSI(14, close) on the configured timeframe (H1 by default) closes a bar inside the oversold zone and the next bar closes back above RSI_Oversold (default 55). Sells fire symmetrically when RSI closes above RSI_Overbought (default 82) and the next bar closes back below. The two-bars-ago check in CheckEntrySignals() acts as the only debounce, and OpenBuyPosition / OpenSellPosition submit trade.Buy / trade.Sell with 0/0 SL/TP brackets and the fixed LotSize input.

Exit Signal

Two paths in CheckExistingPosition(). Path 1: target exit — long closes when rsi_current >= RSI_Target_Buy (default 39, a reversion target below 50), short closes when rsi_current <= RSI_Target_Sell (default 35). Path 2: bars-against timeout — if RSI moves back through the entry threshold for BarsToWait consecutive closed bars (default 2), the position is force-closed; the counter resets the moment RSI returns to the friendly side.

Stop Loss

No price stop is attached at entry — trade.Buy / trade.Sell are called with 0,0 SL/TP. The only time-based stop is the BarsToWait=2 invalidation in CheckExistingPosition(). A 50-lot position with no attached stop is a margin-call risk on a $100 account, so the practical SL is whatever the broker's maintenance margin enforces and any external manual layer the operator chooses to add.

Take Profit

Target exit is the reversion thesis itself — close long at RSI_Target_Buy=39, close short at RSI_Target_Sell=35. Both targets sit below the 50 line, so the EA does not ride momentum to a profit-extension level, it closes on mean-reversion. There is no fixed-pip take profit and no multi-R target; the only other close is the 2-bar bars-against timeout, which functions as a kill-switch rather than a TP.

Best For

Best on XAUUSD M5–H1 (H1 is the actual runtime default because TimeFrame=9 falls through the switch). Minimum balance is the DB-listed $100 only if LotSize is reduced substantially from the as-shipped 50 — at the default lot the EA carries a margin-call risk the first time the broker's maintenance threshold is breached, so a $1,000–$5,000 account with LotSize tuned to roughly 0.05–0.20 per trade is the realistic operating window. The 55/82 entry zone, 39/35 reversion targets, and 2-bar timeout profile as a short-hold mean-reversion EA, so it works best in ranging or choppy gold conditions during the London and New York sessions when RSI regularly cycles between the entry and target zones; spread-sensitive brokers and high-impact news windows are the main risks because there is no spread filter and no news filter in the code.

Strategy Logic

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

Family: TrendFollow Magic: 22218094 Version: 2.00

BRIEF: RSI scalping EA entering on RSI oversold/overbought cross with target-based exits and bars-against timeout exit logic. 12 layers: REGIME, SIGNAL, ENTRY, CONFIRM, NO-TRADE, CAPITAL CAP, RISK, SIZING, MANAGE, EXIT, SCALING, OnTester

INDICATOR STACK:

  • Standard MT5 indicators

KEY FUNCTIONS:

  • UpdateRSI()
  • CheckExistingPosition()
  • CheckEntrySignals()
  • OpenBuyPosition()
  • OpenSellPosition()
  • ClosePosition()
  • TryClose_EX18094()
  • TryClosePartial_EX18094()
  • TryModify_EX18094()

INTERNAL CONSTANTS (0 total):

INPUT PARAMETERS (12 total across 2 groups):

  • [=== Identity ===] InpTradeComment = "Psgrowth.com Expert_18094" // Trade Comment
  • [=== Strategy Settings ===] TimeFrame = 9 // Timeframe (1=M1,2=M5,3=M15,4=M30,5=H1,6=H4,7=D1) // Timeframe for Analysis
  • [=== Strategy Settings ===] RSI_Period = 14 // RSI Period
  • [=== Strategy Settings ===] RSI_Applied_Price = 1 // Applied price (1=close,2=open,3=high,4=low,5=median,6=typical,7=weighted) // RSI Applied Price
  • [=== Strategy Settings ===] RSI_Overbought = 82 // RSI Overbought Level
  • [=== Strategy Settings ===] RSI_Oversold = 55 // RSI Oversold Level
  • [=== Strategy Settings ===] RSI_Target_Buy = 39 // RSI Target for Buy Exit
  • [=== Strategy Settings ===] RSI_Target_Sell = 35 // RSI Target for Sell Exit
  • [=== Strategy Settings ===] BarsToWait = 2 // Bars to wait when RSI goes against position
  • [=== Strategy Settings ===] LotSize = 50 // Lot Size
  • [=== Strategy Settings ===] MagicNumber = 22218094 // Magic Number
  • [=== Strategy Settings ===] Slippage = 3 // Slippage in points
Pseudocode
// Pipsgrowth EX18094 TrendFollow — Execution Flow (from source analysis)
// Family: TrendFollow
// RSI scalping EA entering on RSI oversold/overbought cross with target-based exits and bars-against timeout exit logic. 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:
M5

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
InpTradeComment"Psgrowth.com Expert_18094"Trade Comment
TimeFrame9Timeframe (1=M1,2=M5,3=M15,4=M30,5=H1,6=H4,7=D1) // Timeframe for Analysis
RSI_Period14RSI Period
RSI_Applied_Price1Applied price (1=close,2=open,3=high,4=low,5=median,6=typical,7=weighted) // RSI Applied Price
RSI_Overbought82RSI Overbought Level
RSI_Oversold55RSI Oversold Level
RSI_Target_Buy39RSI Target for Buy Exit
RSI_Target_Sell35RSI Target for Sell Exit
BarsToWait2Bars to wait when RSI goes against position
LotSize50Lot Size
MagicNumber22218094Magic Number
Slippage3Slippage in points
Source Code (.mq5)Open Source
Pipsgrowth_com_EX18094.mq5
#property copyright "Pipsgrowth.com"
#property link      "https://pipsgrowth.com"
#property version   "2.00"
#property strict
#property description "Pipsgrowth.com EX18094 main — RSI scalping with target exits, full 12-layer stack."

#include <Trade\Trade.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_TimeFrame = PERIOD_H1;
ENUM_APPLIED_PRICE g_RSI_Applied_Price = PRICE_CLOSE;
input group "=== Identity ==="
input string InpTradeComment = "Psgrowth.com Expert_18094"; // Trade Comment
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;

Full source code available on download

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

Tags:ex18094trendfollowpipsgrowthfreemt5xauusd

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