P
PipsGrowth
Trend FollowingOpen Source – Free

Pipsgrowth EX16066 Trend

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

Pipsgrowth.com EX16066 Professional_Risk_Manager_EA_Fixed — EMA/RSI/MACD risk-managed trend EA (fixed), full 12-layer stack.

Overview

Pipsgrowth EX16066 is a daily-budgeted trend follower built for XAUUSD on the M5 and H1 timeframes. The header advertises a 12-layer architecture — REGIME, SIGNAL, ENTRY, CONFIRM, NO-TRADE, CAPITAL CAP, RISK, SIZING, MANAGE, EXIT, SCALING, OnTester — but in the code you actually see a focused entry engine with a hard daily P&L circuit breaker wrapped around it. The signal stack is the same triple-confirm recipe used across the EX16xxx trend family: a fast/slow EMA crossover plus an RSI filter plus a MACD-zero-line check, with an ATR(14) gate sitting in front of everything. The 'fixed' in the file name points at the OrderSend return-value discipline — every market entry and every forced close now inspects result.retcode and falls back to a print-and-skip on TRADE_RETCODE_DONE_PARTIAL or any other non-success code rather than silently logging success.

The entry path runs only on the open of a new bar. OnTick keeps a static lastBarTime; when iTime(_Symbol, PERIOD_CURRENT, 0) advances, the EA resets totalTradesOnBar to zero and calls CheckForTradingOpportunity(). Inside that function, two early exits keep position count low: if PositionsTotal() > 0 or the bar has already been traded (totalTradesOnBar >= 1), the EA returns without evaluating signals. So the practical behavior is single-position-at-a-time with a hard ceiling of one entry per bar. There is no explicit session or news filter — the gate is purely indicator-driven and the new-bar rhythm.

The signal itself is a strict AND of three conditions on the freshly-opened bar. For longs (CheckBullishSignal), the fast EMA must cross above the slow EMA on bar 0 (emaFast[1] <= emaSlow[1] && emaFast[0] > emaSlow[0]), RSI(14) must be inside the [30, 70] band (the default RSI_Oversold and RSI_Overbought values), and the MACD main line must be above zero. Shorts are the mirror: fast crosses below slow, RSI still inside the band, MACD below zero. The ATR(14) gate is the only volatility filter — bars where atrValue[0] < MinATR (default 0.0010) are skipped with a Print log so the EA does not chase into a dead market on XAUUSD. GetIndicatorValues pulls three samples of each moving average and two of the oscillator/volume/volatility buffer, and any failed CopyBuffer short-circuits the entry decision.

Position sizing is the standard percentage-of-balance recipe. CalculateLotSize reads the live AccountInfoDouble(ACCOUNT_BALANCE), multiplies by RiskPercent (default 2.0% of account) to get the dollar risk, and divides by StopLossPips * pipValue where pipValue is derived from tickValue * (0.0001 / tickSize). The resulting lot is snapped to the symbol's SYMBOL_VOLUME_STEP and clamped between SYMBOL_VOLUME_MIN and SYMBOL_VOLUME_MAX so it works on both micro-lot brokers and standard accounts. With the default 20-pip stop on gold, a $1,000 account risks $20 per trade.

Stop loss and take profit are pre-computed in OpenBuyPosition / OpenSellPosition before OrderSend. The stop is StopLossPips * point * 10 away from the entry ask or bid; the take-profit is the same distance multiplied by RiskRewardRatio (default 2.0), giving a fixed 1:2 reward-to-risk geometry. Magic number 22216066 and the trade comment Psgrowth.com Expert_16066 are attached to every request. The EA does not trail, does not break even, does not partial-close, and does not scale into winners — the only post-entry management is the daily circuit breaker.

