Pipsgrowth EX07014 MA
MT5 Expert Advisor (Open Source) · XAUUSD · M5, H1
Pipsgrowth.com EX07014 Moving_Average — classic MA crossover with risk-based lot sizing, full 12-layer stack.
Overview
Pipsgrowth EX07014 sits at the most minimal end of the MA-cross family. The whole indicator stack is one line: a single Simple Moving Average built from the close, period 12, shifted six bars into the past. No RSI, no ADX, no ATR, no Bollinger band, no HTF bias, no multi-MA ribbon. The author leaned in the opposite direction of EX07011's eight modules and EX07001's seven-state regime classifier — they gave the trader a textbook mean-reversion cross and asked the price action to do the work.
The entry rule lives in CheckForOpen and is intentionally narrow. Each new bar, on its very first tick (rt[1].tick_volume must be 1 or smaller — anything else means a later tick of the previous bar, and the call returns immediately), the EA pulls the MA value and looks at the current candle's open-to-close relationship to that line. If the bar opened above the MA and closed below it, the EA sends a market SELL. If the bar opened below the MA and closed above it, the EA sends a market BUY. There is no candle pattern, no wick filter, no volume confirmation, no spread cap, and no minimum body size. The cross itself is the signal.
The shift of six bars is the design choice that gives the system its character. iMA(_Symbol,_Period,MovingPeriod=12, MovingShift=6, MODE_SMA, PRICE_CLOSE) returns a value that was computed six candles ago, not the live MA. That deliberate lag means the EA is not chasing the average — it is reacting to a stale reference. On a five-minute chart the line is effectively smoothed across an hour of price action, which filters a lot of the noise that would otherwise whip a faster cross. On H1, six bars is six hours; the MA becomes essentially a daily/weekly-range anchor. The trader who picks M5 gets a different rhythm than the trader who picks H1, and both are valid.
PositionOpen is called with both SL and TP equal to 0 — the server never sees a hard stop, and the EA never sets a take-profit. The only exit is in CheckForClose: when a position is open and the next bar prints a candle that closes on the opposite side of the MA relative to its open (a SELL triggers when a buy-position's bar opens above MA and closes below; a BUY triggers when a sell-position's bar opens below and closes above), TryClose_EX07014 fires with a 3-pip-equivalent deviation. The retry wrapper walks the same three attempts at 200 ms intervals on REQUOTE, TIMEOUT, PRICE_OFF, or PRICE_CHANGED retcodes that the rest of the EX07xxx family uses. Net result: the EA lives and dies by the reverse cross. It can sit in a trade for five bars or for five hundred; the only way out is the next opposing cross.
TradeSizeOptimized is the most interesting function in the file. It starts from the same risk-percentage-of-free-margin pattern that the other EX07 EAs use, but instead of an equity cap it uses orderCalcMargin against 1.0 lot to derive margin per unit, then sets lot = free_margin × MaximumRisk / margin. MaximumRisk defaults to 0.02 (2%). After that, DecreaseFactor kicks in: the function walks HistorySelect from the most recent deal backwards, counting consecutive losses tagged with this EA's magic 22207014, and the moment it sees a profitable deal (or runs out of history) it stops. If the count is greater than 1, the lot is reduced by lot × losses / DecreaseFactor, so a DecreaseFactor of 3 and a string of three losers gives you lot × 1.0 reduction — the next trade is at minimum lot. The mechanism is the opposite of martingale: a losing streak shrinks position size, and the streak only resets on a winning trade. The final lot is then floored to SymbolInfoDouble(SYMBOL_VOLUME_MIN) and capped to SYMBOL_VOLUME_MAX, with the standard stepvol rounding pass to keep it on the broker's grid.
OnInit is the third piece worth noting. It detects the account margin mode — ExtHedging = (ACCOUNT_MARGIN_MODE == ACCOUNT_MARGIN_MODE_RETAIL_HEDGING) — and SelectPosition() branches on that. Hedging accounts loop PositionsTotal() and match by symbol and magic, so multiple positions in the same direction can stack if the broker permits. Netting accounts use PositionSelect on the symbol directly, and the magic must match. ExtTrade.SetExpertMagicNumber(MA_MAGIC) and SetTypeFillingBySymbol() are the standard wrappers; if the iMA handle fails to create, OnInit returns INIT_FAILED and the EA will not start. There is no global OnTradeTransaction filter, no news blackout, no session window, no equity floor, no daily-loss cap, no time stop, no breakeven, no partial close, no trailing ratchet, no pyramiding. The Bars > 100 sanity check is the only safety net in the entry path.
What the trader gets is a clean test bench for a single MA. Drop it on XAUUSD M5, leave the defaults, and the EA will fire when gold crosses its six-hour shifted SMA. Tighten MovingPeriod to 6 and you get a faster, choppier cross that will trade more often. Push MovingShift back to 0 and the MA becomes current — entries tighten, whipsaws multiply. Increase DecreaseFactor to 6 to slow the post-loss shrink, drop it to 2 to compress the curve. There is no optimizer function in the source (no OnTester), so backtest the parameters across different volatility regimes manually, and accept that on a ranging market this EA will pay for every cross with a loss.
For a backtest expectation: the equity curve on a trending XAUUSD M5 will be lumpy but generally upward — long runs of small profits separated by occasional larger givebacks as the lag-filtered MA falls behind a fast reversal. The decrease factor means drawdowns grow in length, not in lot size, which is the gentler failure mode. On EURUSD H1 the same code is a slow grinder; on M1 the shift=6 will look like nonsense. Treat EX07014 as a price-action baseline — it is the stripped-down reference point the rest of the EX07 MA family is measured against.
Strategy Deep Dive
Each tick of OnTick asks SelectPosition whether the magic-tagged position is open. If yes, CheckForClose runs; if no, CheckForOpen runs. Both functions gate themselves on the first tick of a new bar by reading rt[1].tick_volume and returning early if it exceeds 1, which keeps every decision to a single bar boundary. iMA(_Symbol,_Period,12,6,MODE_SMA,PRICE_CLOSE) is created once in OnInit and reused; the shift=6 means the MA buffer at offset 0 holds the value that was true six bars ago. TradeSizeOptimized computes lot = free_margin × 0.02 / margin_per_lot, then walks the deal history backwards counting consecutive losses and, if the streak exceeds 1, subtracts lot × losses / DecreaseFactor (default 3). The result is rounded to the symbol's volume step, floored to SYMBOL_VOLUME_MIN, and capped to SYMBOL_VOLUME_MAX. There is no OnTester, no news filter, no session window, no pyramiding, no breakeven, no trailing stop, no partial close, and no time stop — the reverse cross is the only mechanism that ends a trade.
Open SELL on the first tick of a new bar when the candle opens above the SMA(12, shift=6, close) and closes below it; open BUY on the mirrored condition (open below, close above). The single iMA handle is the entire signal — no additional indicators, no volume or wick filter, no spread cap. Entry is gated only by Bars > 100 (warm-up) and the terminal trading flag.
Position has no hard SL or TP. The exit is a reverse cross: a SELL triggers the close of an open BUY when that candle opens above the MA and closes below, and vice versa. TryClose_EX07014 retries three times at 200 ms on REQUOTE/TIMEOUT/PRICE_OFF/PRICE_CHANGED before giving up.
No per-trade stop-loss is sent to the server — SL=0 in PositionOpen. The reverse cross in CheckForClose is the only stop the EA enforces, so the worst-case loss is determined by how far price can run between two opposing crosses.
No take-profit is set on open positions — TP=0 in PositionOpen. Profits accumulate until the next reverse cross closes the position, which makes the holding time variable from a few bars to many hundreds.
Suited to a $100 minimum balance on XAUUSD M5 or H1, on a low-spread broker (the cross fires on a single tick with no spread cap, so a 30-pip gold spread will eat the move). The MEDIUM risk rating reflects the 2% MaximumRisk default; pair it with a 1:2 or wider manual TP if you need a hard target, since the EA will not set one. Best for traders who want a clean, transparent MA cross without pyramiding, trailing stops, or session filters, and who are comfortable with a single-SMA-curve equity path.
Strategy Logic
Pipsgrowth EX07014 MA — Strategy Logic Analysis (from .mq5 source)
Family: MA
Magic: 22207014
Version: 2.00
BRIEF:
Classic single moving average crossover EA that opens positions when price crosses the MA, with risk-based lot sizing, decrease factor for loss recovery, and position management across a 12-layer architecture. 12 layers: REGIME, SIGNAL, ENTRY, CONFIRM, NO-TRADE, CAPITAL CAP, RISK, SIZING, MANAGE, EXIT, SCALING, OnTester
INDICATOR STACK:
- Standard
MT5indicators
KEY FUNCTIONS:
TradeSizeOptimized()CheckForOpen()CheckForClose()SelectPosition()TryClose_EX07014()TryClosePartial_EX07014()TryModify_EX07014()
INTERNAL CONSTANTS (0 total):
INPUT PARAMETERS (6 total across 3 groups):
- [=== Identity ===]
MA_MAGIC=22207014// Magic number - [=== Identity ===]
InpTradeComment= "Psgrowth.com Expert_07014" // Trade comment - [=== Risk Management ===]
MaximumRisk=0.02// Maximum Risk in percentage - [=== Risk Management ===]
DecreaseFactor= 3 // Descrease factor - [=== Moving Average Settings ===]
MovingPeriod= 12 // Moving Average period - [=== Moving Average Settings ===]
MovingShift= 6 // Moving Average shift
// Pipsgrowth EX07014 MA — Execution Flow (from source analysis)
// Family: MA
// Classic single moving average crossover EA that opens positions when price crosses the MA, with risk-based lot sizing, decrease factor for loss recovery, and position management across a 12-layer architecture. 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
How to Install This EA on MT5
- 1Download the .mq5 file using the button above
- 2Open MetaTrader 5 on your computer
- 3Click File → Open Data Folder in the top menu
- 4Navigate to MQL5 → Experts and paste the .mq5 file there
- 5In MT5, right-click Expert Advisors in the Navigator panel → Refresh
- 6Drag the EA onto an H4 or Daily chart for best results
- 7Configure EMA periods, ADX threshold, and lot size in the dialog
- 8Enable Allow Algo Trading and click OK
EA Parameters
| Parameter | Default | Description |
|---|---|---|
| MA_MAGIC | 22207014 | Magic number |
| InpTradeComment | "Psgrowth.com Expert_07014" | Trade comment |
| MaximumRisk | 0.02 | Maximum Risk in percentage |
| DecreaseFactor | 3 | Descrease factor |
| MovingPeriod | 12 | Moving Average period |
| MovingShift | 6 | Moving Average shift |
#property copyright "Pipsgrowth.com"
#property link "https://pipsgrowth.com"
#property version "2.00"
#property strict
#property description "Pipsgrowth.com EX07014 Moving_Average — classic MA crossover with risk-based lot sizing, full 12-layer stack."
#include <Trade\Trade.mqh>
input group "=== Identity ==="
input int MA_MAGIC = 22207014; // Magic number
input string InpTradeComment = "Psgrowth.com Expert_07014"; // Trade comment
input group "=== Risk Management ==="
input double MaximumRisk = 0.02; // Maximum Risk in percentage
input double DecreaseFactor = 3; // Descrease factor
input group "=== Moving Average Settings ==="
input int MovingPeriod = 12; // Moving Average period
input int MovingShift = 6; // Moving Average shift
//---
int ExtHandle=0;
bool ExtHedging=false;
CTrade ExtTrade;
//+------------------------------------------------------------------+
//| Calculate optimal lot size |
//+------------------------------------------------------------------+
double TradeSizeOptimized(void)
{
double price=0.0;
double margin=0.0;
//--- select lot size
if(!SymbolInfoDouble(_Symbol,SYMBOL_ASK,price))
return(0.0);
if(!OrderCalcMargin(ORDER_TYPE_BUY,_Symbol,1.0,price,margin))
return(0.0);
if(margin<=0.0)
return(0.0);
double lot=NormalizeDouble(AccountInfoDouble(ACCOUNT_MARGIN_FREE)*MaximumRisk/margin,2);
//--- calculate number of losses orders without a break
if(DecreaseFactor>0)
{
//--- select history for access
HistorySelect(0,TimeCurrent());
//---
int orders=HistoryDealsTotal(); // total history deals
int losses=0; // number of losses orders without a break
for(int i=orders-1;i>=0;i--)
{
ulong ticket=HistoryDealGetTicket(i);
if(ticket==0)
{
Print("HistoryDealGetTicket failed, no trade history");
break;
}
//--- check symbol
if(HistoryDealGetString(ticket,DEAL_SYMBOL)!=_Symbol)
continue;
//--- check Expert Magic number
Full source code available on download
Educational purposes only. Do NOT use with real money. Test on demo accounts only.
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
Markets.com
Exness
IC Markets
Similar Expert Advisors
View All Expert AdvisorsMore Trend Following strategy EAs from our library
Pipsgrowth EX16080 Trend
Pipsgrowth.com EX16080 EURUSDTrendFollower — triple-EMA H4 trend follower, full 12-layer stack.
Pipsgrowth EX16081 Trend
Pipsgrowth.com EX16081 GoldTrendEA — XAUUSD H4 EMA cross with Fib targets, full 12-layer stack.
Pipsgrowth EX16033 Trend
Pipsgrowth.com EX16033 EA_Price_Action — price-action grid scalper, full 12-layer stack.
Community
Educational purposes only. Do NOT use with real money. Test on demo accounts only.