This Expert Advisor is a learning template. The code is short and every step is commented, so you can understand how a complete trading robot works and use it as a starting point for your own ideas.
Maximum one trade per day. Ranges smaller than 50 or larger than 400 pips are skipped.
| Input | Default | Meaning |
|---|---|---|
| InpRiskPercent | 1.0 | Risk per trade in % of balance |
| InpMaxDailyLossPercent | 2.0 | Max. daily loss in % (0 = off) |
| InpMaxDrawdownPercent | 15.0 | Max. drawdown from equity peak in % (0 = off) |
| InpRangeStartHour / InpRangeEndHour | 2 / 10 | Time window of the range (server time) |
| InpTradeEndHour / InpCloseHour | 15 / 22 | Delete pending orders / close position |
| InpBufferPips | 5 | Buffer above/below the range |
| InpTakeProfitR | 2.0 | Take profit as multiple of the SL distance |
| InpMinRangePips / InpMaxRangePips | 50 / 400 | Allowed range size |
| InpUseD1Filter / InpD1EmaPeriod | true / 200 | Daily trend filter |
| InpMaxSpreadPips | 10 | Maximum spread for new orders |
| InpAllowLiveAccount | false | Allow trading on a live account |
XAUUSD M5, 01.01.2024 - 25.11.2026, initial deposit 3000 USD, default inputs: profit factor 1.59, 227 trades, 54.6% winners, max. equity drawdown 7.85%. History quality of this test: 32% real ticks. Note: 211 of 227 trades were buys because gold was in a strong uptrend during this period. Between Nov 2024 and Jul 2025 the equity moved sideways to slightly down.

Balance curve of the backtest (XAUUSD M5, 2024-2026)

Test results with default inputs
Use on XAUUSD, timeframe M5. All times are broker server time - check your broker's time zone and adjust the hours if needed.
For educational purposes only. Not financial advice. Past backtest results do not guarantee future results. Test on a demo account first.
ChangePoint: Bayesian online change point detection
Online-Erkennung von Veränderungen des Mittelwerts oder der Volatilität (Adams-MacKay): Wahrscheinlichkeit einer Veränderung in den letzten k Balken, aktuelle Segmentlänge, Prognose und ein Indikator.
Copula: Gaussian, Student t, Clayton, Gumbel and Frank copulas with tail dependence
Passt fünf bivariate Copulas auf Rangzahlen an, unter Berücksichtigung von Kendalls Tau, der Abhängigkeit der Randverteilungen, der Wahrscheinlichkeit gemeinsamer Extremtage, des AIC sowie der bedingten Wahrscheinlichkeiten des Paarehandels.
Accumulation/Distribution
Der Accumulation/Distribution Indikator wird aus Änderung von Preis und Volumen bestimmt.
Accelerator Oszillator (AC)
Der Acceleration/Deceleration Indikator (AC) misst die Beschleunigung und Verlangsamung des aktuellen Marktimpulses, der Kraft der Kursbewegung.