MetaTrader 5 Expert Advisor

Controlled
Martingale EA
v3.5

A disciplined grid-based Expert Advisor for MetaTrader 5. No indicators — pure price-action midpoint signals drive a fixed martingale structure with ATR-scaled spacing, adaptive direction control, and combined basket take profit.

10 Max Grid Levels
3 Pairs Optimized
H1 Default Timeframe
ATR Grid Spacing

How It Works

Two independent code paths keep entry signals separate from grid continuation, eliminating the grid-freeze bug found in earlier martingale systems.

📍

Midpoint Signal

Each bar, the EA computes the midpoint of the previous candle's high and low. If price is above the midpoint it signals BUY; below signals SELL. No external indicators required.

🅐

Path A — New Basket

When no positions are open, a new L1 trade is placed only when the bar signal matches the allowed direction. The starting lot resets to the base lot after an easy win.

🅑

Path B — Grid Continuation

Once a basket is open, additional levels (L2, L3…) are added whenever price moves against the basket by at least ATR × multiplier. This path is unconditional — it runs every bar regardless of the signal.

🔄

Direction Flip

When a basket reaches the max grid level it is counted as a "hard basket". After a configurable number of hard baskets, the EA flips direction (BUY → SELL or SELL → BUY) and scales the next lot size.

Basket Take Profit

All positions in the basket are closed together when their combined floating profit reaches the target in pips. This aggregates all levels into a single exit event.

🛡

Equity Guard

An optional emergency stop closes all positions if the account drawdown exceeds a percentage threshold, protecting against extreme adverse market conditions.

Execution flow — each new bar
New Bar
Calc Midpoint & ATR
Positions open?
No → Path A (signal-gated)
Open L1
Positions open
Path B (unconditional)
Distance ≥ ATR × mult?
Add next level
Max levels → Hard Basket → Flip

Parameters

All input parameters with their default values and descriptions. Use the pre-optimized .set files below instead of tuning manually.

Grid & Lot Sizing
InpBaseLot 0.01 Base lot size for the first trade (L1) of each easy basket
InpMultiplier 2.0 Lot multiplier applied to each successive grid level
InpMaxTrades 10 Maximum grid levels per basket. Reaching this triggers a hard basket count
InpMaxLosses 3 Number of hard baskets before the EA flips direction and scales lot size
Spacing & Take Profit
InpATRPeriod 14 Period used to calculate the ATR for dynamic grid spacing
InpATRMultiplier 1.5 Grid step = ATR × this value. Higher = wider levels, less frequent adds
InpBasketTP_Pips 30.0 Combined basket floating profit target in pips before all positions close
Risk Management
InpMaxDrawdownPct 20.0 If equity drawdown exceeds this %, the equity guard closes all positions
InpUseEquityGuard false Enable or disable the emergency equity drawdown protection
General
InpTimeframe H1 Timeframe for bar signals and ATR calculation
InpMagic 334455 Magic number to identify this EA's orders (change if running multiple instances)
InpComment MartV3 Trade comment prefix attached to each order
InpVerboseLog false Print detailed per-bar logs to the Experts journal
InpChartDisplay false Show live status overlay on the chart (disable during optimization)

Optimized Configurations

Download the pre-optimized .set files for each currency pair. Load them in MetaTrader 5 via Expert Advisor → Load settings.

EURUSD
Euro / US Dollar
🇪🇺 🇺🇸
Base Lot0.01
Multiplier2.0
Max Trades10
ATR Period14
ATR Multiplier1.5
Basket TP (pips)30
AUDUSD
Australian Dollar / US Dollar
🇦🇺 🇺🇸
Base Lot0.01
Multiplier2.0
Max Trades10
ATR Period14
ATR Multiplier1.5
Basket TP (pips)30
USDCAD
US Dollar / Canadian Dollar
🇺🇸 🇨🇦
Base Lot0.01
Multiplier2.0
Max Trades10
ATR Period14
ATR Multiplier1.5
Basket TP (pips)30

* Parameter values shown are defaults. The downloaded .set files contain pair-specific optimized values.

Trade with IC Markets

This EA is optimized for raw spread accounts. IC Markets offers some of the tightest spreads in the industry with fast execution — critical for a martingale system where execution speed directly impacts grid levels.

Use the live price widget to monitor your pairs in real time without leaving this page.

Raw Spreads from 0.0 pips Fast Execution MetaTrader 5 Supported Regulated Broker