Balanaced Martingale EA MT4/MT5 Backtests & New Optimized Set Files

Balanaced Martingale EA MT4/MT5 Backtests & New Optimized Set Files

16 February 2024, 20:20
Biswarup Banerjee
0
739

Complete User Documentation — MT4 & MT5

1. OVERVIEW

The Balanced Martingale EA is a position-sizing robot that applies a martingale multiplier to both losing and winning trades, letting you scale into or out of a trend. It uses a configurable moving average filter to detect the dominant direction and only opens trades aligned with that trend. This solves the classic martingale problem of blowing up in a sideways market by gating entries with a trend check, while still letting you recover losses aggressively when the trend is in your favor.

Who Should Use It: Experienced retail forex traders who understand the risks of martingale systems and want a disciplined, automated way to apply a balanced martingale strategy — one that also compounds winners — on trending pairs like EUR/USD or GBP/JPY.

Main Benefit: Automates a balanced martingale approach that scales both losing and winning positions, with a trend filter to reduce the risk of catastrophic drawdowns during range-bound markets.


2. INPUT PARAMETERS & SETTINGS

This product shares a common set of general input settings with all Expert Advisor products in this series. The following sections are covered in the common guide: General Settings (lot size, SL/TP modes, magic number, trade direction), Breakeven Settings, Trailing Stop Settings, News Filter Settings and News Action Settings, Martingale Settings, Grid Settings, Hedge Settings, Risk Settings, Position Sizing, Alert Settings, Display Settings, Trade Time Settings, Trade Days Settings, Safeguard Settings, and Trend Filter Settings (MA Filter, ADX Filter, RSI Filter, MACD Filter, Parabolic SAR Filter — each with their own strategy options). All of these are fully documented in the Common General Input Settings for Expert Advisors. The sections below cover only the product-specific inputs unique to this product.

General Settings

These two toggles control how the EA accounts for swap costs and whether it logs historical trade data for backtest analysis — both affect profit calculations and optimization accuracy.

Setting Name Type Default Value Description Example
Include Swap charges in Profit bool true When enabled, the EA adds overnight swap fees to the running profit calculation for each position. This matters for martingale systems because swap costs can eat into the equity needed to sustain a losing streak. Disable it if you want to see raw price-based P&L only. Keep true for realistic backtests on high-swap pairs like GBP/JPY; set false if you trade only intraday and want to ignore swap.
Enable history for backtests or optimization bool false When true, the EA records historical trade data into a file during backtests or optimization runs. This lets you analyze trade sequences and equity curves after the test. Leave it off for live trading to avoid unnecessary file writes. Enable only during optimization to export trade logs; keep false in live trading to reduce disk I/O.

Martingale Settings

These two multipliers define how aggressively the EA increases lot size on consecutive losing or winning trades — the core of the balanced martingale approach.

Setting Name Type Default Value Description Example
Martingale Factor on losing trades double 2 Each time a trade closes at a loss, the next trade's lot size is multiplied by this factor. A value of 2 doubles the position size after each loss, aiming to recover the loss with a single win. Higher values increase recovery speed but also risk. Use 2 for a classic martingale recovery; try 1.5 for a more conservative approach on volatile pairs like GBP/JPY.
Martingale Factor on winning trades double 3 After a winning trade, the next trade's lot size is multiplied by this factor. This lets you compound profits during a winning streak. A value of 3 triples the lot after each win, which can rapidly grow equity but also increases exposure. Set to 1 to disable win compounding; use 2 for moderate growth on trending days.

Safeguard Settings

These four parameters act as circuit breakers for backtesting and live trading, limiting drawdown, ensuring minimum profitability, and preventing the EA from running indefinitely without activity.

Setting Name Type Default Value Description Example
Max Loss from initial balance [0: disable] double 0.0 Sets a maximum drawdown limit as a percentage of the starting account balance. When equity drops below this threshold, the EA stops all trading. This is your primary safety net against a martingale runaway. Set to 0 to disable the check. Enter 20 to stop trading if equity falls 20% below initial balance — a sensible hard stop for most accounts.
Minimum Profit Percent [backtesting only] [0: disable] double 0 During backtests, the EA will stop running if the total profit percentage falls below this value. Useful for filtering out poor-performing parameter sets in optimization. Has no effect in live trading. Set to 5 to reject any optimization run that doesn't achieve at least 5% net profit.
Minimum Trades [backtesting only] [0: disable] double 0 Sets a minimum number of trades that must be executed during a backtest for the results to be considered valid. Helps you avoid overfitting to a few lucky trades. Disabled by default. Use 50 to ensure at least 50 trades were taken before trusting the backtest metrics.
Max inactive days [backtesting only] [0: disable] int 0 If the EA goes this many consecutive calendar days without opening a trade during a backtest, it stops. This prevents the optimizer from wasting time on parameter sets that never trigger entries. Set to 30 to kill any backtest run that sits idle for a month — useful when scanning many MA periods.

Trend Filter Settings

These two settings control how the


3. HOW IT WORKS

Core Calculation & Logic

