P
PipsGrowth
Trend FollowingOpen Source – Free

Pipsgrowth EX18064 TrendFollow

MT5 Expert Advisor (Open Source) · XAUUSD · H1

Pipsgrowth.com EX18064 Ichimoku_strategy — Adaptive Ichimoku trend-follow EA, full 12-layer stack.

Overview

Pipsgrowth EX18064 is a fully-discretionary Ichimoku Kinko Hyo system that waits until all four canonical Ichimoku conditions align on a closed bar before it fires. The four conditions, in the order they are evaluated inside SignalIchimoku(), are: (1) Tenkan-sen (period 9) is on the correct side of Kijun-sen (period 26) — Tenkan above for longs, below for shorts; (2) the most recent closed price sits above the upper kumo boundary (Senkou Span A and Span B maximum) for longs, or below the lower boundary for shorts, with a one-bar tolerance so that a bar that just exited the cloud still counts; (3) the Chikou Span — the close from 26 bars back, which is the displaced reading MT5 produces by default — is itself clear of the kumo at the same historical point, which filters out signals where a recent pullback would still be tangled with the cloud; (4) the future cloud 26 bars ahead, computed from Senkou A and Senkou B at index 1+InpKijun, is green for longs or red for shorts. All four must agree; partial consensus is recorded as a confidence score (0–100) but does not open a trade. This is the strictest application of the Ichimoku system in the TrendFollow family — there is no averaging, voting, or scoring fallback.

The signal is gated by a 7-state regime classifier in ClassifyRegime(). It reads ADX(14) main, ATR(14) as a percentile rank over the last 200 bars, and Bollinger Band width(20, 2.0). The thresholds are tunable through #define constants: ADX at or above 35 with an ATR percentile at or above 0.75 returns REG_EXPAND, ADX at or above the InpAdxThreshold input (default 22) returns REG_STRONG_TREND, ADX at or above 20 returns REG_WEAK_TREND, ATR percentile at or below 0.30 returns REG_COMPRESS, and ADX below 18 returns REG_CHOPPY. Of these seven states, only four permit entries: STRONG_TREND, WEAK_TREND, EXPAND, and BREAKOUT. A flip into CHOPPY during an open position is treated as a full-book close signal by ManageOpen() — the EA does not wait for the stop to be hit, it exits at market.

Two HTF filters run in ConfirmEntries(). The first checks that the close on the higher timeframe (default H4InpHtfTimeframe=9 maps to PERIOD_H4 via the same MapTimeframeInt switch) is on the correct side of an EMA(50) computed on that HTF, with a small ±0.3% slack to forgive near-edge price. The second reads the Tenkan/Kijun cross on the HTF Ichimoku and requires the same direction. A failure on either filter is logged and the trade is rejected for that bar. The third guard, IsHtfOpposing(), runs separately and blocks entries when the HTF EMA disagrees by more than 0.3%. Spread is filtered by IsSpreadBad() against both an absolute cap (InpMaxSpreadPoints, default 35 points) and a rolling 50-bar average — a current spread more than 2× the recent average rejects the entry even if it is under the absolute cap.

Risk is sized from effective capital, where effective capital is the live account equity minus realized losses today, optionally capped at InpCapitalCapAmount. Each trade risks InpRiskPercent (0.5%) of that effective capital. The stop distance is InpAtrMultSL × ATR(14), default 2.0 × ATR, which lands a typical XAUUSD H1 SL in the 1.52.5 USD range. TP1 sits at 1R and TP2 at 2R; the order is sent with TP2 as the broker-side target. In ManageOpen(), when the trade reaches 1R the position is partially closed for InpPartialPctR (default 50%) via TryClosePartial_EX18064 — this is a one-shot partial that does not repeat. At the same 1R threshold the stop is moved to break-even with a 10-point offset (BE_OFFSET_POINTS) — long stops move to entry + 10 points, short stops move to entry − 10 points. From that point on, a forward-only ATR trail at 2.5 × ATR(14) (InpTrailAtrMult) ratchets the stop every tick; the ratchet only moves in the favorable direction. All three retry helpers — TryClose_EX18064, TryClosePartial_EX18064, TryModify_EX18064 — use a 3-attempt loop with 200ms backoff on requote/timeout/price-changed conditions.

