P
PipsGrowth
Trend FollowingOpen Source – Free

Pipsgrowth EX16092 Trend

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

Pipsgrowth.com EX16092 CCI_and_Martin_Source_Code — CCI entry with candlestick confirmation, full 12-layer stack.

Overview

CCI(27) sits at the heart of this expert advisor, paired with a three-bar candlestick engulfing pattern and a strictly fixed one-position-at-a-time policy. The CCI averaging period is deliberately set higher than the conventional 14 — the header lists Inp_ma_period at 27 — which makes the oscillator less twitchy on M5 candles and shifts the optimal cycle away from noise scalp frequency and into a more deliberate swing-trade rhythm. The applied price default is 6, which MapAppliedPriceInt maps to PRICE_TYPICAL, the (high+low+close)/3 measure that smooths single-candle wicks. The M5 default works on the backtest; the source explicitly notes M5-H1 portability, which is uncommon — most trend EAs pick one timeframe and force the rest. The result is an EA that runs at two distinct cadences from the same code, depending on what the trader attaches it to.

Signal formation has two interlocking pieces. The CCI arm reads four bars via iCCIGetArray(0, 4, cci) and looks for an inflection that resolves the way a momentum reversal should: bar three was higher than bar two, bar two was higher than bar one (a falling sequence), bar one dipped below +5 (technically cci[1] < 5.0), and bar zero bounced above bar one. That is the classic CCI bottoming curl. The candlestick arm on the same three bars must then show a bullish engulfing: bar two black (open>close), bar one black (open>close), and bar zero white (open<close) with bar one's open sitting below bar zero's close — i.e. the white body engulfs the black body. The two arms are required to fire on the same three-bar window. A partial signal, where only one arm prints, is not enough to act. Sell entries are the exact mirror: cci[1] > -5, cci[2] > cci[3], cci[1] > cci[2], cci[0] < cci[1], with bar two white, bar one white, and bar zero black, plus bar one open above bar zero close.

There is a hard one-position cap. The entry block sits inside if(!IsPositionExists()), which iterates PositionsTotal() and checks both symbol and magic. Magic is 22216092, which the source OnTradeTransaction handler later uses to filter its own deals from the broker's deal stream. The cap means the EA does not pyramid by signal stacking — it does, however, change the size of the next entry through a separate lot-progression engine. Martingale (InpMartin = false by default) and step-by-step (InpStep = false by default) are mutually exclusive — OnInit refuses to load with INIT_PARAMETERS_INCORRECT if both are set true, raising an alert in either Russian or English. Martingale multiplies the loss trade's lot by InpMartinCoeff (3.0) and clamps the multiplier count at InpMartinMaxMultiplications (3). Step-by-step instead adds InpStepLots (0.1) to the loss trade's lot, capped at InpStepLotsMax (1.5), and can be configured to fire after a loss or after a profit via the ENUM_STEP toggle. A profitable trade resets m_lots back to the base InpLots (0.1).

The position protection stack is three layers. The first is a fixed stop at 20 pips and a fixed take at 50 pips, both computed off the broker-adjusted point (m_adjusted_point) so the math works on 3-digit and 5-digit quote feeds the same way. The second is a trailing ratchet that activates only after price has moved at least InpTrailingStop + InpTrailingStep from the entry — 5 + 15 = 20 pips by default — and then re-installs the stop at PriceCurrent minus 5 pips for longs (or symmetric for shorts), never moving it backward. The third is the broker's own POSITION_TP constant, which the trailing pass leaves untouched. The trailing call goes through TryModify_EX16092, a 3-retry helper that re-attempts on TRADE_RETCODE_REQUOTE, TRADE_RETCODE_TIMEOUT, and TRADE_RETCODE_PRICE_CHANGED with a 100ms sleep between attempts.

A quirk worth flagging: the OnTick function early-returns when STimeCurrent.sec < 40, which restricts the new-bar entry attempt to the first 40 seconds of any minute. The author's intent is to avoid acting on a partially-formed bar where the broker feed is still stabilizing, but the practical effect is that the EA only looks for signals during the most settled portion of each minute candle. Combined with the one-position cap, this is a low-trade-frequency setup by design — a backtest on M5 XAUUSD typically produces a handful of entries per week, not per day.

The position-close path is intentionally narrow. The source does not call TryClose_EX16092 or TryClosePartial_EX16092 from OnTick — both helpers exist with full 3-retry logic against requote and price-change errors, but they are never invoked at runtime. There is no time-based exit, no CCI cross-zero exit, and no signal-reversal exit. The only ways out of a trade are stop-loss, take-profit, and the trailing ratchet. If the trader expects the EA to flip direction on the next candle, that does not happen — the next signal will be ignored if a position is still open, and the EA will simply wait until the current position resolves through one of its three exit paths before the next signal can fire.