The Balanced Martingale EA monitors every tick or every bar (depending on your scan mode) and calculates the current position of price relative to a configurable moving average. That MA acts as your trend compass — if price is above it, the EA only looks for long entries; below it, only shorts. The real magic is in the lot sizing: after each closed trade, the EA multiplies the base lot size by the losing or winning factor you set. So if you lose a 0.01 lot trade with a factor of 2, the next trade opens at 0.02 lots. If you win that one with a factor of 3, the following trade jumps to 0.06 lots. This creates a compounding effect on both sides of the P&L curve, which is why you need to be careful with those multipliers.

The mathematical basis is straightforward: the EA tracks the sequence of wins and losses in memory and applies the multiplier to the base lot size for the next trade. It doesn't use any fancy neural nets or hidden indicators — just price relative to MA for direction, and a simple counter for the martingale sequence. The MA period and shift are set in the common trend filter settings (documented in the general guide linked above). If you disable the MA filter entirely, the EA will trade in both directions, which can work in strong trending markets but gets dangerous in choppy conditions.

Entry Strategies Explained

The EA uses a single core strategy based on the moving average filter, but you can configure it to behave differently by adjusting the MA parameters and the martingale factors. Here's the breakdown:

MA Trend Filter Strategy

BUY Signal: Price closes above the MA line AND the EA has no open positions in the opposite direction. The EA then opens a buy at market with the current martingale-adjusted lot size.

SELL Signal: Price closes below the MA line AND no opposing positions exist. The EA opens a sell at market with the adjusted lot size.

Best For: Trending markets like EUR/USD during London or New York sessions. Avoid using this in range-bound markets where price whipsaws around the MA — you'll get chopped up by false signals.

Step-by-Step Workflow

Step 1: Attach to chart Drag the EA onto a chart for your chosen pair (e.g., EURUSD on H1). Make sure AutoTrading is enabled in MT4/MT5.

Step 2: Set your base lot size Enter 0.01 in the "Lot Size" field if you're starting small. This is the foundation for all martingale calculations.

Step 3: Configure martingale factors Set "Martingale Factor on losing trades" to 2 and "Martingale Factor on winning trades" to 1.5 for a conservative start. You can increase the win factor later if you see consistent trends.

Step 4: Set stop-loss and take-profit Choose "Pips" mode and enter 50 for stop-loss and 100 for take-profit. This gives each trade room to breathe while capping risk.

Step 5: Enable the MA filter In the common trend filter settings (see the general guide), set the MA period to 20 and shift to 0. This keeps you on the right side of the trend.

Step 6: Set your safety net Enter 20 in "Max Loss from initial balance" to stop trading if equity drops 20% below starting balance. This is non-negotiable for martingale systems.

Step 7: Run a backtest first Use the Strategy Tester with "Every tick" mode for at least 6 months of data. Check the equity curve for smoothness — if you see sharp drops, reduce your multipliers.

Step 8: Go live with a demo account Run the EA on a demo for at least 2 weeks before touching real money. Watch how it behaves during news events and rollovers.


4. RISK MANAGEMENT FEATURES

This EA includes several built-in safeguards to help you survive the inevitable losing streaks that martingale systems produce. Here's what each one does:

Feature Description
Max Loss from Initial Balance Stops all trading when equity drops below a percentage of your starting balance. Set this to 20% or less — it's your last line of defense against a martingale blowout. Disable only if you're monitoring the EA 24/7.
Minimum Profit Percent (backtest only) Filters out optimization runs that don't hit a minimum profit threshold. Use 5-10% to avoid overfitting to marginal strategies. Has no effect in live trading — it's purely a backtest quality filter.
Minimum Trades (backtest only) Ensures your backtest results are based on a statistically meaningful number of trades. Set to 50-100 to avoid trusting a strategy that got lucky on 3 trades. Disabled by default.
Max Inactive Days (backtest only) Stops the backtest if the EA goes this many days without opening a trade. Useful for detecting parameter sets that are too conservative. Set to 30 to catch strategies that never trade.
Hidden SL/TP When enabled, the stop-loss and take-profit levels are hidden from the broker's server. This prevents other traders or algorithms from seeing your exit levels. Useful if you're trading on a platform with visible order book data.

Quick Start Guide

Follow these steps to get started in under 5 minutes:

  1. Download and install: Purchase the EA from the MQL5 Market, then download and install it via the MT4/MT5 Navigator panel (drag it to "Expert Advisors" folder).
  2. Attach to a chart: Open a chart for your preferred pair (e.g., EURUSD on H1), drag the EA from Navigator onto the chart, and confirm the dialog.
  3. Set your base lot: Enter 0.01 in the "Lot Size" field — start small until you understand the EA's behavior in live conditions.
  4. Configure martingale factors: Set losing factor to 2 and winning factor to 1.5. This gives you recovery power without excessive risk.
  5. Enable the MA filter: In the common settings (linked above), set MA period to 20 and shift to 0. This keeps you trading with the trend.
  6. Set your safety limit: Enter 20 in "Max Loss from initial balance" to stop trading if equity drops 20% below starting balance.
  7. Run a backtest: Use the Strategy Tester with "Every tick" mode for at least 6 months of data. Check the equity curve for smoothness.
  8. Test on demo: Run the EA on a demo account for 2 weeks minimum before going live. Monitor drawdown and trade frequency.


Installation Guide for MQL Products | Updating Purchased MQL Products on MT4/MT5 | General Troubleshooting Guide | Backtest and Set Files

Check all my products: https://www.mql5.com/en/users/biswait50/seller

Contact me for support: https://www.mql5.com/en/users/biswait50