P
PipsGrowth
Trend FollowingOpen Source – Free

Pipsgrowth EX16087 Trend

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

Pipsgrowth.com EX16087 BullishBearish_MeetingLines_CCI - Meeting Lines pattern + CCI confirm, full 12-layer stack.

Overview

A two-bar Japanese-candlestick pattern called Meeting Lines sits at the heart of this EA. The Meeting Lines setup is the classical Western interpretation of an Asian candlestick pair where two consecutive candles close at almost the same level, signalling that the previous directional move has stalled and the market is now turning. EX16087 is built around the bullish and bearish variants of that pattern, gated by a single momentum filter (CCI) and exited on a fixed bar-count deadline.

The EA scans every new bar of the running timeframe (M5 to H1, default M5) and looks for two adjacent completed candles whose closes sit within a tight tolerance of each other. Specifically, CheckPattern() first tests for the bullish variant: bar 2 must be a long black body (its open-to-close range exceeds the 12-bar average body length) and bar 1 must be a long white body of equal magnitude, with the two closes within 0.1 × AvgBody(1) of each other. The bearish mirror is the second test: a long white body on bar 2 followed by a long black body on bar 1, with the two closes again almost identical. The word 'long' here is measured relative to AvgBody(), which averages the absolute open-minus-close difference across the 12 most recent bars, so a candle has to be visibly larger than the recent noise to count as part of the pattern. This is what makes the pattern rare — a pair of large opposing bodies with near-identical closes does not appear every bar, even on XAUUSD.

When the pattern fires, the EA flags a tentative signal but does not open a position until the CCI(37) confirmation passes on the same bar. CheckConfirmation() pulls the most recent completed bar's Commodity Channel Index value using the applied price selected through InpPrice (default close, but configurable from 1=close through 7=weighted). A bullish Meeting Lines needs CCI(1) below −50 to be considered a confirmed buy, while the bearish variant needs CCI(1) above +50 to be confirmed as a sell. Those thresholds filter out pattern occurrences that appear in low-impulse environments and keep entries restricted to bars where momentum has actually been running against the prior trend. A pattern without confirmation simply clears the signal — there is no 'maybe' state carried into the next bar.

Once a pattern is detected and confirmed, PositionOpen() is called on the next tick. The order is sent at the current ask for a buy or current bid for a sell with a fixed 0.10 lot (InpLot). Risk is fully configurable by the trader — there is no automatic risk-percent sizing in this EA, no balance-based scaling, and no margin-utilisation check. Position sizing is whatever the lot input specifies, so a trader upgrading from 0.01 to 1.0 needs to think about contract value themselves.

The protective stop and target are both fixed in points through InpSL (default 200 points, which is 20 pips on a 5-digit broker) and InpTP (also 200 points). Both are inserted into the order ticket at entry, not maintained on a separate schedule. PositionOpen() applies a useful safety check: if the current spread is wider than the configured stop or target, the SL or TP distance is set to the spread itself rather than the requested value. This keeps the EA from sending obviously bad tickets during news spikes or low-liquidity transitions, although the trade-off is that the protection is then reduced to whatever the spread is at the moment of the order.

There is no trailing stop, no break-even function, and no partial-close logic wired into the live trading path. Three retry helpers — TryClose_EX16087, TryClosePartial_EX16087, and TryModify_EX16087 — exist at the bottom of the file with the standard 3-attempt, 100–200 ms sleep pattern for handling requotes, timeouts, and price changes. Only TryClose_EX16087 is invoked, from CloseBySignal() and CloseByTime(). The partial-close and modify helpers are defined but never called from the live OnTick path, so they would only fire if a developer wired them up manually.

A dedicated time-based exit is what separates this EA from a pure price-action reversal bot. After the position is opened, every tick checks how many bars have elapsed since entry. BarsHold() returns the number of completed bars between the position's open time and now using CopyRates on the chart symbol, and once that count reaches InpDuration (default 10 bars) the position is force-closed via CloseByTime(), regardless of whether price is in profit or loss. On M5 this works out to roughly 50 minutes of maximum exposure, on M15 to two and a half hours, and on H1 to ten hours. A second independent close path runs through CheckCloseSignal(): if CCI swings back across ±80 (for example, CCI(1) drops below 80 while CCI(2) was above 80, or crosses back through −80), the EA closes the open position. So a position can exit via four distinct routes — the CCI extreme unwind, the fixed TP, the fixed SL, or simply running out of bars.

