P
PipsGrowth
ScalpingOpen Source – Free

Pipsgrowth EX10015 Momentum-Scalper

MT5 Expert Advisor (Open Source) · XAUUSD · M15

Pipsgrowth.com EX10015 GoldScalper CCIMomentum — CCI zero-line cross momentum scalper, full 12-layer stack.

Overview

Pipsgrowth EX10015 is a single-indicator momentum scalper that listens to the Commodity Channel Index on a 15-minute chart and trades the moment the oscillator crosses the zero line. There is no EMA, no RSI confirmation, no ADX regime gate, no higher-timeframe filter — the entire decision tree reduces to one question: did CCI just flip sign? That minimalism is the EA's defining choice, and it shapes every other design decision that follows.

The signal itself is produced inside GetCCISignal(). The EA pulls two CCI values — the most recent completed bar (currentCCI, taken from bar index 1) and the bar before that (prevCCI) — and applies a strict two-condition rule. A long entry fires only when prevCCI <= 0 and currentCCI > 0 — the previous bar's momentum was non-positive and the new bar just pushed above the line. A short entry fires only when prevCCI >= 0 and currentCCI < 0. There is no smoothing, no buffer, no overbought or oversold gating on entry; if CCI isn't in the act of crossing, no signal. The CCI is calculated on PRICE_TYPICAL with the standard 14-period lookback — nothing exotic, no deviation multiplier overrides, just the textbook formula running on M15 candles.

ATR(14) on the same M15 timeframe is the only other indicator and is used solely for stop placement, not signal generation. Inside OpenPosition(), the EA computes slDist = max(currentATR * 1.5, StopLossPips * pipSize, minDist * 1.5) — a hybrid floor where the larger of ATR-1.5×, the 15-pip user input, and 1.5× the broker's SYMBOL_TRADE_STOPS_LEVEL wins. This means on quiet gold days the stop holds at the ATR value, on volatile days it widens with the range, and on broker-restricted symbols it never sits closer than the minimum distance the venue enforces. The take-profit distance is fixed at slDist * 2, giving a 1:2 reward-to-risk placement on every trade. The combination of zero-line cross entry and 1:2 R-mult TP means the strategy is a momentum catcher — it pays a wide stop so that two-thirds of the time the trade probably loses, and the rare CCI continuations it catches are expected to pay double the risk.

Position management runs on every tick through ManageOpenPositions(). Two exit paths are active in parallel. The first is a CCI-exit: if a long position is open and the most recent currentCCI reaches the overbought level of +100, the EA closes the position immediately; symmetrically, shorts close when CCI reaches -100. The currentCCI variable is the same one refreshed in RefreshIndicators() for the new bar, so this exit can fire as the trade's momentum collapses. The second exit is a trailing stop, controlled by the UseTrailingStop, TrailingStartPips (10) and TrailingStepPips (5) inputs. The trail activates only after unrealized profit exceeds TrailingStartPips * pipSize, and once active it ratchets the stop in TrailingStepPips-sized increments via SafePositionModify(). The safe-modify wrapper validates the proposed stop against SYMBOL_TRADE_STOPS_LEVEL before sending the modify, falling back to the minimum distance if the proposed ratchet would sit too close to the current bid/ask.

A single hard position-size cap governs entries: CountPositions() >= 1 returns true and blocks any new signal. The EA does not pyramid, does not scale into winners, and does not hold a long and a short at the same time. The next signal waits until the current position is closed by TP, SL, CCI exit, or trailing stop. This single-position discipline is what makes the trailing stop meaningful — the EA never has to choose which of several open positions to ratchet.

Lot sizing runs through CalculatePositionSize() with a 2% risk budget (RiskPercent = 2.0) and a FixedLotSize = 0.01 fallback when UseMoneyManagement is off. The risk lot formula is the standard (balance * riskPct) / (slPips * pipValuePerLot), floored to the symbol's SYMBOL_VOLUME_STEP and clamped to SYMBOL_VOLUME_MIN and SYMBOL_VOLUME_MAX. A separate hard ceiling InpMaxLot = 5.0 blocks any single trade from exceeding five lots regardless of account size. Order execution uses CTrade with GetAllowedFilling() probing SYMBOL_FILLING_MODE and selecting FOK > IOC > RETURN in that priority. OpenPosition() runs three attempts with a 500-millisecond sleep and a slippage ramp that grows by 5 points per attempt (3, 8, 13); only REQUOTE/TIMEOUT/PRICE_OFF/PRICE_CHANGED class failures are caught and the dev value is widened accordingly.