Three extra exits are layered on top of the trailing logic. First, a max-hold time exit at MAX_HOLD_BARS=500 (the time exit uses Bars() between the open time and the current bar) closes the trade without waiting for a stop or target hit. Second, an opposite-signal exit re-runs SignalIchimoku() on every tick and, if the consensus flips, closes the trade at market. Third, the regime-change exit described above. The loss-cooldown is implemented through g_lastLossBarTime plus the COOLDOWN_BARS=3 constant — after a losing close, the next three bars on the working timeframe are blocked from entry. Daily loss is capped at 3% of effective capital and weekly loss at 6%; both are computed from closed deal history (RealizedSince(dayStart) and RealizedSince(weekStart)). InpMaxConcurrent defaults to 2 and the symbol-level cap MAX_SYMBOL_EXPOSURE also defaults to 2, so the EA will not stack more than two XAUUSD positions at a time. The OnTester() fitness function returns (net * pf) / (1 + dd), with a 30-trade floor — backtests under 30 trades or with non-positive drawdown score 0, so the optimizer will not pick degenerate parameter combinations.

In practical terms this EA is built for a trader who already trusts Ichimoku as a complete system and wants the discipline of never breaking its rules. The 2R target is realistic for a trend continuation on H1, the 1R partial turns the win rate into something measurable, and the regime filter keeps the EA out of the sideways conditions where Ichimoku whipsaws badly. The 500-bar max-hold is generous (≈3 weeks on H1) but it acts as a circuit breaker for trades that simply never develop. Like all of the TrendFollow EAs in the Pipsgrowth library, the file defaults to InpDryRun=true so a new installation does not place real orders until you have reviewed the inputs and the EA's behavior in the Strategy Tester. The order comment is hard-coded to "Psgrowth.com Expert_18064" and the magic number is 22218064 — both are required for the EA to recognize its own positions during manage/exit passes.

Strategy Deep Dive

On every tick, OnTick() refreshes effective capital from live account equity minus realized losses today, optionally capped at InpCapitalCapAmount, then runs ManageOpen() against all positions owned by magic 22218064. The strategy layer reads from six indicator handles — iIchimoku on the working timeframe, iIchimoku on the higher timeframe, iADX(14), iATR(14), iBands(20, 0, 2.0), and iMA(EMA, 50) on the HTF — and on a fresh working-TF bar runs ClassifyRegime() to assign one of seven states, then SignalIchimoku() to test the four-condition consensus on the closed bar, then IsSpreadBad() / IsHtfOpposing() / IsBrokerBlocked() for the no-trade gates, then ConfirmEntries() for the HTF EMA + HTF Tenkan/Kijun cross checks, then BuildAndSend() which sizes the lot from effective capital and SL distance and submits a single order with TP2 as the broker-side target. The Ichimoku signal is the strictest of any EA in the family — there is no vote averaging, no fallback scoring, and no partial consensus trade.

Entry Signal

Entries fire only when a closed bar satisfies all four Ichimoku conditions: Tenkan-sen(9) on the correct side of Kijun-sen(26), price above the upper kumo boundary (or below the lower boundary for shorts) with a one-bar exit tolerance, Chikou Span clear of the kumo at the corresponding 26-bars-back point, and the future cloud 26 bars ahead green for longs or red for shorts. The bar must also fall in one of the four tradeable regime states (STRONG_TREND, WEAK_TREND, EXPAND, or BREAKOUT) per ClassifyRegime(), pass the HTF EMA(50) agreement check, pass the HTF Tenkan/Kijun direction check, and have a spread under InpMaxSpreadPoints (default 35 points) and under 2× the 50-bar rolling average.