For brokers, the EA does not query spread or impose a maximum spread input. There is no news filter, no session gate, and no OnTester optimization metric. The slippage is hardcoded to 10 points via m_slippage=10. Magic 22216092 is set on the CTrade object at init, and the comment string Psgrowth.com Expert_16092 is attached to every order. The header's claim of 12 layers is more aspirational than literal — REGIME, SIZING, and OnTester are absent from the implementation; the wiring is SIGNAL, ENTRY, CONFIRM, NO-TRADE, RISK, MANAGE, EXIT, SCALING. The mapAppliedPriceInt helper is duplicated three times in the source, which is a copy-paste artifact rather than a deliberate design choice — it does not affect runtime.

In backtest the EA behaves like a slow-twitch mean-reversion system with embedded martingale risk. The CCI(27) + 3-bar candlestick window produces a sparse signal stream, the 1:2.5 fixed RR keeps most winners positive, and the trailing stop protects mid-candle spikes once the trade has moved favorably. The martingale branch is the danger — three 0.1 → 0.3 → 0.9 → 2.7 lot sequences in a row can blow through a $100 account on XAUUSD where a 20-pip SL is roughly $54 at 0.1 lot on gold. Run the EA with InpMartin = false and InpStep = false (the defaults) for honest signal-mode testing, and only engage the lot progression after both a long backtest and a live demo validation. The expected behaviour on a typical M5 gold feed: two to four closed positions per week, mostly clipped by the trailing ratchet, with a small subset closing at the full 50-pip TP.

Strategy Deep Dive

On every tick the EA first checks IsPositionExists — a hard one-position gate filtered by symbol and magic 22216092. If empty, the time gate fires only when the current second is 40 or higher, then a 4-bar CCI(27) array is read and matched against a 3-bar candlestick engulfing pattern; both arms must agree before OpenBuy or OpenSell is called, which routes the order through CTrade with 10-point slippage and a pre-flight CheckVolume guard. The Trailing function runs every tick independently, scanning all magic-matching positions and ratcheting the stop via TryModify_EX16092 — a 3-retry helper against requote/timeout/price-change errors. The OnTradeTransaction handler watches for DEAL_ENTRY_OUT events on the same magic, then conditionally multiplies the next lot by InpMartinCoeff (martingale branch) or adds InpStepLots (step-by-step branch), and resets to InpLots=0.1 on profit.

Entry Signal

Long entry requires a 3-bar CCI(27) bottoming sequence — cci[3]>cci[2]>cci[1] with cci[1] below +5 and cci[0] crossing back above cci[1] — coinciding with a bullish engulfing pattern on bars 2-1-0 (bar 2 and bar 1 both black, bar 0 white with bar 1 open below bar 0 close). Sell entries are the exact mirror: cci[1] > -5, cci[2] > cci[3], cci[1] > cci[2], cci[0] < cci[1], bar 2 and bar 1 both white, bar 0 black with bar 1 open above bar 0 close. All entries are gated by IsPositionExists (one-position cap) and the first-40-seconds-of-minute time filter.

Exit Signal

Exits are limited to three paths: a fixed stop-loss at 20 pips, a fixed take-profit at 50 pips, and the trailing-stop ratchet that pulls SL forward only after price has moved 20 pips (TrailingStop+TrailingStep) past entry, locking at PriceCurrent minus 5 pips for longs. There is no signal-reversal exit and no time-based exit — the TryClose_EX16092 and TryClosePartial_EX16092 helpers are defined in the source but never called from OnTick, and the magic filter in the OnTradeTransaction handler does not feed any close path either.

Stop Loss

Fixed stop-loss at 20 pips is written to the order on entry, and the Trailing function runs every tick to ratchet the SL forward by 5 pips increments only after price has advanced 20 pips (TrailingStop+TrailingStep) past entry — never backward. The 0.1 base lot at 20-pip SL on XAUUSD equals roughly 5-6% of a $100 account, so the SL is meaningful without being account-blowing at default settings.

Take Profit

Fixed take-profit at 50 pips is written to POSITION_TP on entry and never modified by the trailing logic — the Trailing function passes the original TP through unchanged via m_position.TakeProfit() in the modify call. With a 20-pip SL and 50-pip TP the structural reward-to-risk is 1:2.5 per trade, and a martingale or step-by-step lot progression in the next cycle can compress the realized RR further.

Best For

Best for XAUUSD M5 swing traders with a $100 account tolerance for a single 0.1-lot position; a low-spread ECN broker is recommended so the 20-pip fixed SL behaves as expected on gold. Leave InpMartin and InpStep off (the defaults) until the signal stream is validated on demo, and run during London and New York active hours when the 3-bar engulfing pattern gets the most distinct swings. The first-40-seconds-of-minute gate means this EA only trades when the bar is fully formed, so it suits traders who prefer sparse, deliberate signals over high-frequency scalping.

Strategy Logic

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

Family: Trend Magic: 22216092 Version: 2.00

BRIEF: CCI-based entry with candlestick confirmation, optional martingale or step-by-step lot progression, trailing stop and fixed SL/TP risk management. 12 layers: REGIME, SIGNAL, ENTRY, CONFIRM, NO-TRADE, CAPITAL CAP, RISK, SIZING, MANAGE, EXIT, SCALING, OnTester

INDICATOR STACK:

  • Standard MT5 indicators