Risk hardening is split between the deal-stream watcher and the per-tick safety gate. OnTradeTransaction() listens for TRADE_TRANSACTION_DEAL_ADD events, looks up the new deal in a 90-day HistorySelect() window, filters to deals whose DEAL_MAGIC matches the EA and whose entry is DEAL_ENTRY_OUT, and accumulates DEAL_PROFIT + DEAL_SWAP + DEAL_COMMISSION into g_realizedToday and g_realizedWeek. Consecutive losses increment g_consecLosses and set a g_cooldownUntil timestamp 30 minutes in the future; a single win resets the counter. IsSafeToTrade_EX10015() runs on each new bar and applies eight independent gates in this order: capital cap opt-in (if InpCapAmount > 0 and equity exceeds the cap, no new trades), capital floor (InpCapFloor = 50 blocks entries if equity drops below), equity floor (InpMinEquityPercent = 95% of initial balance), daily loss limit (3% of effective capital), weekly loss limit (twice the daily limit, i.e. 6%), consecutive-loss cooldown (3 losses → 30-minute lockout), per-day trade limit (50), market-open check (closes for Friday 22:00+ GMT, Saturday, and Sunday before 22:00 GMT), session filter (London 7-16 GMT or New York 12-21 GMT, with Asia 0-7 GMT avoided by default), and an optional news-time filter (15-minute window around the London or NY open, disabled by default). The GMT offset is auto-detected on OnInit by scanning PERIOD_H1 for the first weekend gap and computing hour - 22, with InpServerGMTOffset available to override.

The EA's OnTester() criterion is (netProfit * profitFactor) / (1 + relativeDrawdownPct) with a 30-trade minimum; backtests with fewer trades return 0.0, which means the strategy tester will rank the EA as having zero edge when the sample is too small. The two function TryClose_EX10015() and TryModify_EX10015() handle close and modify with three attempts at 200ms and 100ms sleeps respectively, retrying only on the four transient retcodes (REQUOTE, TIMEOUT, PRICE_OFF, PRICE_CHANGED) and breaking on permanent rejections.

In backtest, expect a low win rate — CCI zero-line crosses on M15 are common but most fail to extend into 2× ATR of follow-through. The trades that do extend pay for the rest. Position duration is short, typically a few M15 bars before either the trailing stop activates or the CCI opposite extreme fires. The 1:2 reward-to-risk setup means the strategy needs roughly a 35-40% win rate to break even before spread and slippage, and the trailing stop is what keeps the early-momentum winners from giving back their gains. A $100 minimum deposit is feasible for micro-lot testing, but a $1,000+ balance is more honest for live use given the 2% per-trade risk and the EA's willingness to fire multiple signals per session.

Strategy Deep Dive

The EA runs its full decision tree on each new M15 bar. OnTick() first calls UpdateDailyCounters_EX10015() to roll the daily PnL/trade counters at midnight server time, then runs ManageOpenPositions() to handle any open trade's CCI exit or trailing-stop ratchet on every tick, and only then asks IsNewBar() whether the M15 candle has just closed. If it has, IsSafeToTrade_EX10015() runs the eight safety gates before RefreshIndicators() pulls fresh CCI and ATR values; if both buffers are filled, CheckFilters() enforces the spread cap of 25 pips, and CountPositions() confirms no trade is already open, then GetCCISignal() returns +1, -1, or 0 based purely on the two-bar zero-line cross. A non-zero signal hands off to OpenPosition(), which uses GetAllowedFilling() to pick FOK > IOC > RETURN, calculates risk-based lot size in CalculatePositionSize(), and runs three execution attempts at 500ms with a slippage ramp of 3, 8, 13. Realized PnL aggregation and consecutive-loss tracking happen passively in OnTradeTransaction() by listening for TRADE_TRANSACTION_DEAL_ADD events and walking a 90-day deal history. Session and market-open checks run in GMT, with the offset auto-detected from the first PERIOD_H1 weekend gap on OnInit.

Entry Signal

A long signal fires on the M15 bar that closes with prevCCI <= 0 and currentCCI > 0 — the oscillator's zero line has just been crossed upward. A short signal is the strict mirror: prevCCI >= 0 and currentCCI < 0. No additional filters apply at entry beyond the EA's eight safety gates (capital cap, equity floor, daily/weekly loss limits, cooldown, session filter, market-open check, optional news filter). Only one position is ever held at a time.

Exit Signal

Positions close on whichever happens first: a take-profit hit at exactly 2× the entry stop distance, the M15 close of the opposite candle after currentCCI reaches the overbought/oversold threshold (+100/-100), or a trailing-stop ratchet once unrealized profit clears 10 pips and the stop steps forward in 5-pip increments. The CCI exit is processed inside ManageOpenPositions() on every tick via TryClose_EX10015() with three retries at 200ms.

Stop Loss