Exit Signal

Exits are layered. At 1R the position takes a one-shot 50% partial close via TryClosePartial_EX18064; at the same 1R level the stop is moved to entry + 10 points (long) or entry − 10 points (short). After that a forward-only ATR trail at 2.5 × ATR(14) ratchets the stop in the favorable direction. An opposite-signal flip from SignalIchimoku() forces a market close, a regime change into CHOPPY forces a full book close, and a 500-bar max-hold time exit closes the trade regardless of price. The final TP2 at 2R is also held as a broker-side target.

Stop Loss

Initial stop is InpAtrMultSL × ATR(14) — 2.0 × ATR(14) by default, which lands a typical XAUUSD H1 stop around $1.5–$2.5. The stop is enforced to respect the broker's minimum stops-level via RespectsStops(). At 1R the stop moves to break-even plus a 10-point offset (entry + 10 points for longs, entry − 10 points for shorts), then a forward-only 2.5 × ATR(14) trail ratchets it in the favorable direction. A regime change to CHOPPY closes the position at market rather than waiting for the stop.

Take Profit

TP1 sits at 1R and TP2 sits at 2R; the order is submitted with TP2 as the broker-side target. The MinRR input defaults to 1.5 and the order is rejected before send if the actual R-multiple of the planned trade falls below that floor. TP1 is realized as a one-shot 50% partial via TryClosePartial_EX18064 when the position reaches 1R; the remaining half then runs the trailing-stop logic with the 2R broker target as a hard ceiling.

Best For

Designed for XAUUSD on H1 with a $100 minimum deposit (the EA will block entries when effective capital falls below the $50 InpCapitalCapFloor). The Ichimoku 4-condition consensus is slow to flip, so this EA is best for swing-style positioning on metals and major FX pairs where the broker allows stops-level under 30 points and the spread averages below 30 points — a low-spread ECN account is the right fit. The London and New York sessions produce the cleanest H1 Ichimoku signals; during the Asian session the EA is likely to remain flat because kumo shifts on H1 are rare overnight. Use this EA when you want a patient, full-Ichimoku system with built-in regime filtering and a 1:2 reward profile.

Strategy Logic

Pipsgrowth EX18064 TrendFollow — Strategy Logic Analysis (from .mq5 source)

Family: TrendFollow Magic: 22218064 Version: 2.00

BRIEF: Classic Ichimoku 4-condition consensus (TK side + kumo side + Chikou clear + future-kumo agreement) on closed bar; gated by ADX/ATR-pct/BB-width regime, HTF agreement, capital-allocation-cap risk model, ATR-based SL, partial TP, ATR trail, regime exit. 12 layers: REGIME, SIGNAL, ENTRY, CONFIRM, NO-TRADE, CAPITAL CAP, RISK, SIZING, MANAGE, EXIT, SCALING, OnTester

INDICATOR STACK:

  • Standard MT5 indicators

KEY FUNCTIONS:

  • RegimeAllowsEntry()
  • RegimeName()
  • PercentileRank()
  • SignalIchimoku()
  • ConfirmEntries()
  • IsSpreadBad()
  • IsBrokerBlocked()
  • IsHtfOpposing()
  • CalcLots()
  • BuildAndSend()
  • ManageOpen()
  • RespectsStops()
  • ...and 11 more

