Gaussian Ensemble
Trading Engine
A multi-strategy Expert Advisor built from scratch in pure MQL5/MQL4. Six Gaussian-based strategies vote on every tick — the ensemble decides when to trade.
A multi-strategy Expert Advisor built from scratch in pure MQL5/MQL4. Six Gaussian-based strategies vote on every tick — the ensemble decides when to trade.
Every tick flows through the price buffer, into six parallel strategies, then into the ensemble voter that produces the final trade decision.
Data flows left-to-right: raw prices → parallel strategies → ensemble vote → risk-managed trade execution
Each strategy is a self-contained Gaussian method that votes Buy, Sell, or Neutral with a confidence level. The ensemble weights and aggregates them. Click each strategy to expand its full explanation and visualisation.
Applies two Gaussian kernels with different width (fast σ=3, slow σ=6) to the price series. The convolution produces smoothed lines — the fast line reacts quickly, the slow line lags behind.
Crossover logic: When the fast line crosses above the slow, the trend is up (Buy, confidence 0.8). When it crosses below, the trend is down (Sell, 0.8). The relative position also produces a lower-confidence bias signal (0.3) when no crossover has occurred.
Why Gaussian? Unlike simple moving averages, Gaussian convolution gives more weight to the centre bar and smoothly tapers to the edges — producing a cleaner, phase-preserving smooth that doesn't overshoot on sharp moves.
Trains a Gaussian Process on the last InpGPRLookback (default 30) price bars using an RBF (squared-exponential) kernel. The GP produces both a mean prediction and a predictive variance (uncertainty band) for the next bar.
Mean-reversion logic: If the current price is more than InpGPRStdThresh (default 1.5) standard deviations away from the GP mean, the market is considered overextended. A buy signal fires when price is unusually low (below −σ), a sell when unusually high (above +σ).
Implementation: The GP is trained via Cholesky decomposition (O(n³) upfront, O(n²) per prediction). The prediction at x* is: μ = k(x*)ᵀ · α, where α = (K + σ²I)⁻¹ · y. The confidence band shrinks near training points and widens in extrapolation regions.
Fits a 2-component univariate GMM on daily return percentages using the Expectation-Maximisation (EM) algorithm. One component captures the low-volatility regime, the other the high-volatility regime.
Adaptive logic: In the high-vol regime, the strategy looks for momentum continuation — if the latest return exceeds 0.5·σ_HV in the direction of the move, it trades with the trend. In the low-vol regime, it switches to mean reversion — returns beyond 0.3·σ_HV from zero are faded.
EM algorithm: E-step computes responsibility γᵢₖ (probability each point belongs to each component). M-step re-estimates π, μ, σ for each component. Converges in ~10–20 iterations. Components are sorted so component 1 is always the high-vol regime.
Trains a binary Gaussian Naive Bayes classifier on three independent features to predict whether the next bar closes up or down:
The Naive Bayes assumption (conditional independence of features given the class) allows the joint likelihood to be computed as a product of univariate Gaussians: P(f₀,f₁,f₂ | class) = Πⱼ PDF(fⱼ | μ_class_j, σ_class_j).
Trade logic: If P(up | features) > InpGNBProbThresh (0.60) → Buy. If P(up) < 1 − threshold → Sell. Confidence = |P(up) − 0.5| × 2, mapping the range [0.5, 1.0] → [0, 1.0].
Computes a Gaussian-weighted rolling mean and standard deviation over the last 30 bars. The Gaussian kernel (length 15, σ=4.0) assigns higher weight to recent prices — making the band adaptive to recent market conditions while still retaining statistical stability.
Band logic: When price moves beyond InpVolBandMultiplier (default 2.0) standard deviations from the weighted mean, the market is statistically overextended. A sell signal fires above the upper band, a buy below the lower band. The confidence scales linearly with the distance from the band edge, capped at 1.0.
Why Gaussian-weighted? Unlike a simple rolling window (equal weights), the Gaussian weighting smoothly transitions from recent to older data — avoiding the "cliff edge" effect where a bar suddenly drops out of the window, causing a discontinuous jump in the mean and std.
Calculates the z-score of the current close price relative to the mean and standard deviation of the last period (default 20) bars: z = (Price − μ) / σ. The z-score is a unitless measure of how many standard deviations the current price is from its recent average.
Fade-the-move logic: When |z| > InpZScoreEntry (default 2.0), the price is statistically extreme — large deviations from the mean tend to revert. A buy signal fires at z = −2.0 (oversold), a sell at z = +2.0 (overbought). The confidence scales linearly with |z|, capped at 1.0 at z = 5.0.
Why z-score? The z-score normalises price by recent volatility — it works across different instruments and timeframes without parameter changes. A z-score of 2.0 means the same thing (95th percentile) whether on EUR/USD H1 or XAU/USD D1, making this strategy the most portable of the six.
Each strategy returns a (signal, confidence) pair. The ensemble computes a weighted sum and compares it to a threshold.
6
totalVote = Σ signal_s × confidence_s × weight_s
s=1
if totalVote ≥ +threshold → BUY
if totalVote ≤ −threshold → SELL
else → NEUTRAL
| Variable | Description | Range |
|---|---|---|
| signal | Direction vote from each strategy | −1, 0, +1 |
| confidence | How strongly the strategy believes its signal | [0.0, 1.0] |
| weight | User-configurable influence per strategy | any positive |
| threshold | Minimum ensemble conviction to enter | default 1.8 |
ATR-adaptive SL/TP, trailing stop, and breakeven — all configurable as percentages of TP distance rather than fixed point values.
| Feature | How It Works |
|---|---|
| ATR SL/TP | At order open, SL = price − 1.5 × ATR(14) and TP = price + 3.0 × ATR(14). Adapts to volatility automatically. |
| Trailing Stop | Once price reaches 50% of the TP distance, the EA tracks the peak. SL is tightened in 25% increments of the TP distance. |
| Breakeven | When price reaches 30% of TP distance, SL is moved to entry + small buffer (0.1 × ATR). Fires once per position. |
The ensemble was designed for liquid markets with balanced trending and mean-reversion behaviour. Below are the best pairs and timeframes based on backtesting.
| Pair | Why |
|---|---|
| EUR/USD | Tightest spread, balanced trending/ranging, GMM regime detection works well |
| GBP/USD | More volatility than EUR/USD, trends clearly, good for Filter + GPR combo |
| USD/JPY | Clean trends, lower noise, Z-score channels perform well |
| EUR/JPY | Higher volatility, good for GMM high-vol regime momentum trades |
| XAU/USD | Strong trending + sharp reversals — plays to both Filter and mean-rev strategies |
InpMaxSpread rejection and ATR-based SL becomes erratic.| TF | Why | Trades/week |
|---|---|---|
| H4 ★ | Sweet spot: enough bars for GPR/GMM training, low noise | 1–3 |
| H1 | Good balance, more signals, noise filtered by ensemble | 3–6 |
| D1 | Cleanest signals, but fewer trades; GPR lookback = 6 weeks | 0–1 |
EUR/USD H4 — the 6-strategy ensemble filters H4 noise well, ATR-based SL adapts to its volatility, and the GMM regime detector has clear high/low regimes to exploit.Need more power? FxMath offers professional-grade EAs with gradient boosting, reinforcement learning, and AI strategy generation — built for traders who demand more.
| Feature | GaussEnsemble FREE |
RFConsensus $99 |
Lumina $299 |
|---|---|---|---|
| AI Engine | Gaussian Ensemble (6 strategies) | RF + LGBM + Q-Learning RL | LightGBM Strategy Generator |
| Features | 6 models — math from scratch | 28 technical features | 500+ ML features |
| Timeframes | Any (best on H1–H4) | 3 (multi-TF voting) | Any (M1–MN) |
| Reinforcement Learning | No | Yes — Q-Learning | Yes — Adaptive |
| Strategy | 6 Gaussian strategies + voting | AI ensemble consensus | Custom-generated by RR target |
| Walk-Forward Validation | Manual | Yes | Yes |
| Simultaneous Instances | 1 per chart | 1 per chart | Unlimited |
| Platform | MT4 + MT5 | MT4 + MT5 | MT5 (Python bridge) |
| DLL Required | No — pure MQL | RF: No / LGBM: Yes | Yes (static) |
Two AI Engines in One Package
RFConsensus is the first EA to offer two AI engines in one package: a pure-MQL Random Forest (no DLLs) and a LightGBM + Q-Learning version with reinforcement learning that adapts trading thresholds based on every trade outcome.
AI Strategy Generator
Lumina is an autonomous ML trading terminal. You don't code strategy rules — you set your ideal Risk/Reward ratio and profit target, and Lumina generates a complete machine-learned strategy around your preferences.
Both MQL5 (.ex5) and MQL4 (.ex4) compiled files are ready to use. No registration, no license — deploy on any chart, any broker.
Need a custom or more advanced EA? Explore FxMath Lumina (AI Strategy Generator, $299) or FxMath RFConsensus (Dual AI Engines + RL, $99). Or just ask us anything!
Need a tailored solution? Advanced EAs, indicators, or ML-based strategies?
Contact us for custom projects
Upgrade to Lumina (AI strategy generator) or RFConsensus (dual AI engines + RL)