EA-68537 · Martingale

SidewaysMartingale

This EA uses an ONNX neural network model to detect sideways market conditions and trades mean-reversion entries at Envelopes indicator bands. When a position goes against it, the EA applies a Martingale recovery strategy by multiplying the lot size and adding positions at fixed pip distances, closing all positions when the combined profit reaches a USD target.

Open the interactive view (equity curve, symbol switch)

Key facts

CategoryMartingale
RiskDangerous
Blow-up riskElevated
Rating★★☆☆☆
TypeTrading EA
TimeframesM15, M30, H1
IndicatorsEnvelopes, ATR, EMA200, ONNX Neural Network
Authorzvickyhac

Backtest results (H1, about 1 year)

SymbolP&LAnnualMax DDTradesWin rateSharpeRecoveryLosing streakPer tradeStatus
EURUSD0.00%0.00%0.00%0—————Run error
GBPUSD0.00%0.00%0.00%0—————Run error
USDJPY0.00%0.00%0.00%0—————Run error
XAUUSD0.00%0.00%0.00%0—————Run error

Converted from MQL5 to Python and run with the same rules for every EA. Positions use MT5 lot sizes (100,000 units per FX lot, 100 oz per gold lot) with 1:100 leverage, one order at a time, and a stop-out below 10% of the starting balance. Sharpe is computed from the equity curve. Results marked as unreliable are shown for completeness only.

Blow-up risk: Elevated

  • Increases the position size after losses (martingale)
  • Can hold up to 8 positions at once

High: stopped out in our backtest, or martingale/grid sizing without a stop loss. Elevated: martingale or grid sizing with a stop loss, or several positions at once without a stop loss. What the label means and what we found →

Strategy analysis

Strategy concept: A mean-reversion approach combining an ONNX neural network for sideways market detection with the Envelopes indicator, capturing pricereversion opportunities when price touches envelope bands during ranging conditions. Entry conditions: Buy when the AI model predicts sideways probability ≥ 0.70 and close price touches the lower envelope band; Sell when sideways probability is high and close price touches the upper envelope band. Exit conditions: All positions in the series close simultaneously when combined unrealized profit reaches the $12 USD target, or the margin stop-loss triggers at 50% equity drawdown from balance. Position sizing: Initial lot is 0.08, with subsequent recovery trades doubling the lot size (2x multiplier) up to a maximum of 8 trades in the series, spaced 15 pips apart. Money management: A margin-based stop-loss at 50% equity drawdown and pre-trade margin check provide risk control, but individual positions have no stop-loss or take-profit. AI safety filter: During Martingale recovery additions, if the opposing trend probability exceeds 0.75, the add-on trade is skipped, providing some directional protection against trending markets.

Strengths

  • Uses ONNX machine learning model to intelligently detect market regime, avoiding entries during trending conditions
  • AI safety filter provides directional protection during Martingale recovery, reducing counter-trend add-on risk
  • Includes margin check and account-level stop-loss, providing a basic risk management framework
  • New bar check prevents duplicate trades within the same candle, reducing overtrading
  • Lot precision handling and broker limit checks (min/max/step/volume limit) are thorough

Weaknesses

  • Martingale strategy inherently carries exponential risk growth; 8 levels at 2x multiplier means the last trade is 256x the initial lot size
  • Individual positions have no stop-loss, relying entirely on account-level margin stop-loss which may fail in extreme gap scenarios
  • Envelope deviation of 0.06 is extremely small, likely generating too many signals and triggering frequently even in mild volatility
  • 15-pip Martingale distance translates to only 1.5 pips on 5-digit brokers, making add-on positions dangerously close together
  • ONNX model file is not embedded; missing file causes INIT_FAILED with no fallback strategy
  • Fixed $12 profit target doesn't scale with position size, potentially causing premature exits on large Martingale positions

Possible improvements

  • Add individual stop-loss per position, at minimum an ATR-based dynamic stop as a last line of defense
  • Make Martingale add-on distance ATR-adaptive instead of fixed pips, preventing overly dense positions in low-volatility instruments
  • Profit target should dynamically scale with total position size rather than using a fixed USD amount
  • Implement a fallback strategy when the ONNX model is missing, such as trading with envelopes-only logic
  • Add a spread filter to avoid opening positions during high-spread conditions, reducing slippage losses
  • Cap maximum total exposure by lot size or margin percentage, not just the number of Martingale layers

Risk assessment

Overall risk: Dangerous

  • Martingale with 8 levels at 2x multiplier can reach 256x initial lot size on the final trade, representing extreme risk
  • No individual stop-loss on positions, relying solely on account-level margin stop which can be gapped through in fast markets
  • 15-pip distance on 5-digit brokers equals only 1.5 actual pips, concentrating positions dangerously close together
  • Extremely small envelope deviation (0.06) causes frequent entries, increasing probability of triggering Martingale sequences on false signals

Evaluation scores

Code quality3.0
Strategy logic3.0
Risk management2.0
Robustness2.0
Innovation4.0
Documentation1.0
Overall2.5

Parameters

ParameterDefaultDescription
InpMagic9191EA magic number for identifying positions
InpLotSize0.08Initial lot size
TakeProfitTargetUSD12Total profit target for all positions in USD
InpModelNametrend_detector.onnxONNX model file name
InpAISidewayThreshold0.70AI sideways market probability threshold
InpAISafetyThreshold0.75AI trend safety filter probability threshold
InpEnvPeriod8Envelopes indicator period
InpEnvDeviation0.06Envelopes deviation coefficient
InpEnvMethodMODE_SMAEnvelopes moving average method
LotMultiplier2.0Martingale lot multiplication factor
DistanceMartingalePips15Martingale add-on distance in pips
MaxTradesInSeries8Maximum consecutive martingale add-on trades
StopLossByMarginPercent50.0Margin stop loss percentage

Similar Martingale EAs

Backtests are historical simulations and do not guarantee future results. Not financial advice.

Get the weekly Arena report

One email a week: ranking changes, new signals and new research. No spam; unsubscribe any time.