INTERNAL CONSTANTS (20 total):

  • SENKOU_PERIOD = 52 // Senkou Span B (standard)
  • BB_PERIOD = 20 // Bollinger width period
  • BB_DEV = 2.0 // Bollinger deviation
  • ATR_PCTILE_LOOKBACK = 200 // ATR percentile lookback bars
  • ATR_PCTILE_STRONG = 0.75 // ATR percentile "expanding" threshold
  • ATR_PCTILE_COMPRESS = 0.30 // ATR percentile "compressing" threshold
  • ADX_EXPAND_THRESH = 35.0 // ADX above = expansion regime
  • ADX_CHOP_THRESH = 18.0 // ADX below = choppy/range
  • SPREAD_AVG_BARS = 50 // rolling spread average window
  • SLIPPAGE_POINTS = 20 // CTrade deviation in points
  • BE_TRIGGER_R = 1.0 // break-even trigger at 1R
  • BE_OFFSET_POINTS = 10 // break-even offset points
  • COOLDOWN_BARS = 3 // bars to wait after a loss
  • MAX_HOLD_BARS = 500 // max bars in trade (time exit)
  • MAX_SYMBOL_EXPOSURE = 2 // max simultaneous positions per symbol
  • ...and 5 more

INPUT PARAMETERS (21 total across 6 groups):

  • [=== Identity ===] InpMagic = 22218064 // Magic number
  • [=== Identity ===] InpTradeComment = "Psgrowth.com Expert_18064" // Trade comment
  • [=== Identity ===] InpTimeframe = 8 // Timeframe (1=M1,2=M5,3=M15,4=M30,5=H1,6=H4,7=D1) // Working timeframe
  • [=== Identity ===] InpHtfTimeframe = 9 // Timeframe (1=M1,2=M5,3=M15,4=M30,5=H1,6=H4,7=D1) // HTF trend-agreement timeframe
  • [=== Risk & Sizing ===] InpRiskPercent = 0.5 // Risk per trade (% of effective capital)
  • [=== Risk & Sizing ===] InpCapitalCapAmount = 0.0 // Capital cap amount (real-money equity $)
  • [=== Risk & Sizing ===] InpCapitalCapFloor = 50.0 // Capital floor (block entries below)
  • [=== Risk & Sizing ===] InpDailyLossLimitPercent = 3.0 // Daily loss limit (% effective capital)
  • [=== Risk & Sizing ===] InpWeeklyLossLimitPercent = 6.0 // Weekly loss limit (% effective capital)
  • [=== Signal (Ichimoku) ===] InpTenkan = 9 // Tenkan-sen period
  • [=== Signal (Ichimoku) ===] InpKijun = 26 // Kijun-sen period
  • [=== Regime & Confirm ===] InpAdxThreshold = 22.0 // Min ADX main for trend entry
  • [=== Regime & Confirm ===] InpMinRR = 1.5 // Min reward:risk ratio
  • [=== Regime & Confirm ===] InpMaxSpreadPoints = 35 // Max spread (points)
  • [=== Exit / Manage ===] InpAtrPeriod = 14 // ATR period (SL & trail)
  • [=== Exit / Manage ===] InpAtrMultSL = 2.0 // ATR multiple for initial SL (Kijun floor)
  • [=== Exit / Manage ===] InpTrailAtrMult = 2.5 // ATR trailing multiple
  • [=== Exit / Manage ===] InpPartialPctR = 50 // Partial close % at TP1 (1R)
  • [=== Operational ===] InpMaxConcurrent = 2 // Max concurrent positions
  • [=== Operational ===] InpDryRun = true // Dry-run mode (no real sends)
  • [=== Operational ===] InpKillSwitch = false // Global kill switch
