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:
```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.
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:
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: