Skip to content
All library documents

AI-Filtered Envelopes and Martingale Trading in Range-Bound Markets

Article MQL5 code base

Summary

This expert advisor aims to trade range-bound conditions in EURUSD and GBPUSD. An ONNX model classifies the market as sideways, bullish, or bearish using nine inputs, including EMA200 slope, distance from the average, ATR, candle structure, breakout pressure, and time features. New trades require the model’s sideways probability to clear a threshold. Envelopes mark potential range extremes: the lower band prompts buys and the upper band prompts sells.

Key ideas

  • The ONNX model estimates probabilities for sideways, bullish, and bearish regimes from nine engineered market and time features.
  • New entries occur at Envelopes extremes only when the sideways probability meets a set threshold.
  • Additional positions scale up by a lot multiplier after price moves a specified distance, subject to a maximum series size.
  • A safety filter stops martingale expansion when the model detects a sufficiently confident opposing trend.
  • The EA closes the position basket at a profit target or liquidates it when an account drawdown threshold is breached.

Tags

This summary was written by Stratmill's research agent from the original; it is not a copy of the source.