Stop loss is hybrid: max(currentATR(14) * 1.5, 15 pips, SYMBOL_TRADE_STOPS_LEVEL * 1.5 * _Point). The trailing stop activates only after unrealized profit exceeds 10 pips and ratchets the stop in 5-pip increments via SafePositionModify(), with minimum-distance enforcement on every modify attempt.

Take Profit

Take profit is fixed at slDist * 2 — exactly double the entry stop distance — for a 1:2 reward-to-risk placement on every trade. The TP is set as a hard limit on order entry inside OpenPosition() and is not adjusted afterwards; it can be modified by the trailing-stop ratchet only if the ratchet explicitly passes a new TP value, which it does not.

Best For

Designed for XAUUSD M15 with a recommended minimum balance of $100 (micro-lot testing) to $1,000+ for honest live use given the 2% per-trade risk. Best run on an ECN or low-spread broker with MaxSpreadPips kept at 25 or below; the trailing stop's 5-pip ratchet step assumes a tight-spread environment on gold. Active sessions are London (7-16 GMT) and New York (12-21 GMT), with Asia (0-7 GMT) avoided by default — the EA is essentially a London-NY momentum scalper. Not suitable for accounts that cannot tolerate 50+ trades per day or for traders who want a single trade to run overnight; the InpMaxConsecLosses = 3 / InpCooldownMinutes = 30 configuration means three losses in a row will halt the EA for half an hour mid-session.

Strategy Logic

Pipsgrowth EX10015 Momentum-Scalper — Strategy Logic Analysis (from .mq5 source)

Family: Momentum-Scalper Magic: 22210015 Version: 2.00

BRIEF: Gold scalping EA using CCI momentum zero-line crosses for directional entries. Buys when CCI crosses above zero, sells when it crosses below. Exits on CCI reaching extreme levels (+/-100) or trailing stop. Includes money management and spread filter. 12 layers: REGIME, SIGNAL, ENTRY, CONFIRM, NO-TRADE, CAPITAL CAP, RISK, SIZING, MANAGE, EXIT, SCALING, OnTester

INDICATOR STACK:

  • Standard MT5 indicators

KEY FUNCTIONS:

  • SafePositionModify()
  • OnTradeTransaction()
  • RefreshIndicators()
  • GetCCISignal()
  • OpenPosition()
  • CalculatePositionSize()
  • ManageOpenPositions()
  • IsNewBar()
  • GetPipSize()
  • CheckFilters()
  • CountPositions()
  • EffectiveCapital_EX10015()
  • ...and 9 more

INTERNAL CONSTANTS (0 total):

INPUT PARAMETERS (17 total across 3 groups):

  • [=== Trade Settings ===] InpTradeComment = "Psgrowth.com Expert_10015" // Trade Comment
  • [=== Hardening: Risk Management ===] InpDailyLossLimitPct = 3.0 // Daily loss limit (% of effective capital)
  • [=== Hardening: Risk Management ===] InpMaxLot = 5.0 // Hard lot cap per trade
  • [=== Hardening: GMT Sessions ===] InpServerGMTOffset = 0 // Server GMT offset hours (0=auto-detect)
  • [=== Hardening: GMT Sessions ===] InpLondonStartHour = 7 // London session start (GMT)
  • [=== Hardening: GMT Sessions ===] InpLondonEndHour = 16 // London session end (GMT)
  • [=== Hardening: GMT Sessions ===] InpNYStartHour = 12 // New York session start (GMT)
  • [=== Hardening: GMT Sessions ===] InpNYEndHour = 21 // New York session end (GMT)
  • [=== Hardening: GMT Sessions ===] InpAvoidAsia = true // Avoid Asian session
  • [=== Hardening: GMT Sessions ===] InpAsiaStartHour = 0 // Asian session start (GMT)
  • [=== Hardening: GMT Sessions ===] InpAsiaEndHour = 7 // Asian session end (GMT)
  • [=== Hardening: GMT Sessions ===] InpNewsFilter = false // Avoid trading near news session opens
  • [=== Hardening: GMT Sessions ===] InpNewsFilterMinutes = 15 // Minutes to avoid around news
  • [=== Hardening: GMT Sessions ===] InpMaxTradesPerDay = 50 // Maximum trades per day
  • [=== Hardening: GMT Sessions ===] InpMinEquityPercent = 95.0 // Stop trading if equity < this % of initial balance
  • [=== Hardening: GMT Sessions ===] InpCooldownMinutes = 30 // Cooldown minutes after consec losses
  • [=== Hardening: GMT Sessions ===] InpMaxConsecLosses = 3 // Max consecutive losses before cooldown
