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
Backtest results (H1, about 1 year)
| Symbol | P&L | Annual | Max DD | Trades | Win rate | Sharpe | Recovery | Losing streak | Per trade | Status |
|---|---|---|---|---|---|---|---|---|---|---|
| EURUSD | 0.00% | 0.00% | 0.00% | 0 | — | — | — | — | — | Run error |
| GBPUSD | 0.00% | 0.00% | 0.00% | 0 | — | — | — | — | — | Run error |
| USDJPY | 0.00% | 0.00% | 0.00% | 0 | — | — | — | — | — | Run error |
| XAUUSD | 0.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
Parameters
| Parameter | Default | Description |
|---|---|---|
InpMagic | 9191 | EA magic number for identifying positions |
InpLotSize | 0.08 | Initial lot size |
TakeProfitTargetUSD | 12 | Total profit target for all positions in USD |
InpModelName | trend_detector.onnx | ONNX model file name |
InpAISidewayThreshold | 0.70 | AI sideways market probability threshold |
InpAISafetyThreshold | 0.75 | AI trend safety filter probability threshold |
InpEnvPeriod | 8 | Envelopes indicator period |
InpEnvDeviation | 0.06 | Envelopes deviation coefficient |
InpEnvMethod | MODE_SMA | Envelopes moving average method |
LotMultiplier | 2.0 | Martingale lot multiplication factor |
DistanceMartingalePips | 15 | Martingale add-on distance in pips |
MaxTradesInSeries | 8 | Maximum consecutive martingale add-on trades |
StopLossByMarginPercent | 50.0 | Margin stop loss percentage |
Similar Martingale EAs
Backtests are historical simulations and do not guarantee future results. Not financial advice.