The circuit breaker is what makes this EA behave differently from a vanilla crossover bot. UpdateDailyPnL detects a server-day rollover by integer-dividing TimeCurrent() by 86400 and resets startOfDayBalance to the current balance; from there the daily P&L is recomputed every tick as currentDayPnL = AccountInfoDouble(ACCOUNT_BALANCE) - startOfDayBalance. CheckDailyLimits converts that to a percentage of the day's starting balance and compares against MaxDailyLoss (default -5.0%) and DailyProfitTarget (default 3.0%). If either threshold is breached, dailyTradingAllowed is set to false, every open position is closed via CloseAllPositions with the comment Daily limit reached, and the EA returns from OnTick for the rest of the server day. New session, new budget. The MaxDailyRisk input (default 6.0%) is declared but never actually read by the code — it is exposed for documentation only.

The footer of the source includes three retry helpers — TryClose_EX16066, TryClosePartial_EX16066, and TryModify_EX16066 — built on the standard CTrade wrapper (g_trade_wrappers_EX16066) with up to three attempts and Sleep(200) or Sleep(100) waits on requote/timeout/price-changed/price-off. Like the other EAs in the family, none of these are called from the actual OnTick path; the live runtime uses raw OrderSend for both entries and CloseAllPositions. They are present as utility scaffolding for a future managed-positions extension, not as wired production logic.

Because the EA is a daily-budgeted single-position trend follower, the practical expectations are straightforward. The crossover-and-MACD gate produces a modest trade frequency — typical M5 gold setups yield a handful of entries per day, but the MinATR filter and the one-trade-per-bar cap mean low-volatility sessions often produce none. Realistic backtests will show long strings of small wins punctuated by occasional 2R wins, with the daily-loss cap mechanically truncating losing days at -5% regardless of how many stop-outs occur. There is no OnTester formula, no Monte Carlo robustness test, and no walk-forward machinery in the code; the only fitting discipline is the indicator-period and risk-percent inputs. Treat the defaults as starting points, optimize the EMA pair and the MinATR threshold to the broker's typical gold spread, and validate the daily P&L caps against the account size you actually intend to trade.

Strategy Deep Dive

Five indicator handles are created in OnInit (EMA fast/slow, RSI(14), MACD(12,26,9), ATR(14)) and released in OnDeinit. On each tick, UpdateDailyPnL recomputes session P&L as the delta from the day's opening balance, and CheckDailyLimits blocks trading and force-closes open positions if day P&L breaches either -5% or +3%. A new-bar guard built on a static lastBarTime then re-arms totalTradesOnBar to zero and runs CheckForTradingOpportunity, which pulls fresh indicator buffers, skips the bar if ATR is below the 0.0010 threshold, and routes to OpenBuyPosition or OpenSellPosition if the EMA crossover, RSI band, and MACD zero-line conditions all line up. The OpenBuy and OpenSell functions compute a 20-pip stop and a 1:2 take profit, derive a 2%-of-balance lot size via CalculateLotSize, and submit a market OrderSend with the magic 22216066 and the Psgrowth.com Expert_16066 comment. The three TryClose_EX16066 / TryClosePartial_EX16066 / TryModify_EX16066 retry helpers are scaffolded at the bottom of the file but the live trade path uses raw OrderSend for both entries and CloseAllPositions.

Entry Signal

Long entry fires on a new bar when the fast EMA(20) crosses above the slow EMA(50), RSI(14) sits inside the [30, 70] band, and the MACD(12,26,9) main line is above zero, with the additional ATR(14) >= 0.0010 volatility gate. Short entry is the strict mirror. Only one position is held at a time and a hard cap of one entry per bar is enforced via the totalTradesOnBar counter that resets on each new bar.

Exit Signal

There is no signal-based exit. The only active exit path is the daily P&L circuit breaker in CheckDailyLimits: if day P&L reaches +3% (DailyProfitTarget) or -5% (MaxDailyLoss), CloseAllPositions force-closes every open ticket with the comment Daily limit reached and the EA stops trading for the rest of the server day. The trailing, breakeven, and partial-close helpers TryClose_EX16066, TryClosePartial_EX16066, and TryModify_EX16066 are defined in the source but never invoked from the live runtime.

Stop Loss

Fixed 20-pip stop loss on every entry, computed as StopLossPips * _Point * 10 from the entry ask (buy) or bid (sell). There is no trailing stop, no breakeven, and no per-trade SL override. The only drawdown control beyond the per-trade stop is the account-level daily loss cap of -5% which closes everything once breached.