Pseudocode
// Pipsgrowth EX18064 TrendFollow — Execution Flow (from source analysis)
// Family: TrendFollow
// Classic Ichimoku 4-condition consensus (TK side + kumo side + Chikou clear + future-kumo agreement) on closed bar; gated by ADX/ATR-pct/BB-width regime, HTF agreement, capital-allocation-cap risk model, ATR-based SL, partial TP, ATR trail, regime 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:
H1

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
InpMagic22218064Magic number
InpTradeComment"Psgrowth.com Expert_18064"Trade comment
InpTimeframe8Timeframe (1=M1,2=M5,3=M15,4=M30,5=H1,6=H4,7=D1) // Working timeframe
InpHtfTimeframe9Timeframe (1=M1,2=M5,3=M15,4=M30,5=H1,6=H4,7=D1) // HTF trend-agreement timeframe
InpRiskPercent0.5Risk per trade (% of effective capital)
InpCapitalCapAmount0.0Capital cap amount (real-money equity $)
InpCapitalCapFloor50.0Capital floor (block entries below)
InpDailyLossLimitPercent3.0Daily loss limit (% effective capital)
InpWeeklyLossLimitPercent6.0Weekly loss limit (% effective capital)
InpTenkan9Tenkan-sen period
InpKijun26Kijun-sen period
InpAdxThreshold22.0Min ADX main for trend entry
InpMinRR1.5Min reward:risk ratio
InpMaxSpreadPoints35Max spread (points)
InpAtrPeriod14ATR period (SL & trail)
InpAtrMultSL2.0ATR multiple for initial SL (Kijun floor)
InpTrailAtrMult2.5ATR trailing multiple
InpPartialPctR50Partial close % at TP1 (1R)
InpMaxConcurrent2Max concurrent positions
InpDryRuntrueDry-run mode (no real sends)
InpKillSwitchfalseGlobal kill switch
Source Code (.mq5)Open Source
Pipsgrowth_com_EX18064.mq5
#property copyright "Pipsgrowth.com"
#property link      "https://pipsgrowth.com"
#property version   "2.00"
#property strict
#property description "Pipsgrowth.com EX18064 Ichimoku_strategy — Adaptive Ichimoku trend-follow EA, full 12-layer stack."

#include <Trade\Trade.mqh>
#include <Trade\PositionInfo.mqh>
#include <Trade\SymbolInfo.mqh>
#include <Trade\AccountInfo.mqh>
#include <Trade\OrderInfo.mqh>
#include <Trade\DealInfo.mqh>

// ============================ #define CONSTANTS (non-input tunables) ============================
#define SENKOU_PERIOD      52          // Senkou Span B (standard)
#define BB_PERIOD          20          // Bollinger width period
#define BB_DEV             2.0         // Bollinger deviation
#define ATR_PCTILE_LOOKBACK 200        // ATR percentile lookback bars
#define ATR_PCTILE_STRONG   0.75       // ATR percentile "expanding" threshold
#define ATR_PCTILE_COMPRESS 0.30       // ATR percentile "compressing" threshold
#define ADX_EXPAND_THRESH   35.0       // ADX above = expansion regime
#define ADX_CHOP_THRESH     18.0       // ADX below = choppy/range
#define SPREAD_AVG_BARS     50         // rolling spread average window
#define SLIPPAGE_POINTS     20         // CTrade deviation in points
#define BE_TRIGGER_R        1.0        // break-even trigger at 1R
#define BE_OFFSET_POINTS    10         // break-even offset points
#define COOLDOWN_BARS       3          // bars to wait after a loss
#define MAX_HOLD_BARS       500        // max bars in trade (time exit)
#define MAX_SYMBOL_EXPOSURE 2          // max simultaneous positions per symbol
#define NEWS_WINDOW_MIN     0          // manual news block minutes (0 = off)
#define PYRAMID_ENABLED     false      // scaling default OFF
#define PYRAMID_MAX_LEVELS  3          // pyramid cap
#define PYRAMID_ATR_SPACING 1.5        // pyramid spacing in ATR mult
#define WEEKLY_LOSS_HARD_HRS 1440      // weekly cooldown minutes

CTrade        trade;
CPositionInfo posInfo;
CSymbolInfo   symInfo;

// ============================ INPUTS (22 total) ============================
ENUM_TIMEFRAMES MapTimeframeInt(int tf)
{
   switch(tf)
   {
      case 1: return PERIOD_M1;
      case 2: return PERIOD_M5;
      case 3: return PERIOD_M15;
      case 4: return PERIOD_M30;
      case 5: return PERIOD_H1;
      case 6: return PERIOD_H4;
      case 7: return PERIOD_D1;
      default: return PERIOD_H1;
   }
}

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:ex18064trendfollowpipsgrowthfreemt5xauusd

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