Why Most Martingale EAs Bleed Accounts Dry
I've been developing and trading Expert Advisors for over a decade, and I've watched countless traders fall for the martingale trap. The logic sounds seductive: "If I just double my lot size after every loss, one win will recover everything." In a perfect, infinite-liquidity market with unlimited capital, that might work. In reality, it's a fast track to a blown account. I've seen EAs that looked beautiful on backtests—smooth equity curves, high profit factors—only to implode in live trading when a string of five or six consecutive losses hit. The math is unforgiving: a 6-loss streak on a 2x martingale means you're risking 63 times your initial lot on the final trade. One more loss, and your broker's margin call saves you from yourself.
But there is a smarter, more sustainable way to size positions dynamically. It's called anti-martingale. Instead of increasing risk after losses, you increase risk after wins—scaling into profitable trades while keeping losses small. This approach aligns with the fundamental truth of trading: you don't know which trades will be winners, but you can let your winners run and cut your losers short. In this post, I'll show you how to code a robust anti-martingale position sizing system in MQL4 that you can integrate into any Expert Advisor, along with the practical trade-offs you need to understand before going live.
What Is Anti-Martingale Position Sizing?
Anti-martingale is a positive progression system. After each winning trade, you increase your position size by a predefined factor. After a losing trade, you reset to your base lot size. The core philosophy is that you want to be aggressive when you're on a winning streak (the market is "with you") and conservative when you're losing (the market is "against you"). This is the opposite of the gambler's fallacy—it doesn't assume that a loss "must" be followed by a win. Instead, it accepts that losses are part of the game and focuses on maximizing gains during favorable sequences.
Let's be clear: anti-martingale does not turn a losing strategy into a winning one. If your entry logic has negative expectancy, no amount of position sizing will save you. What it does is amplify the positive expectancy of a genuinely profitable system by concentrating risk where it's most likely to pay off. It also has a powerful psychological benefit: you never feel the panic of a huge losing trade because your maximum loss is always capped at your base lot size.
How It Differs from Fixed Fractional and Kelly Criterion
Many traders confuse anti-martingale with other dynamic sizing methods. Fixed fractional sizing (e.g., risking 1% of equity per trade) adjusts lot size based on account balance, not trade outcomes. The Kelly Criterion optimizes for long-term growth using win rate and average win/loss ratio. Anti-martingale is simpler: it only cares about the sequence of wins and losses, not the magnitude of each win or the current account equity. This makes it easy to implement and backtest, but also means it can over-allocate during a streak if you're not careful.
Practical Implementation in MQL4
Let's get our hands dirty with real code. I'll show you how to build an anti-martingale module that you can drop into any MQL4 Expert Advisor. The key components are a consecutive win counter, a multiplier, and a maximum lot size cap. Here's the core function:
//+------------------------------------------------------------------+
//| Calculate anti-martingale lot size |
//+------------------------------------------------------------------+
double AntiMartingaleLotSize(double baseLot, int consecutiveWins,
double multiplier, double maxLot)
{
double lot = baseLot * MathPow(multiplier, consecutiveWins);
// Apply maximum lot cap
if(lot > maxLot) lot = maxLot;
// Ensure lot respects broker minimum and step
double minLot = SymbolInfoDouble(_Symbol, SYMBOL_VOLUME_MIN);
double stepLot = SymbolInfoDouble(_Symbol, SYMBOL_VOLUME_STEP);
lot = MathRound(lot / stepLot) * stepLot;
if(lot < minLot) lot = minLot;
return(lot);
}
This function takes your base lot (e.g., 0.01), the current number of consecutive wins, a multiplier (e.g., 2.0), and a hard maximum lot size. It uses MathPow to calculate the exponential progression. The key safety measure is the maximum lot cap—without it, a long winning streak could produce absurdly large positions. I also include a rounding step to ensure the lot size conforms to your broker's volume step (typically 0.01 for micro lots).
Integrating into an EA's Trade Logic
You need to track consecutive wins across the EA's lifetime. I recommend using a global variable stored in the terminal's global variable space (not just a memory variable) so the count persists even if the EA is restarted or the terminal is closed. Here's how to implement the tracking:
//+------------------------------------------------------------------+
//| Track consecutive wins |
//+------------------------------------------------------------------+
void UpdateConsecutiveWins()
{
static int prevTotalTrades = 0;
static int consecutiveWins = 0;
int currentTotal = OrdersHistoryTotal();
if(currentTotal > prevTotalTrades)
{
// Select the most recent closed order
if(OrderSelect(currentTotal - 1, SELECT_BY_POS, MODE_HISTORY))
{
if(OrderProfit() > 0)
{
consecutiveWins++;
GlobalVariableSet("ConsecutiveWins_" + _Symbol, consecutiveWins);
}
else
{
consecutiveWins = 0;
GlobalVariableSet("ConsecutiveWins_" + _Symbol, 0);
}
}
prevTotalTrades = currentTotal;
}
}
This function runs on every tick (or every new bar, to reduce CPU load). It checks if a new historical order has appeared, evaluates its profit, and updates the consecutive win counter stored in the terminal's global variables. I prefix the variable name with the symbol to avoid conflicts in multi-symbol EAs.
Putting It All Together in the EA's Main Loop
In your EA's OnTick() or OnBar() function, call the update function and then use the stored value to calculate your lot size before opening a new trade:
//+------------------------------------------------------------------+
//| Expert tick function |
//+------------------------------------------------------------------+
void OnTick()
{
// Update consecutive win count
UpdateConsecutiveWins();
// Get current consecutive wins from global variable
int wins = (int)GlobalVariableGet("ConsecutiveWins_" + _Symbol);
// Calculate lot size
double lot = AntiMartingaleLotSize(0.01, wins, 2.0, 0.5);
// Entry logic (simplified example)
if(YourEntryCondition())
{
int ticket = OrderSend(_Symbol, OP_BUY, lot, Ask, 3, 0, 0,
"AntiMartingaleEA", MagicNumber, 0, Green);
}
}
Notice the hard cap of 0.5 lots. Even with a base of 0.01 and a multiplier of 2.0, after 5 consecutive wins you'd be at 0.32 lots, and after 6 wins at 0.64—but the cap stops you at 0.5. This prevents runaway sizing during exceptional streaks.
Pros, Cons, and Risks
Let me be brutally honest about where anti-martingale shines and where it can hurt you.
| Aspect | Advantage | Disadvantage / Risk |
|---|---|---|
| Drawdown Control | Maximum loss per trade stays at base lot, limiting downside. | During a losing streak, small base lots may not recover previous gains quickly. |
| Win Streak Amplification | Compounds gains during favorable market conditions. | A single loss after a long streak resets to base, potentially giving back a large portion of accumulated profits. |
| Psychological Impact | No panic from large losing trades; you're never "all in" on a loser. | May lead to overconfidence during streaks, causing traders to override the system. |
| Backtest Sensitivity | Works well with strategies that have win rates above 50% and good risk-reward. | Over-optimizing multiplier and cap on historical data can lead to curve-fitting and poor live performance. |
The biggest risk I've observed in practice is over-optimization. Traders tweak the multiplier and maximum lot cap to produce the highest backtest profit, often ending up with a multiplier of 3.0 or more and a cap that's too high. In live trading, a 10-win streak might look amazing on the backtest, but the moment the market regime shifts, the EA takes a massive hit. I recommend keeping the multiplier between 1.5 and 2.0 and the maximum lot no more than 10x your base lot. This gives you meaningful scaling without excessive exposure.
Example Walkthrough: A Trend-Following EA on EUR/USD
Let's walk through a concrete example. Suppose you have a simple trend-following EA that uses the 50-period SMA and the 200-period SMA. It buys when the 50 SMA crosses above the 200 SMA (golden cross) on the H1 chart, and sells on the death cross. Your base lot is 0.01, multiplier is 2.0, and max lot is 0.1. You start with a $1,000 account.
- Trade 1 (Win): Golden cross occurs. Lot = 0.01. Price rises 80 pips. Profit = $8 (assuming 1:100 leverage). Consecutive wins = 1.
- Trade 2 (Win): Next golden cross. Lot = 0.01 * 2^1 = 0.02. Price rises 60 pips. Profit = $12. Consecutive wins = 2.
- Trade 3 (Win): Lot = 0.01 * 2^2 = 0.04. Price rises 100 pips. Profit = $40. Consecutive wins = 3.
- Trade 4 (Loss): Lot = 0.01 * 2^3 = 0.08. Price drops 40 pips. Loss = $32. Consecutive wins reset to 0.
- Trade 5 (Win): Lot resets to 0.01. Price rises 50 pips. Profit = $5.
Notice that the loss on trade 4 ($32) was larger than the first three wins combined ($8 + $12 + $40 = $60), but you still came out ahead overall. Without anti-martingale, you would have risked 0.01 on every trade: four wins ($8+$6+$10+$5=$29) and one loss ($4) for a net of $25. With anti-martingale, your net profit was $60 - $32 + $5 = $33. The system amplified gains during the winning streak while capping the loss on the losing trade to a manageable level. The key was that the losing trade happened after a streak, so the lot size was already elevated. If the loss had occurred earlier (e.g., on trade 2), the impact would have been smaller.
Key Takeaways
- Anti-martingale is not a magic bullet. It only works with strategies that have positive expectancy and a win rate above 50%. Test your entry logic first without any position sizing to confirm it's profitable.
- Always cap your maximum lot size. Without a hard cap, a long winning streak can produce position sizes that exceed your account's risk tolerance.
- Use a conservative multiplier. 1.5 to 2.0 is a safe range. Higher multipliers look great on backtests but are dangerous in live trading.
- Store consecutive wins persistently. Use global variables or file storage so the count survives terminal restarts. Losing the streak count mid-trade can cause incorrect lot sizing.
- Backtest with out-of-sample data. Optimize the multiplier and cap on one period (e.g., 2020-2022) and validate on another (2023-2024). If the performance degrades significantly, your strategy is likely overfitted.
Frequently Asked Questions
Can I use anti-martingale with a scalping EA that has a high win rate but small profit per trade?
Yes, but be cautious. Scalping EAs often have win rates above 70%, which makes them good candidates for anti-martingale. However, the small profit per trade means you need a higher multiplier to see meaningful gains, which increases risk. I recommend a multiplier of 1.3 to 1.5 for scalpers and a very tight maximum lot cap (e.g., 5x base lot). Also, ensure your broker's spread and commission don't eat up the scaled profits.
What happens if my EA opens multiple positions simultaneously? Does the consecutive win counter still work?
The approach I've shown assumes one trade at a time. For multi-position EAs, you need to define what constitutes a "win." You could track wins per position (e.g., each closed position is a data point) or per signal (e.g., a cluster of positions closed at the same time). I recommend the latter: sum the profit of all positions closed within the same bar or within a