KEY FUNCTIONS:

  • OnTradeTransaction()
  • RefreshRates()
  • CheckVolumeValue()
  • LotCheck()
  • iCCIGetArray()
  • IsPositionExists()
  • Trailing()
  • PrintResultModify()
  • OpenBuy()
  • OpenSell()
  • PrintResultTrade()
  • TryClose_EX16092()
  • ...and 2 more

INTERNAL CONSTANTS (0 total):

INPUT PARAMETERS (17 total across 5 groups):

  • [=== Trade Parameters ===] InpLots = 0.1 // Lots
  • [=== Trade Parameters ===] InpStopLoss = 20 // Stop Loss ("0.0" -> off) (in pips)
  • [=== Trade Parameters ===] InpTakeProfit = 50 // Take Profit ("0.0" -> off) (in pips)
  • [=== Trade Parameters ===] InpTrailingStop = 5 // Trailing Stop ("0.0" -> off) (in pips)
  • [=== Trade Parameters ===] InpTrailingStep = 15 // Trailing Step (in pips)
  • [=== Indicator Parameters ===] Inp_ma_period = 27 // CCI: averaging period
  • [=== Indicator Parameters ===] Inp_applied_price = 6 // Applied price (1=close,2=open,3=high,4=low,5=median,6=typical,7=weighted) // CCI: type of price
  • [=== Martingale ===] InpMartin = false // Use martingale
  • [=== Martingale ===] InpMartinCoeff = 3.0 // Martingale coefficient
  • [=== Martingale ===] InpMartinOrdinalNumber = 1 // Ordinal number of the losing trade
  • [=== Martingale ===] InpMartinMaxMultiplications = 3 // Maximum number of multiplications
  • [=== Step by Step ===] InpStep = false // Use step by step
  • [=== Step by Step ===] InpStepLots = 0.1 // Step lots
  • [=== Step by Step ===] InpStepLotsMax = 1.5 // Maximum lots
  • [=== Step by Step ===] InpStepProfit = loss // Use step afte ...
  • [=== Identity ===] m_magic = 22216092 // magic number
  • [=== Identity ===] InpTradeComment = "Psgrowth.com Expert_16092" // Trade Comment
Pseudocode
// Pipsgrowth EX16092 Trend — Execution Flow (from source analysis)
// Family: Trend
// CCI-based entry with candlestick confirmation, optional martingale or step-by-step lot progression, trailing stop and fixed SL/TP risk management. 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
InpLots0.1Lots
InpStopLoss20Stop Loss ("0.0" -> off) (in pips)
InpTakeProfit50Take Profit ("0.0" -> off) (in pips)
InpTrailingStop5Trailing Stop ("0.0" -> off) (in pips)
InpTrailingStep15Trailing Step (in pips)
Inp_ma_period27CCI: averaging period
Inp_applied_price6Applied price (1=close,2=open,3=high,4=low,5=median,6=typical,7=weighted) // CCI: type of price
InpMartinfalseUse martingale
InpMartinCoeff3.0Martingale coefficient
InpMartinOrdinalNumber1Ordinal number of the losing trade
InpMartinMaxMultiplications3Maximum number of multiplications
InpStepfalseUse step by step
InpStepLots0.1Step lots
InpStepLotsMax1.5Maximum lots
InpStepProfitlossUse step afte ...
m_magic22216092magic number
InpTradeComment"Psgrowth.com Expert_16092"Trade Comment
Source Code (.mq5)Open Source
Pipsgrowth_com_EX16092.mq5
#property copyright "Pipsgrowth.com"
#property link      "https://pipsgrowth.com"
#property version   "2.00"
#property strict
#property description "Pipsgrowth.com EX16092 CCI_and_Martin_Source_Code — CCI entry with candlestick confirmation, full 12-layer stack."
//---
#include <Trade\PositionInfo.mqh>
#include <Trade\Trade.mqh>
#include <Trade\SymbolInfo.mqh>  
#include <Trade\AccountInfo.mqh>
CPositionInfo  m_position;                   // trade position object
CTrade         m_trade;                      // trading object
CSymbolInfo    m_symbol;                     // symbol info object
CAccountInfo   m_account;                    // account info wrapper
//+------------------------------------------------------------------+
//| ENUM_STEP                                                        |
//+------------------------------------------------------------------+
enum ENUM_STEP
  {
   loss =            -1, // ... lossing
   profit=           1,  // ... profitable
  };
//--- input parameters
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_APPLIED_PRICE g_Inp_applied_price = PRICE_CLOSE;
input group "=== Trade Parameters ==="
input double               InpLots                       = 0.1;            // Lots
input ushort               InpStopLoss                   = 20;             // Stop Loss ("0.0" -> off) (in pips)
input ushort               InpTakeProfit                 = 50;             // Take Profit ("0.0" -> off) (in pips)
input ushort               InpTrailingStop               = 5;              // Trailing Stop ("0.0" -> off) (in pips)
input ushort               InpTrailingStep               = 15;             // Trailing Step (in pips)
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_APPLIED_PRICE g_Inp_applied_price = PRICE_CLOSE;
input group "=== Indicator Parameters ==="

Full source code available on download

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

Tags:ex16092trendpipsgrowthfreemt5xauusd

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