Risk is one-sided: there is no portfolio-level drawdown cap, no daily loss limit, no news filter, no session filter, and no equity-flooring function. The closest safety gates are the spread-versus-SL/TP check at entry and the magic-number filter at every close loop, so the EA will only ever manage its own positions on the chart symbol with magic 22216087. The lot input is the only capital-allocation lever; everything else is deterministic from the bar structure and the CCI value.

A practical backtest expectation: the equity curve depends almost entirely on how often the 12-bar average body definition catches a real reversal rather than a coincidental near-close pair. The pattern is rare, so the EA will typically open only a handful of trades per day on M5. On a 1:1 reward-to-risk ratio with a 10-bar time stop, expect roughly half of closed trades to be small winners, with the remainder split between time-stop losses and SL hits. Traders looking to optimise further should treat the SL/TP pair and the time-out as a single tunable, because changing the timeframe quietly changes how long a position is allowed to live.

Strategy Deep Dive

Every new bar, CheckState() runs CheckPattern() to look for the bullish or bearish Meeting Lines two-bar formation, comparing each candle's body against the 12-bar AvgBody() and the two closes against a 10%-of-body tolerance. If a pattern forms, CheckConfirmation() samples the CCI(37) one bar back — a buy needs CCI < −50, a sell needs CCI > +50, while a no-confirm simply cancels the signal. Confirmed patterns trigger PositionOpen(), which submits a market order at the current ask/bid with a fixed 0.1 lot, a 200-point stop, and a 200-point take-profit; if the live spread exceeds either protective distance, that distance is replaced with the spread itself. The order is monitored every tick for three exit conditions: a CCI extreme unwind (crossing ±80), the SL/TP fill, and the 10-bar time stop that CloseByTime() enforces through BarsHold(). There is no trailing, no breakeven, no partial close, no news filter, and no session filter — risk lives entirely in the magic-number filter, the spread check, and the fixed-lot input.

Entry Signal

The EA looks for a two-bar Meeting Lines candlestick pattern — a long black candle immediately followed by a long white candle (or vice versa) whose closes fall within 10% of the 12-bar average body length. Once a pattern fires, the entry is gated by CCI(37) on the most recent closed bar: a long entry needs CCI < −50, a short entry needs CCI > +50. Confirmation runs only at each new bar of the running timeframe, and only the first position in the signal direction is allowed open at a time.

Exit Signal

Exits run through four independent paths: the fixed 200-point Take Profit, the fixed 200-point Stop Loss, the CCI-extreme unwind (closing when CCI crosses back through ±80), and a time-based force-close after InpDuration (default 10) bars elapse since entry. TryClose_EX16087 is the only retry helper wired into the live OnTick path; the partial-close and modify retry helpers are defined but never invoked from runtime code.

Stop Loss

Every order carries a fixed InpSL = 200-point stop (20 pips on a 5-digit broker) sent with the ticket at entry. If the live spread is wider than the configured SL, the code falls back to a spread-sized stop and prints a warning rather than sending a thinner ticket. There is no per-trade trailing or break-even stop, and no portfolio-level drawdown cap.

Take Profit

Take profit is fixed at 200 points (InpTP), giving a 1:1 reward-to-risk ratio against the matching 200-point stop. As with the stop, the code falls back to spread-width if the live spread is wider than the configured TP at the moment of entry. The pattern's own 10-bar time stop can also close a position before the TP is hit.

Best For

Recommended balance starts at $100 with the default 0.10 lot, keeping per-trade exposure modest on a cent account. The pattern needs clean price action, so a low-spread ECN broker on XAUUSD with M5 charts during the London and New York active hours is the cleanest operating environment; quiet Asian sessions tend to produce too few genuine reversals. The CCI(37) period is long enough that the EA is not a scalper, but the 10-bar time stop keeps exposure bounded — swing traders looking for multi-day holds should re-timeframe or skip this EA.

Strategy Logic

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

Family: Trend Magic: 22216087 Version: 2.00