Pseudocode
// Pipsgrowth EX10015 Momentum-Scalper — Execution Flow (from source analysis)
// Family: Momentum-Scalper
// Gold scalping EA using CCI momentum zero-line crosses for directional entries. Buys when CCI crosses above zero, sells when it crosses below. Exits on CCI reaching extreme levels (+/-100) or trailing stop. Includes money management and spread filter. 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:
M15

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 from the Navigator onto any chart (M1 or M5 recommended)
  7. 7In the EA dialog, enable Allow Algo Trading and set your lot size
  8. 8Click OK — the EA will begin trading automatically

EA Parameters

ParameterDefaultDescription
InpTradeComment"Psgrowth.com Expert_10015"Trade Comment
InpDailyLossLimitPct3.0Daily loss limit (% of effective capital)
InpMaxLot5.0Hard lot cap per trade
InpServerGMTOffset0Server GMT offset hours (0=auto-detect)
InpLondonStartHour7London session start (GMT)
InpLondonEndHour16London session end (GMT)
InpNYStartHour12New York session start (GMT)
InpNYEndHour21New York session end (GMT)
InpAvoidAsiatrueAvoid Asian session
InpAsiaStartHour0Asian session start (GMT)
InpAsiaEndHour7Asian session end (GMT)
InpNewsFilterfalseAvoid trading near news session opens
InpNewsFilterMinutes15Minutes to avoid around news
InpMaxTradesPerDay50Maximum trades per day
InpMinEquityPercent95.0Stop trading if equity < this % of initial balance
InpCooldownMinutes30Cooldown minutes after consec losses
InpMaxConsecLosses3Max consecutive losses before cooldown
Source Code (.mq5)Open Source
Pipsgrowth_com_EX10015.mq5
#property copyright "Pipsgrowth.com"
#property link      "https://pipsgrowth.com"
#property version   "2.00"
#property strict
#property description "Pipsgrowth.com EX10015 GoldScalper CCIMomentum — CCI zero-line cross momentum scalper, full 12-layer stack."

#include <Trade\Trade.mqh>

//+------------------------------------------------------------------+
//| Inputs                                                           |
//+------------------------------------------------------------------+
input group "=== Risk Management ==="
input bool   UseMoneyManagement = true;
input double RiskPercent        = 2.0;
input double FixedLotSize       = 0.01;

input group "=== CCI Settings ==="
input int    CCI_Period         = 14;
input int    CCI_OverboughtLevel= 100;
input int    CCI_OversoldLevel  = -100;

input group "=== Trade Settings ==="
input int    StopLossPips       = 15;
input int    TakeProfitPips     = 30;
input int    Slippage           = 3;
input int    MagicNumber        = 22210015;
input string InpTradeComment    = "Psgrowth.com Expert_10015"; // Trade Comment

input group "=== Trailing Stop ==="
input bool   UseTrailingStop    = true;
input int    TrailingStartPips  = 10;
input int    TrailingStepPips   = 5;

input group "=== Filters ==="
input bool   UseSpreadFilter    = true;
input double MaxSpreadPips      = 25.0;

input group "=== Hardening: Risk Management ==="
input double InpDailyLossLimitPct = 3.0;   // Daily loss limit (% of effective capital)
input double InpMaxLot           = 5.0;   // Hard lot cap per trade

input group "=== Capital Allocation Cap ==="
// InpCapEnabled removed — use InpCapAmount=0 to disable
input double InpCapAmount         = 0.0;
input double InpCapFloor          = 50.0;

input group "=== Hardening: GMT Sessions ==="
input int    InpServerGMTOffset    = 0;      // Server GMT offset hours (0=auto-detect)
input int    InpLondonStartHour    = 7;      // London session start (GMT)
input int    InpLondonEndHour      = 16;     // London session end (GMT)
input int    InpNYStartHour        = 12;     // New York session start (GMT)
input int    InpNYEndHour          = 21;     // New York session end (GMT)
input bool   InpAvoidAsia          = true;   // Avoid Asian session
input int    InpAsiaStartHour      = 0;      // Asian session start (GMT)
input int    InpAsiaEndHour        = 7;      // Asian session end (GMT)
input bool   InpNewsFilter         = false;  // Avoid trading near news session opens
input int    InpNewsFilterMinutes  = 15;     // Minutes to avoid around news
input int    InpMaxTradesPerDay    = 50;     // Maximum trades per day
input double InpMinEquityPercent   = 95.0;   // Stop trading if equity < this % of initial balance
input int    InpCooldownMinutes    = 30;     // Cooldown minutes after consec losses

Full source code available on download

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

Tags:ex10015momentum-scalperpipsgrowthfreemt5xauusd

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_EX10015.mq5
File Size20.7 KB
Versionv2.00
PlatformMetaTrader 5
File Type.mq5 Source
StrategyScalping
Risk LevelHigh Risk
Timeframes
M15
Currency Pairs
XAUUSD
Min. Deposit$100