EA Apex Trading

EA Apex Trading

7 July 2026, 10:41
Vitali Vasilenka
0
45

A trend-breakout Expert Advisor based on Trendlines with Breaks and Range Weighted EMA
Category: Strategies • Platform: MetaTrader 5 • Default symbol XAUUSD M5

 


About the Expert Advisor - https://www.mql5.com/en/market/product/184358?source=Site+Market+Product+Page
EA Apex Trading is a fully automated Expert Advisor for MetaTrader 5, built around two proven indicators: Trendlines with Breaks and Range Weighted EMA (RwEMA). Market entry occurs only when both indicators confirm each other: a channel breakout aligns with the direction and slope of the weighted moving average. This dual-filter approach eliminates most of the false signals typical of single-indicator breakout strategies.
Beyond the core signal logic, the EA features an industrial-grade risk management suite: ATR-based stops, auto-lot sizing based on a percentage of the deposit, a limited "smart" martingale with reversal, a daily drawdown limit, and a session time filter.

Key Highlights
Trend breakout → RwEMA slope confirmation → ATR-SL/TP → controlled martingale with reversal. The system operates on a "one tick per bar" basis, utilizing a unified indicator cache and headless mode for optimization.
Key Advantages

  • Dual entry confirmation — a dual signal filter eliminates noise and counter-trend entries.
  • ATR-based stops — stop-loss and take-profit levels adapt to current volatility rather than being hard-coded in points.
  • Flexible entry modes — 4 modes (BREAKOUT, PULLBACK, TREND_CONF, ANY) ranging from aggressive to smoothed.
  • Multi-confirmation — up to 4 independent confirmation filters (slope, distance, cross, momentum) with ALL / ANY / MAJORITY logic.
  • Smart Martingale — geometric lot multiplier, hard cap, direction reversal, and cooldown period after a series.
  • Money management — auto-lot based on risk percentage, daily drawdown limit, session filter, and margin/stop checks.
  • Strategy Tester optimization — unified ATR and EMA caching (single CopyBuffer call per bar); "headless" mode completely disables the HUD during testing, resulting in 5–10x faster runs.
  • MQL5 Market compliance — volume, lot step, SYMBOL_TRADE_STOPS_LEVEL, and free margin are validated prior to `OrderSend`.

How the built-in indicators work

1. Trendlines with Breaks
The indicator constructs the upper and lower boundaries of a dynamic price channel based on extremes over N bars and a volatility coefficient. Channel slope is calculated using one of three selectable methods: ATR, standard deviation, or linear regression. When the price closes a bar outside the channel, a binary signal—`upos` (upside breakout) or `dnos` (downside breakout)—is generated.

What the Expert Advisor reads
values ​​of the upper and lower lines (for level plotting and logging);
`upos` / `dnos` flags at the close of the previous bar—this serves as the primary entry trigger; previous state (prevUpos / prevDnos) — to distinguish a fresh breakout from a continuation of the move.
The channel length (InpLength) and multiplier (InpMult) are fully customizable. The default preset for XAUUSD M5 uses 43 bars and a coefficient of 6.16, with the slope calculated via ATR—the fastest and most stable method.

2. Range Weighted EMA (RwEMA)
RwEMA is a modification of the Exponential Moving Average where bar weights depend on their range. Candles with wide bodies and significant movement receive higher weight, while narrow "noise" candles are largely ignored. This makes the line significantly more responsive to genuine impulses while remaining resistant to market noise.

Role of RwEMA in the strategy:

  • determines trend direction: price above RwEMA → trade only long; below → trade only short;
  • measures the moving average slope — a minimum slope threshold (in points per bar) filters out sideways markets;
  • serves as a return level in PULLBACK mode — the Expert Advisor waits for the price to pull back to the RwEMA (within a specified tolerance) to enter at a better price;
  • calculates the distance between the close and the RwEMA — acting as a "price has moved far enough from the average" filter.

The period (inpRwEmaPeriod) and price type (inpRwEmaPrice) are configurable. The default settings use a period of 50 based on the open price—a classic combination for capturing medium-term impulses in gold.

3. ATR — for stops and slope
The Average True Range is used in two ways: as the calculation method for the "Trendlines with Breaks" channel slope and as the basis for adaptive SL/TP levels. Stop-loss = ATR × InpATR_SL_Mult, take-profit = ATR × InpATR_TP_Mult, while observing the minimum distances InpATR_MinSLPts and InpATR_MinTPPts to ensure the stop levels are not placed closer than allowed.


EA Apex Trading is fully adaptable to any symbol: currency pairs, metals, indices, cryptocurrency, or stock CFDs. The logic is universal—only the numerical parameters for indicators and risk management need to be adjusted.

  1. Step 1. Preparing the Strategy Tester

  1. Open MetaTrader 5 → "View" → "Strategy Tester" (Ctrl+R).

  1. Expert Advisor: select EA Apex Trading.ex5.

  1. Symbol: the desired instrument (e.g., XAUUSD, EURUSD, BTCUSD, US500).

  1. Period: M5–H1 recommended (matches the working timeframe).

  1. Dates: at least 1 year of history; 2–3 years is preferable.

  1. Modeling mode: "Every tick based on real ticks" — the most accurate option.

  1. Deposit: 1,000–10,000 USD; leverage 1:100 or 1:500.

  1. Type: "Fast (genetic algorithm)"