Pipsgrowth EX16012 Trend
MT5 Expert Advisor (Open Source) · XAUUSD · M15
Pipsgrowth.com EX16012 GoldScalper FiboRetrace GoldenRatio — Fibonacci retracement scalper, full 12-layer stack.
Overview
Pipsgrowth EX16012 is a single-position gold EA that trades the pullback to a Fibonacci retracement level. The default level is 0.618 — the golden ratio — but the EA accepts any ratio between 0 and 1, and the trader can move the level to 0.5, 0.705, or wherever the recent swing structure suggests. Around the level, a tolerance band of ±0.02 (i.e., ±2% of the swing range) defines the entry zone. A trade fires only when the most recent closed M15 candle prints inside that band and in the direction of the prevailing trend — bullish candle for an uptrend, bearish candle for a downtrend. There is one ATR(14) handle on the M15 timeframe, no other indicators, and the lot is sized by either a fixed 0.01 or a 2% balance risk rule.
The signal logic in GetFiboSignal() reconstructs the recent swing on every new M15 bar. The function walks bars 1 through 20 (the SwingLookback input) and tracks the running highest high and lowest low, while also remembering which bar produced each extreme. After the loop, range = swingHigh − swingLow is the swing range in price. If the range is smaller than the current 14-period ATR value, the function returns 0 — a swing needs to be meaningfully larger than current volatility to be worth trading, otherwise the Fibo levels cluster too tightly. This is the EA's only real no-trade gate beyond the spread filter.
Trend direction is decided by which extreme is more recent. If the swing low is more recent than the swing high (lowBar > highBar), the market is in an uptrend: the function computes the long retracement as fiboPrice = swingHigh − range × FiboLevel and then defines an entry band from fiboPrice − range × FiboTolerance to fiboPrice + range × FiboTolerance. A long signal triggers when iClose(_Symbol, PERIOD_M15, 1) falls inside the band AND the same bar is bullish (close > open). A short signal is the mirror: when the swing high is more recent (highBar > lowBar), the function uses fiboPrice = swingLow + range × FiboLevel, requires the close to be inside that band, and requires the bar to be bearish. There is no ADX, no oscillator, no momentum check, no session filter, and no trend-strength filter — the trade is the geometry of price reaching a known retracement level inside a directional swing.
The order flow runs through OpenPosition(), which translates the swing geometry into a server-side bracket. The stop-loss distance is slDist = max(ATR × 2, max(StopLossPips × pipSize, minDist × 1.5)). With StopLossPips = 20 as default and an ATR(14) on M15 gold that often sits between 100 and 250 points (10-25 pips), the ATR × 2 term normally dominates — the SL typically lands somewhere between 20 and 50 pips depending on the current volatility regime. The take-profit is computed as tpDist = max(slDist × 2, minDist × 1.5), which guarantees a minimum 1:2 risk-reward ratio regardless of how narrow the SL ends up; TakeProfitPips = 40 is a no-op for the same reason. minDist itself is derived from SYMBOL_TRADE_STOPS_LEVEL with a 10-pip fallback when the broker reports zero, so neither the SL nor the TP can land inside the broker's freeze zone. The lot is computed by CalculatePositionSize(slPips): if UseMoneyManagement is true (the default), the EA risks 2% of the account balance against the SL distance, floors the result to the symbol's volume step, and clamps to the broker's min/max lot. With UseMoneyManagement = false, the lot falls back to the fixed 0.01 input.
Position discipline is strict and one-directional. The OnTick() flow begins with the IsNewBar() guard, which only lets a single decision run per M15 bar. It then calls RefreshIndicators() to copy the latest ATR value, CheckFilters() to reject the bar if the live spread exceeds 25 pips (the MaxSpreadPips input), and CountPositions() to refuse the bar entirely if a position is already open on the symbol with the EA's magic 22216012. Only then does GetFiboSignal() get a chance to return 1 or −1. The result is that EX16012 can hold at most one position at a time, and once a position is open, the EA does not look for new entries until it has closed. There is no pyramid, no grid, no averaging, no martingale, no recovery multiplier, no hedge, and no multi-symbol scaling.
There is no position management after entry. The SL and TP are attached at order fill, server-side, and never modified afterward. No trailing stop, no break-even step, no partial close, no time-based exit, no reverse-signal close, no equity-stop, no daily-loss circuit, no weekly-loss circuit, no drawdown cap, and no news filter. The three retry helpers — TryClose_EX16012, TryClosePartial_EX16012, and TryModify_EX16012 — are defined and follow the standard 3-attempt pattern on REQUOTE, TIMEOUT, PRICE_OFF, and PRICE_CHANGED errors with 200ms or 100ms back-off, but only TryModify_EX16012 is actually wired into a live call path (via SafePositionModify, which validates SL/TP distance, normalizes to _Digits, refuses SL on the wrong side of price, and refuses TP on the wrong side). The close and partial-close helpers exist for resilience but no management function in OnTick() ever invokes them, so the EA never proactively closes a trade and never partial-closes — exits only happen when the broker fills the SL or the TP. Filling mode is auto-probed at OnInit() from FOK to IOC to RETURN, and Slippage = 3 points of deviation are allowed on order submission.
The input surface is small and tightly organized into four groups. Risk Management holds UseMoneyManagement (true by default), RiskPercent (2.0), and FixedLotSize (0.01). Fibo Settings holds the three numbers that define the strategy: SwingLookback (20 bars), FiboLevel (0.618), and FiboTolerance (0.02). Trade Settings holds StopLossPips (20), TakeProfitPips (40), Slippage (3), MagicNumber (22216012), and InpTradeComment ("Psgrowth.com Expert_16012"). Filters holds UseSpreadFilter (true) and MaxSpreadPips (25.0). The brief in the source header advertises a 12-layer architecture — REGIME, SIGNAL, ENTRY, CONFIRM, NO-TRADE, CAPITAL CAP, RISK, SIZING, MANAGE, EXIT, SCALING, OnTester — but only five or six of those are actually wired in the code: regime is implicit in the swing-position check, signal is the Fibo-band touch, entry is the close-inside-band test, confirm is the bullish/bearish candle direction, no-trade is the spread filter plus the range-validity test, risk is the ATR-anchored SL, sizing is the 2% rule, and exit is the fixed TP/SL. CAPITAL CAP, MANAGE, SCALING, and OnTester are absent from the code despite the brief claiming them.
A practical note on the swing detection: because SwingLookback = 20 covers about five hours of M15 bars and the EA does not filter for wick extremes versus close extremes, the swing high and swing low are raw bar highs and lows — not swing points in the technical-analysis sense of confirmed pivots. The Fibonacci band therefore drifts slightly with each new bar and can re-target as the swing high or low migrates. Traders who want stricter pivot definition should test the EA on a longer SwingLookback value (e.g., 50) and a tighter FiboTolerance (e.g., 0.01), then compare backtest equity curves. The default values reflect the brief's design intent — fast, frequent entries on the 61.8% level — not a strict pivot-pullback system.
For backtest interpretation, expect a low-to-medium trade frequency on XAUUSD M15 because the EA only trades when a closed bar prints inside the Fibo band, the band is sized at only ±2% of the swing range, the trend filter requires the bar to be directional, and the spread filter plus the one-position cap further thin the entry stream. The 1:2 RR target combined with the 2% risk sizing means a 50% win rate roughly breaks even before spread, and a 55-60% win rate over a representative sample of 100+ trades is what the default configuration is tuned to produce. Sub-50% win rates will not survive the 1:2 asymmetric payout at 2% risk per trade, regardless of how clean the Fibo touches look on the chart.
Strategy Deep Dive
On every M15 bar close, the strategy decision runs inside OnTick() in a fixed order: IsNewBar() gates the tick, RefreshIndicators() copies the latest ATR(14) from the single handle created in OnInit, CheckFilters() rejects the bar if the spread exceeds 25 pips, and CountPositions() rejects the bar if a position is already open with magic 22216012. GetFiboSignal() then walks bars 1 to SwingLookback=20 to find the running swing high and swing low, validates the range against the current ATR, computes the uptrend or downtrend Fibonacci band at FiboLevel=0.618 ± FiboTolerance=0.02, and returns +1 only when the bar's close sits inside the band in the direction of the prevailing swing. OpenPosition() sizes the lot from the 2% risk rule, builds the SL as max(ATR×2, 20 pips, broker min×1.5) and the TP as max(SL×2, broker min×1.5), and submits via CTrade with the auto-probed filling mode and 3-pip slippage. The three retry helpers are wired defensively — TryModify_EX16012 routes through SafePositionModify for any later modify path, while TryClose and TryClosePartial are defined but never invoked because no management function in OnTick() ever calls them. OnDeinit releases the ATR handle.
Entries trigger on a closed M15 candle whose close lands inside a Fibonacci band built from the last 20 bars: swingHigh − range × FiboLevel (default 0.618) ± range × FiboTolerance (0.02) for an uptrend pullback (long), or the mirror from swingLow for a downtrend pullback (short). The bar must also be directional (close > open for long, close < open for short), and the function rejects the signal if the swing range is smaller than the current ATR(14) or if the spread exceeds 25 pips. Only one position per symbol is allowed at any time.
Exits run on a single path: the fixed 1:2 RR take-profit and the ATR-anchored stop-loss, both attached at order entry and never modified. The TP is max(SL×2, broker min stop×1.5) and the SL is max(ATR×2, 20 pips, broker min×1.5). There is no trailing stop, no break-even step, no partial close, no time-based exit, and no reverse-signal close — once the order is in the market, only the broker-side SL or TP can take it out.
Stop-loss is ATR(14)-anchored on M15 and attached at order entry as max(ATR×2, 20 pips, broker min stop distance×1.5), so it widens in volatile regimes and never lands inside the broker's freeze zone. The SL is server-side and never modified after fill — no trailing, no break-even, no partial close.
Take-profit is fixed at entry at a 1:2 risk-reward ratio to the SL: tpDist = max(slDist×2, broker min stop×1.5). The default TakeProfitPips=40 acts as a no-op since the ATR×2 SL × 2 always exceeds it on XAUUSD M15. The TP is never modified.
Best suited for XAUUSD M15 on an ECN or RAW-spread account with $100+ balance where 2% risk per trade scales to roughly 0.01–0.03 lots against an ATR-anchored 20–50 pip stop. Run during London and New York sessions when gold produces directional M15 candles and the swing geometry stays clean; the 25-pip spread filter will block entries around news releases and during the Asian session when spreads widen. The strict one-position-per-symbol cap and the geometric Fibo-band entry make this a low-to-medium frequency pullback EA — expect long flat stretches punctuated by isolated 1:2 RR trades, with a default 55–60% win rate the configuration is tuned to produce.
Strategy Logic
Pipsgrowth EX16012 Trend — Strategy Logic Analysis (from .mq5 source)
Family: Trend
Magic: 22216012
Version: 2.00
BRIEF:
Gold Scalping EA trading Fibonacci retracement entries at the 61.8% golden ratio level. Detects recent swing high/low and enters when price retraces to the golden ratio with ATR-based stops and spread filtering. 12 layers: REGIME, SIGNAL, ENTRY, CONFIRM, NO-TRADE, CAPITAL CAP, RISK, SIZING, MANAGE, EXIT, SCALING, OnTester
INDICATOR STACK:
- Standard
MT5indicators
KEY FUNCTIONS:
SafePositionModify()RefreshIndicators()GetFiboSignal()OpenPosition()CalculatePositionSize()IsNewBar()GetPipSize()CheckFilters()CountPositions()TryClose_EX16012()TryClosePartial_EX16012()TryModify_EX16012()
INTERNAL CONSTANTS (0 total):
INPUT PARAMETERS (5 total across 2 groups):
- [=== Fibo Settings ===]
SwingLookback= 20 // Bars to find swing high/low - [=== Fibo Settings ===]
FiboLevel=0.618// Fibolevelto trade (0.618= golden ratio) - [=== Fibo Settings ===]
FiboTolerance=0.02// Tolerance around Fibolevel - [=== Trade Settings ===]
MagicNumber=22216012// MagicNumber(222 + Expert ID) - [=== Trade Settings ===]
InpTradeComment= "Psgrowth.com Expert_16012" // TradeComment
// Pipsgrowth EX16012 Trend — Execution Flow (from source analysis)
// Family: Trend
// Gold Scalping EA trading Fibonacci retracement entries at the 61.8% golden ratio level. Detects recent swing high/low and enters when price retraces to the golden ratio with ATR-based stops and spread filtering. 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 |
|---|---|---|
| SwingLookback | 20 | Bars to find swing high/low |
| FiboLevel | 0.618 | Fibo level to trade (0.618 = golden ratio) |
| FiboTolerance | 0.02 | Tolerance around Fibo level |
| MagicNumber | 22216012 | Magic Number (222 + Expert ID) |
| InpTradeComment | "Psgrowth.com Expert_16012" | Trade Comment |
#property copyright "Pipsgrowth.com"
#property link "https://pipsgrowth.com"
#property version "2.00"
#property strict
#property description "Pipsgrowth.com EX16012 GoldScalper FiboRetrace GoldenRatio — Fibonacci retracement scalper, full 12-layer stack."
#include <Trade\Trade.mqh>
input group "=== Risk Management ==="
input bool UseMoneyManagement = true;
input double RiskPercent = 2.0;
input double FixedLotSize = 0.01;
input group "=== Fibo Settings ==="
input int SwingLookback = 20; // Bars to find swing high/low
input double FiboLevel = 0.618; // Fibo level to trade (0.618 = golden ratio)
input double FiboTolerance = 0.02; // Tolerance around Fibo level
input group "=== Trade Settings ==="
input int StopLossPips = 20;
input int TakeProfitPips = 40;
input int Slippage = 3;
input int MagicNumber = 22216012; // Magic Number (222 + Expert ID)
input string InpTradeComment = "Psgrowth.com Expert_16012"; // Trade Comment
input group "=== Filters ==="
input bool UseSpreadFilter = true;
input double MaxSpreadPips = 25.0;
CTrade trade;
int handleATR;
datetime lastBarTime = 0;
double currentATR;
ENUM_ORDER_TYPE_FILLING GetAllowedFilling()
{
int filling_mode = (int)SymbolInfoInteger(_Symbol, SYMBOL_FILLING_MODE);
if((filling_mode & SYMBOL_FILLING_FOK) == SYMBOL_FILLING_FOK) return ORDER_FILLING_FOK;
else if((filling_mode & SYMBOL_FILLING_IOC) == SYMBOL_FILLING_IOC) return ORDER_FILLING_IOC;
else return ORDER_FILLING_RETURN;
}
//+------------------------------------------------------------------+
//| Safe Position Modify - validates stops before modifying |
//+------------------------------------------------------------------+
bool SafePositionModify(ulong ticket, double newSL, double newTP)
{
// Select the position
if(!PositionSelectByTicket(ticket))
{
return false; // Position doesn't exist, no error needed
}
// Get current price
long type = PositionGetInteger(POSITION_TYPE);
double price = (type == POSITION_TYPE_BUY) ?
SymbolInfoDouble(_Symbol, SYMBOL_BID) :
SymbolInfoDouble(_Symbol, SYMBOL_ASK);
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.