BRIEF: MeetingLines pattern + CCI confirm, time exit 12 layers: REGIME, SIGNAL, ENTRY, CONFIRM, NO-TRADE, CAPITAL CAP, RISK, SIZING, MANAGE, EXIT, SCALING, OnTester

INDICATOR STACK:

  • Standard MT5 indicators

KEY FUNCTIONS:

  • CheckState()
  • PositionOpen()
  • CloseBySignal()
  • CloseByTime()
  • PositionExist()
  • PositionExpiredByTimeExist()
  • BarsHold()
  • Open()
  • Close()
  • Low()
  • High()
  • MidPoint()
  • ...and 9 more

INTERNAL CONSTANTS (3 total):

  • SIGNAL_BUY = 1 // Buy signal
  • SIGNAL_NOT = 0 // no trading signal
  • CLOSE_LONG = 2 // signal to close Long

INPUT PARAMETERS (10 total across 4 groups):

  • [=== Pattern Parameters ===] InpAverBodyPeriod = 12 // period for calculating average candlestick size
  • [=== Pattern Parameters ===] InpPeriodCCI = 37 // CCI period
  • [=== Pattern Parameters ===] InpPrice = 1 // Applied price (1=close,2=open,3=high,4=low,5=median,6=typical,7=weighted) // price type
  • [=== Trade Parameters ===] InpDuration = 10 // position holding time in bars
  • [=== Trade Parameters ===] InpSL = 200 // Stop Loss in points
  • [=== Trade Parameters ===] InpTP = 200 // Take Profit in points
  • [=== Trade Parameters ===] InpSlippage = 10 // slippage in points
  • [=== Money Management ===] InpLot = 0.1 // lot
  • [=== Identity ===] InpMagicNumber = 22216087 // Magic Number
  • [=== Identity ===] InpTradeComment = "Psgrowth.com Expert_16087" // Trade comment
Pseudocode
// Pipsgrowth EX16087 Trend — Execution Flow (from source analysis)
// Family: Trend
// MeetingLines pattern + CCI confirm, time exit 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
InpAverBodyPeriod12period for calculating average candlestick size
InpPeriodCCI37CCI period
InpPrice1Applied price (1=close,2=open,3=high,4=low,5=median,6=typical,7=weighted) // price type
InpDuration10position holding time in bars
InpSL200Stop Loss in points
InpTP200Take Profit in points
InpSlippage10slippage in points
InpLot0.1lot
InpMagicNumber22216087Magic Number
InpTradeComment"Psgrowth.com Expert_16087"Trade comment
Source Code (.mq5)Open Source
Pipsgrowth_com_EX16087.mq5
#property copyright "Pipsgrowth.com"
#property link      "https://pipsgrowth.com"
#property version   "2.00"
#property strict
#property description "Pipsgrowth.com EX16087 BullishBearish_MeetingLines_CCI - Meeting Lines pattern + CCI confirm, full 12-layer stack."
#include <Trade\Trade.mqh>
#include <Trade\SymbolInfo.mqh>

#define SIGNAL_BUY    1             // Buy signal
#define SIGNAL_NOT    0             // no trading signal
#define SIGNAL_SELL  -1             // Sell signal

#define CLOSE_LONG    2             // signal to close Long
#define CLOSE_SHORT  -2             // signal to close Short

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_InpPrice = PRICE_CLOSE;
input group "=== Pattern Parameters ==="
input int InpAverBodyPeriod=12;     // period for calculating average candlestick size
input int InpPeriodCCI     =37;     // CCI period
input int InpPrice = 1; // Applied price (1=close,2=open,3=high,4=low,5=median,6=typical,7=weighted) // price type

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_InpPrice = PRICE_CLOSE;
input group "=== Trade Parameters ==="
input uint InpDuration=10;          // position holding time in bars
input uint InpSL      =200;         // Stop Loss in points
input uint InpTP      =200;         // Take Profit in points
input uint InpSlippage=10;          // slippage in points
ENUM_APPLIED_PRICE MapAppliedPriceInt(int ap)
{
   switch(ap)
   {
      case 1: return PRICE_CLOSE;

Full source code available on download

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

Tags:ex16087trendpipsgrowthfreemt5xauusd

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