Loading…

Anti-Martingale Demonstrator

"Anti-martingale" (also called reverse martingale) is often pitched as the safe alternative to martingale because it never chases a loss by doubling down. That is true, but it is not the same as being safe outright: any scheme that scales up during a winning streak is, by construction, at its largest size exactly when the streak is most likely to end. This EA is built to show that plainly rather than to hide it. The trading signal is a deliberately ordinary fast/slow SMA cross, so what is being demonstrated is the sizing behaviour, not a clever entry. After every closed trade, the position size for the next trade is set from the result of this one: multiplied by InpWinMultiplier on a win, and either reset fully to InpBaseLots or cut by InpLossMultiplier on a loss, with a hard ceiling at InpMaxMultiplier times the base lot no matter how long a streak runs. Every time one of this EA's own trades closes, its real pip result is replayed at a fixed InpBaseLots size to build a second, simulated equity curve in parallel with the real one. Both curves are driven by exactly the same sequence of wins and losses, so the chart comment's comparison between "real anti-martingale P/L" and "simulated flat P/L" is a fair one - it shows what the variable sizing actually bought or cost against doing nothing clever at all, on the same trades, not on two different signal runs that happened to disagree by chance. Notes and limitations - This is an educational demonstrator, not a strategy recommendation. The SMA cross signal is intentionally plain; the point is the sizing rule. - The simulated flat-sizing curve ignores swap and commission timing differences that a real fixed-lot run might show, though it does use the same tick-value-based money conversion as the real trade. - Trade history from before the EA was attached is not replayed into the comparison - the simulated curve starts from zero at attach time. - One position at a time, tracked by InpMagicNumber. An opposite cross closes and reverses; a same-direction cross while already positioned is ignored. - InpMaxMultiplier is the only thing standing between a long winning streak and an oversized position - treat it as the most important input here. - On the MQL5 build, entries refuse on a netting account if the chart symbol already carries a position under a different magic number, and the flat-sizing comparison skips (but still sizes) any closed trade whose opening deal cannot be located in history - see MQL4 VERSUS MQL5 DIFFERENCES above.

Expert advisor · MT4 · v1.0 · Free

About Anti-Martingale Demonstrator

Anti-Martingale Demonstrator is an expert advisor (trading robot) for MetaTrader 4 based on Moving Average. It increases the lot size after a losing trade (martingale) and can size trades from your balance and risk percent. It has 13 settings, such as Fast ma period, Slow ma period and Stop loss pips. MQL source code included.

Files in the download: AntiMartingaleDemonstrator.ex4, AntiMartingaleDemonstrator.mq4, AntiMartingaleDemonstrator.txt.

Trading robots can lose money. Check every setting and test on a demo account before using real funds.

Settings

SettingDefaultWhat it does
Fast ma period10Fast SMA period
Slow ma period30Slow SMA period
Stop loss pips40Stop loss distance, in pips
Take profit pips80Take profit distance, in pips (0 = none)
Base lots0.01Starting lot size and the size used for the flat-sizing comparison
Win multiplier1.3Multiply current lots by this after a winning trade
Reset to base after losstruetrue = full reset to InpBaseLots after any loss (conservative)
Loss multiplier0.5Multiply current lots by this after a loss, only when the reset above is off
Max multiplier5.0Hard cap on lots as a multiple of InpBaseLots - the runaway-growth brake
Magic number20260902Magic number for orders this EA places
Slippage pips3Slippage tolerance, in pips
Max retries5Attempts per trade action before giving up
Retry wait ms500Pause between attempts, milliseconds

How to install

  1. Download the ZIP from your PolyMaria library and unzip it.
  2. In MetaTrader 4 open File → Open Data Folder, then go to MQL4 → Experts.
  3. Copy the .mq4 file(s) there. Put any .mqh files in MQL4 → Include.
  4. Open the .mq4 file in MetaEditor and press Compile (F7) if MetaTrader does not show it.
  5. Drag the expert advisor from the Navigator onto a chart, check the settings, allow Algo/Auto Trading and press OK.
  6. Test it first on a demo account or in the Strategy Tester.

Download the PDF guide

Tags: Martingale · Risk & Lot Size · Moving Average · MT4 Expert Advisor · MQL4 Source Code

Expert advisors (EA) for MT4 & MT5 · PolyMaria