Pipsgrowth EX18099 TrendFollow
MT5 Expert Advisor (Open Source) · XAUUSD · M5
Pipsgrowth.com EX18099 RSIScalping — RSI overbought/oversold scalping with target exits, full 12-layer stack.
Overview
Pipsgrowth EX18099 TrendFollow is a single-indicator RSI scalper with one entry model on each side and a double exit gate. It runs a 14-period RSI on the close of the active timeframe (H1 by default — the TimeFrame=5 input maps to PERIOD_H1 inside the code, not the M5 listed in the database card) and trades every crossover through a fixed pair of trigger levels. It does not use ATR, ADX, EMAs, volume, or higher-timeframe confirmation; the decision is made entirely from the three most recent RSI bars.
The most important thing to know about this EA before you run it is that the input names are inverted relative to their conventional meaning. RSI_Oversold defaults to 50, and RSI_Overbought defaults to 19. The CheckEntrySignals function does not compare RSI to a deep-oversold zone and a deep-overbought zone — it compares RSI to a midline and a deep-oversold zone. A long fires when the RSI two-bars-ago value was at or below 50 and the previous-bar value crossed above 50. A short fires when the RSI two-bars-ago value was at or above 19 and the previous-bar value crossed below 19. In other words, the long is a midline-breakout entry, and the short is a momentum-exhaustion entry off a deep-oversold print. Calling them both RSI_Overbought/RSI_Oversold levels is misleading; the long side behaves like a momentum filter and the short side behaves like a contrarian reversion trigger.
Once a position is open, two independent exit conditions are evaluated on every new bar in CheckExistingPosition. The first is a target condition: the long closes when the current bar's RSI reaches 71 (RSI_Target_Buy = 71), and the short closes when the current bar's RSI reaches 70 (RSI_Target_Sell = 70). The two targets are deliberately close in value but asymmetric in the distance they need to travel. From a 50-entry long, the indicator has to climb 21 RSI points to print 71. From a 19-entry short, the indicator has to drop 51 points to print a 70 oversold reading, which in practice means the short target is rarely hit and most short exits are driven by the second path. The second exit path is a bars-against counter. If the long has been below 50 for BarsToWait=1 closed bar, the position closes; if the short has been above 19 for BarsToWait=1 closed bar, the position closes. The counter is forgiving — it resets the moment the indicator returns to the friendly side of the trigger — so a one-bar dip below 50 in an otherwise uptrending RSI does not flatten the long.
The architecture is intentionally minimal. There is one indicator handle — iRSI(14, PRICE_CLOSE) — and 9 functions: UpdateRSI, CheckExistingPosition, CheckEntrySignals, OpenBuyPosition, OpenSellPosition, ClosePosition, plus three retry helpers TryClose_EX18099, TryClosePartial_EX18099, and TryModify_EX18099. Only TryClose_EX18099 is actually called in the live code path; the partial-close and modify helpers are defined but unused. The trade object is configured with SetTypeFilling(ORDER_FILLING_FOK) and SetDeviationInPoints(3) in OnInit, and the slippage input is wired straight through. There is no OnTester function, no OnTradeTransaction handler, no equity-floor drawdown breaker, no regime classifier, no HTF alignment check, no news filter, no session filter, no spread cap, no consecutive-loss counter, and no equity-percent position sizing. The header advertises a "12-layer" stack in the comment block, but the actual implementation contains only the signal, the entry, and the exit layers — the rest of the stack named in the comment is aspirational.
Position sizing is the single biggest configuration concern. The LotSize input defaults to 50, which is a notional size intended for an institutional or test-harness context and will not work on a retail MT5 account. There is no risk-percent input and no balance-aware sizing helper — the value is passed verbatim to trade.Buy and trade.Sell inside OpenBuyPosition and OpenSellPosition. For live use on a $100–$1,000 account, you must lower this to whatever the broker's minimum lot allows, and treat the default as a placeholder, not a recommendation. The trade is opened with 0 SL and 0 TP at the CTrade level, so no bracket is attached — the only stop in the system is the bars-against exit on the next bar. There is no SL/TP modification loop; the TryModify_EX18099 helper exists but is not invoked by any of the active functions.
The single-position gate is enforced by a plain boolean. After OpenBuyPosition or OpenSellPosition writes the ticket from trade.ResultOrder() to position_ticket, the position_open flag prevents the OnTick loop from re-entering CheckEntrySignals on the next bar until the existing position is closed. There is no pyramiding, no hedging, no scaling-in, and no partial-close logic. When ClosePosition runs, it calls TryClose_EX18099 which attempts the CTrade.PositionClose up to three times, sleeping 200ms on requote/timeout/price-change responses, and clears the state on a successful DONE or DONE_PARTIAL return code.
The 12 inputs divide into three groups. The Strategy group holds TimeFrame (1-7 with H1 as the default fall-through), RSI_Period (default 14), RSI_Applied_Price (1-7 with PRICE_CLOSE as the fall-through), the four RSI thresholds, and BarsToWait (default 1). The Risk Management group contains only LotSize (default 50). The Identity group holds MagicNumber (22218099), InpTradeComment, and Slippage (default 3). There are no defines, no enum-style macro guards, and no compile-time constants — every numeric is a runtime input. Note that the source has 4 duplicate copies of the MapTimeframeInt and MapAppliedPriceInt helper functions spread across lines 32-130; this is a copy-paste artifact of the auto-template, not a runtime behavior, and the MQL5 compiler absorbs the duplicates into a single symbol.
What to expect in a backtest: this is a single-indicator, two-signal system with no risk-percentage and a 1-bar adverse-bar exit. The behavior will be choppy on H1 gold because the bars-against timeout (1 bar) lets through the first pullback and then closes the trade quickly on the second, often before a real pullback has finished. To tune it for a given symbol, the most useful inputs are RSI_Overbought (move it up if you want only deeply-oversold short triggers), RSI_Oversold (move it down toward 45 if you want the long to fire on a softer midline break), BarsToWait (raise it to 3-5 if you want the position to survive the first pullback), and the two targets. Treat the LotSize input as a placeholder and set it to your broker's allowed minimum. The 3-point slippage and FOK filling assume a low-spread, low-latency broker; on a wide-spread retail account, the slippage will eat a noticeable slice of any target hit, especially on the short side where the distance to the 70 target is short and the relative cost is high.
Strategy Deep Dive
OnInit creates a single iRSI(14, PRICE_CLOSE) handle bound to the timeframe produced by MapTimeframeInt(TimeFrame=5 → PERIOD_H1) and configures the CTrade object with FOK filling and 3-point slippage. On every tick, OnTick returns early until a new bar opens on the working timeframe, at which point UpdateRSI copies the last three RSI values into rsi_current, rsi_prev, and rsi_two_bars_ago. CheckExistingPosition then either exits on a target hit, exits on a BarsToWait=1 adverse bar, or does nothing; if no position is open, CheckEntrySignals compares the two-bar crossover against the RSI_Oversold=50 long trigger and the RSI_Overbought=19 short trigger, and OpenBuyPosition or OpenSellPosition fires a market order with 0 SL / 0 TP and the configured LotSize=50. The state machine is just three booleans — position_open, rsi_against_position, and bars_against_count — plus the ticket and the current position type.
Long entries fire on a closed-bar RSI(14) crossover through the RSI_Oversold input (default 50): the indicator must have been at or below 50 two bars ago and above 50 on the previous bar. Short entries fire when RSI(14) crosses down through the RSI_Overbought input (default 19) on the same two-bar pattern. Both signals are checked in CheckEntrySignals only when no position is currently open, and a single-position gate prevents re-entry until the existing trade is closed.
Each open position has two independent exit paths evaluated on every new bar: a target exit and a bars-against timeout. A long closes when current-bar RSI reaches 71 (RSI_Target_Buy) or after BarsToWait=1 closed bar below 50; a short closes when RSI reaches 70 (RSI_Target_Sell) or after 1 closed bar above 19. The bars-against counter resets the moment the indicator returns to the friendly side of its trigger, so a single adverse bar does not flatten the trade.
There is no fixed stop-loss. Positions are opened with 0 SL at the CTrade level; the only protective logic is the bars-against timeout, which closes the trade after BarsToWait=1 closed bar in the adverse zone of the RSI trigger. Risk is governed entirely by position sizing on entry and the RSI-based exit logic — no drawdown cap, no equity floor, no trailing stop, no break-even ratchet exists in the source.
There is no fixed take-profit; the CTrade call passes 0 for the TP parameter. Exits are RSI-level targets: long closes at RSI >= 71, short closes at RSI <= 70. The two targets sit close in absolute value but require different RSI distances from their respective entries (long needs +21 from 50, short needs -51 from 19), which makes the short target far less likely to be hit in practice.
Suited to traders running a single-indicator momentum/discriminator system on XAUUSD H1 (the TimeFrame=5 default fall-through) with a low-spread, low-latency ECN broker, on a minimum deposit of $100, MEDIUM risk. The LotSize input must be lowered to the broker's allowed minimum before live use because the 50-lot default is a placeholder. The two-layer exit (RSI target + 1-bar adverse-bar timeout) is most appropriate for short-duration trades where the operator wants a tight pullback filter and does not require drawdown protection, regime classification, or higher-timeframe alignment.
Strategy Logic
Pipsgrowth EX18099 TrendFollow — Strategy Logic Analysis (from .mq5 source)
Family: TrendFollow
Magic: 22218099
Version: 2.00
BRIEF:
RSI scalping EA that buys when RSI crosses up from oversold and sells when RSI crosses down from overbought. Exits when RSI reaches target levels or has been against the position for N bars. 12 layers: REGIME, SIGNAL, ENTRY, CONFIRM, NO-TRADE, CAPITAL CAP, RISK, SIZING, MANAGE, EXIT, SCALING, OnTester
INDICATOR STACK:
- Standard
MT5indicators
KEY FUNCTIONS:
UpdateRSI()CheckExistingPosition()CheckEntrySignals()OpenBuyPosition()OpenSellPosition()ClosePosition()TryClose_EX18099()TryClosePartial_EX18099()TryModify_EX18099()
INTERNAL CONSTANTS (0 total):
INPUT PARAMETERS (12 total across 3 groups):
- [=== Strategy ===]
TimeFrame= 5 //Timeframe(1=M1,2=M5,3=M15,4=M30,5=H1,6=H4,7=D1) // Timeframe for Analysis - [=== Strategy ===] RSI_Period = 14 //
RSIPeriod - [=== Strategy ===] RSI_Applied_Price = 1 // Applied price (1=close,2=open,3=high,4=low,5=median,6=typical,7=weighted) //
RSIApplied Price - [=== Strategy ===] RSI_Overbought = 19 //
RSIOverbought Level - [=== Strategy ===] RSI_Oversold = 50 //
RSIOversold Level - [=== Strategy ===] RSI_Target_Buy = 71 //
RSITarget for Buy Exit - [=== Strategy ===] RSI_Target_Sell = 70 //
RSITarget for Sell Exit - [=== Strategy ===]
BarsToWait= 1 // Bars to wait whenRSIgoes against position - [=== Risk Management ===]
LotSize= 50 // Lot Size - [=== Identity ===]
MagicNumber=22218099// Magic Number - [=== Identity ===]
InpTradeComment= "Psgrowth.com Expert_18099" // TradeComment - [=== Identity ===] Slippage = 3 // Slippage in points
// Pipsgrowth EX18099 TrendFollow — Execution Flow (from source analysis)
// Family: TrendFollow
// RSI scalping EA that buys when RSI crosses up from oversold and sells when RSI crosses down from overbought. Exits when RSI reaches target levels or has been against the position for N bars. 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 |
|---|---|---|
| TimeFrame | 5 | Timeframe (1=M1,2=M5,3=M15,4=M30,5=H1,6=H4,7=D1) // Timeframe for Analysis |
| RSI_Period | 14 | RSI Period |
| RSI_Applied_Price | 1 | Applied price (1=close,2=open,3=high,4=low,5=median,6=typical,7=weighted) // RSI Applied Price |
| RSI_Overbought | 19 | RSI Overbought Level |
| RSI_Oversold | 50 | RSI Oversold Level |
| RSI_Target_Buy | 71 | RSI Target for Buy Exit |
| RSI_Target_Sell | 70 | RSI Target for Sell Exit |
| BarsToWait | 1 | Bars to wait when RSI goes against position |
| LotSize | 50 | Lot Size |
| MagicNumber | 22218099 | Magic Number |
| InpTradeComment | "Psgrowth.com Expert_18099" | Trade Comment |
| Slippage | 3 | Slippage in points |
#property copyright "Pipsgrowth.com"
#property link "https://pipsgrowth.com"
#property version "2.00"
#property strict
#property description "Pipsgrowth.com EX18099 RSIScalping — RSI overbought/oversold 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 "=== Strategy ==="
input int TimeFrame = 5; // Timeframe (1=M1,2=M5,3=M15,4=M30,5=H1,6=H4,7=D1) // Timeframe for Analysis
input int RSI_Period = 14; // RSI Period
input int RSI_Applied_Price = 1; // Applied price (1=close,2=open,3=high,4=low,5=median,6=typical,7=weighted) // RSI Applied Price
input double RSI_Overbought = 19; // RSI Overbought Level
input double RSI_Oversold = 50; // RSI Oversold Level
input double RSI_Target_Buy = 71; // RSI Target for Buy Exit
input double RSI_Target_Sell = 70; // RSI Target for Sell Exit
input int BarsToWait = 1; // Bars to wait when RSI goes against position
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.
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.