Summary: Part 4 of a 10-part series. EA strategy principles explained: trend-following, mean-reversion, and volatility-adaptive logic. Includes pseudo-code and anti-martingale safeguards.




Title: EA Strategy Principles Part 4: Non-Martingale Logic and Volatility-Adaptive EAs

Most retail EAs fail because they rely on martingale or grid-without-stops. A robust EA is built on three principles: non-martingale position sizing, adaptive parameters, and hard risk limits. This guide decomposes three production-ready EA logic structures.

1. Principle 1 – Never Multiply Losers (Anti-Martingale)
Martingale doubles lot size after a loss. It produces small wins and catastrophic drawdowns. Instead use:
  • Fixed fractional sizing: Same risk percentage per trade regardless of prior outcome

  • Anti-martingale (growth-aware): Increase size only after profit targets are met, never after losses


  • ```python
    # Anti-martingale logic (correct)
    if last_trade_won and equity_grew_by(5_percent):
    next_risk = previous_risk * 1.1 # gradual increase after success
    else:
    next_risk = base_risk # never increase after loss
    ```

    2. Principle 2 – Volatility-Adaptive Entries
    A static distance EA dies when volatility changes. Use ATR-based adaptation:
    ```python
    # Volatility-adaptive EA logic skeleton
    atr_value = iATR(Symbol(), PERIOD_H1, 14, 1)

    def get_dynamic_distance():
    if atr_value < 15 * Point:
    return 15 * Point
    elif atr_value < 30 * Point:
    return atr_value * 0.8
    else:
    return 25 * Point # cap during high volatility

    entry_long = High[1] + get_dynamic_distance()
    stop_loss = entry_long - (atr_value * 1.5)
    take_profit = entry_long + (atr_value * 2.0)
    ```

    3. Principle 3 – Three EA Logic Types Compared

    | EA Type | Logic | Pros | Cons |
    |---------|-------|------|------|
    | Trend-following | Buy when price > moving average + filter | Captures big moves | Whipsaws in ranges |
    | Mean-reversion | Buy when price oversold (RSI < 30) | High win rate | Catastrophic on trends |
    | Hybrid | Switch logic based on ADX (ADX>25 = trend, ADX<20 = reversion) | Adapts to market | Needs careful calibration |

    4. Complete EA Structure – The Robust Template
    Every production EA must have these five blocks:
    ```python
    def start():
    if not is_trading_time(): return
    if is_news_event(): return
    if get_current_drawdown() > MAX_DRAWDOWN_PERCENT: return

    risk_percent = calculate_risk_based_on_drawdown()
    lot_size = compute_lot_size(risk_percent)

    if trend_following_condition():
    execute_trade(OP_BUY, lot_size, atr_based_sl(), atr_based_tp())
    elif mean_reversion_condition():
    execute_trade(OP_BUY, lot_size * 0.7, tight_sl(), reversion_tp())
    ```

    5. The Martingale Trap – Exact Numbers
    Assume a martingale EA with starting 0.01 lot, 6 levels, 20 pip distance.
  • Level 6 lot size: 0.32 lot (32x initial)

  • Margin required at level 6: ~$2,560 (on EURUSD with 1:500 leverage)

  • Probability of hitting level 6 in a ranging market: ~15% per month

  • Expected drawdown when level 6 is hit: 30-50% of account

  • A mature grid (fixed lots, fixed distance, kill switch) is mathematically distinct from martingale.

    6. Backtesting Requirements for EAs
    Do not trust simple backtest reports. Require:
  • Minimum 2,000 trades (not candles)

  • Slippage model: 1-2 pips per trade

  • Commission model: $3-7 per lot round-turn

  • Walk-forward validation: Optimize on 3 years, test on next 2 years without re-optimization

  • Monte Carlo simulation: Randomly remove 10-30% of trades to test robustness


  • 7. News Filter Implementation
    ```python
    news_events = ["NFP", "FOMC", "ECB", "CPI", "GDP"]
    def is_safe_to_trade():
    for event in news_events:
    if within_30_minutes_of(event):
    return False
    return True
    ```
    Never trade an EA 30 minutes before or after major news.

    8. Next Step
    Part 5 covers backtesting methods – tick data, walk-forward analysis, and Monte Carlo simulation.

    Reference:
  • Pardo, R. (2008). *The Evaluation and Optimization of Trading Strategies*. Wiley.

  • Chan, E. P. (2009). *Quantitative Trading*. Wiley.