Take Profit

Fixed 1:2 reward-to-risk take profit at StopLossPips * RiskRewardRatio * _Point * 10 from entry (default 40 pips on the default 20-pip stop). TP is set in the original OrderSend request and is not subsequently modified — there is no scaling out, no partial close, and the live TryModify_EX16066 helper is never called.

Best For

Best for a $100 minimum-balance XAUUSD account (M5 or H1) on a broker that quotes gold with a 5-digit point and a tight tick size, where the trader wants a daily-bounded trend follower that cannot bleed past -5% in a single session. The fixed 20-pip stop, the 1:2 RR, and the percentage-based sizing make the risk per trade legible on small accounts; the daily P&L circuit breaker means the worst realistic day is capped even if the stop loss is skipped or widened by gap risk. Avoid on netting accounts where multiple-symbol hedging matters, on pairs other than gold (the ATR(0.0010) gate is calibrated to XAUUSD volatility), and on brokers with re-quote or requote-heavy execution where the OrderSend direct path may fail without the retry scaffolding being wired in.

Strategy Logic

Pipsgrowth EX16066 Trend — Strategy Logic Analysis (from .mq5 source)

Family: Trend Magic: 22216066 Version: 2.00

BRIEF: Professional risk manager EA (fixed version) with EMA crossover, RSI and MACD confirmation filtered by ATR. Enforces daily profit targets, max daily loss, and risk-per-trade sizing with proper OrderSend return-value checking. 12 layers: REGIME, SIGNAL, ENTRY, CONFIRM, NO-TRADE, CAPITAL CAP, RISK, SIZING, MANAGE, EXIT, SCALING, OnTester

INDICATOR STACK:

  • Standard MT5 indicators

KEY FUNCTIONS:

  • CheckDailyLimits()
  • UpdateDailyPnL()
  • CheckForTradingOpportunity()
  • GetIndicatorValues()
  • CheckBullishSignal()
  • CheckBearishSignal()
  • CalculateLotSize()
  • OpenBuyPosition()
  • OpenSellPosition()
  • CloseAllPositions()
  • TryClose_EX16066()
  • TryClosePartial_EX16066()
  • ...and 1 more

INTERNAL CONSTANTS (0 total):

INPUT PARAMETERS (18 total across 4 groups):

  • [=== Identity ===] MagicNumber = 22216066 // Magic number
  • [=== Identity ===] InpTradeComment = "Psgrowth.com Expert_16066" // Trade comment
  • [=== Risk Management ===] RiskPercent = 2.0 // Risk per trade (% of account)
  • [=== Risk Management ===] MaxDailyRisk = 6.0 // Maximum daily risk (%)
  • [=== Risk Management ===] DailyProfitTarget = 3.0 // Daily profit target (%)
  • [=== Risk Management ===] MaxDailyLoss = -5.0 // Maximum daily loss (%)
  • [=== Trade Settings ===] StopLossPips = 20 // Fixed stop loss in pips
  • [=== Trade Settings ===] RiskRewardRatio = 2.0 // Risk:Reward ratio
  • [=== Indicators ===] EMA_Fast = 20 // Fast EMA period
  • [=== Indicators ===] EMA_Slow = 50 // Slow EMA period
  • [=== Indicators ===] RSI_Period = 14 // RSI period
  • [=== Indicators ===] RSI_Oversold = 30.0 // RSI oversold level
  • [=== Indicators ===] RSI_Overbought = 70.0 // RSI overbought level
  • [=== Indicators ===] MACD_Fast = 12 // MACD fast EMA
  • [=== Indicators ===] MACD_Slow = 26 // MACD slow EMA
  • [=== Indicators ===] MACD_Signal = 9 // MACD signal line
  • [=== Indicators ===] MinATR = 0.0010 // Minimum ATR for trading
  • [=== Indicators ===] ATR_Period = 14 // ATR period
Pseudocode
// Pipsgrowth EX16066 Trend — Execution Flow (from source analysis)
// Family: Trend
// Professional risk manager EA (fixed version) with EMA crossover, RSI and MACD confirmation filtered by ATR. Enforces daily profit targets, max daily loss, and risk-per-trade sizing with proper OrderSend return-value checking. 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
MagicNumber22216066Magic number
InpTradeComment"Psgrowth.com Expert_16066"Trade comment
RiskPercent2.0Risk per trade (% of account)
MaxDailyRisk6.0Maximum daily risk (%)
DailyProfitTarget3.0Daily profit target (%)
MaxDailyLoss-5.0Maximum daily loss (%)
StopLossPips20Fixed stop loss in pips
RiskRewardRatio2.0Risk:Reward ratio
EMA_Fast20Fast EMA period
EMA_Slow50Slow EMA period
RSI_Period14RSI period
RSI_Oversold30.0RSI oversold level
RSI_Overbought70.0RSI overbought level
MACD_Fast12MACD fast EMA
MACD_Slow26MACD slow EMA
MACD_Signal9MACD signal line
MinATR0.0010Minimum ATR for trading
ATR_Period14ATR period
Source Code (.mq5)Open Source
Pipsgrowth_com_EX16066.mq5
#property copyright "Pipsgrowth.com"
#property link      "https://pipsgrowth.com"
#property version   "2.00"
#property strict
#property description "Pipsgrowth.com EX16066 Professional_Risk_Manager_EA_Fixed — EMA/RSI/MACD risk-managed trend EA (fixed), full 12-layer stack."
#include <Trade\Trade.mqh>

//--- Input parameters
input group "=== Identity ==="
input int      MagicNumber = 22216066;              // Magic number
input string   InpTradeComment = "Psgrowth.com Expert_16066"; // Trade comment

input group "=== Risk Management ==="
input double   RiskPercent = 2.0;           // Risk per trade (% of account)
input double   MaxDailyRisk = 6.0;          // Maximum daily risk (%)
input double   DailyProfitTarget = 3.0;     // Daily profit target (%)
input double   MaxDailyLoss = -5.0;         // Maximum daily loss (%)

input group "=== Trade Settings ==="
input int      StopLossPips = 20;           // Fixed stop loss in pips
input double   RiskRewardRatio = 2.0;       // Risk:Reward ratio

input group "=== Indicators ==="
input int      EMA_Fast = 20;               // Fast EMA period
input int      EMA_Slow = 50;               // Slow EMA period
input int      RSI_Period = 14;             // RSI period
input double   RSI_Oversold = 30.0;         // RSI oversold level
input double   RSI_Overbought = 70.0;       // RSI overbought level
input int      MACD_Fast = 12;              // MACD fast EMA
input int      MACD_Slow = 26;              // MACD slow EMA
input int      MACD_Signal = 9;             // MACD signal line
input double   MinATR = 0.0010;             // Minimum ATR for trading
input int      ATR_Period = 14;             // ATR period

//--- Global variables
double startOfDayBalance;
double currentDayPnL;
bool dailyTradingAllowed;
int totalTradesOnBar;

//--- Handles for indicators
int handleEMA_Fast, handleEMA_Slow, handleRSI, handleMACD, handleATR;

//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
{
    // Initialize indicators
    handleEMA_Fast = iMA(_Symbol, PERIOD_CURRENT, EMA_Fast, 0, MODE_EMA, PRICE_CLOSE);
    handleEMA_Slow = iMA(_Symbol, PERIOD_CURRENT, EMA_Slow, 0, MODE_EMA, PRICE_CLOSE);
    handleRSI = iRSI(_Symbol, PERIOD_CURRENT, RSI_Period, PRICE_CLOSE);
    handleMACD = iMACD(_Symbol, PERIOD_CURRENT, MACD_Fast, MACD_Slow, MACD_Signal, PRICE_CLOSE);
    handleATR = iATR(_Symbol, PERIOD_CURRENT, ATR_Period);

    // Check if indicators are created successfully
    if(handleEMA_Fast == INVALID_HANDLE || handleEMA_Slow == INVALID_HANDLE ||
       handleRSI == INVALID_HANDLE || handleMACD == INVALID_HANDLE ||
       handleATR == INVALID_HANDLE)
    {

Full source code available on download

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

Tags:ex16066trendpipsgrowthfreemt5xauusd

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